调用地图服务问题

以下为加载几种类型地图服务的flex源码:
case "wmts":
                    {
                        var wmtsLayer:GeoTileLayer = new GeoTileLayer(url);
                        wmtsLayer.alpha = alpha;
                        wmtsLayer.id = layId;
                        wmtsLayer.name = label;
                        wmtsLayer.visible = visible;
                        layerObject.layer = wmtsLayer;
                        map.addLayer(wmtsLayer);
                        break;
                    }
					case "czwmts":
					{
						var array:Array=new Array();
						array=url.split(';');
						var tlayer:TLayer=new TLayer();
						tlayer.id="baseMap";
						tlayer.name="地图";
						tlayer.visible=true;
						tlayer.layerId="vec";
						tlayer.serviceMode="KVP";
						tlayer.tileMatrixSetId="c";
						tlayer.imageFormat="tiles";
						tlayer.baseURL=array[0];
						map.addLayer(tlayer);
						
						var tlayerr:TLayer=new TLayer();
						tlayerr.id="tipMap";
						tlayerr.name="切片地图";
						tlayerr.visible=true;
						tlayerr.layerId="cva";
						tlayerr.serviceMode="KVP";
						tlayerr.tileMatrixSetId="c";
						tlayerr.imageFormat="tiles";
						tlayerr.baseURL=array[1];
						map.addLayer(tlayerr);
						
						break;
					}
                    case "tiled":
                    {
                        var tiledLayer:ArcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(url);
                        tiledLayer.alpha = alpha;
                        tiledLayer.id = layId;
                        tiledLayer.name = label;
                        tiledLayer.token = token;
                        tiledLayer.visible = visible;
                        if (displayLevels)
                        {
                            tiledLayer.displayLevels = displayLevels.split(",");
                            for (i = 0; i < tiledLayer.displayLevels.length; i++)
                            {
                                tiledLayer.displayLevels[i] = Number(tiledLayer.displayLevels[i]); // convert to Numbers
                            }
                        }
                        if (proxyUrl && useProxy)
                        {
                            tiledLayer.proxyURL = proxyUrl;
                        }
                        layerObject.layer = tiledLayer;
                        map.addLayer(tiledLayer);
                        break;
                    }
                    case "dynamic":
                    {
                        var dynLayer:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(url);
                        dynLayer.alpha = alpha;
                        dynLayer.id = layId;
                        dynLayer.name = label;
						dynLayer.imageFormat = "png32";
                        dynLayer.token = token;
                        dynLayer.visible = visible;
                        dynLayer.useMapTime = useMapTime;
                        if (autoRefresh > 0)
                        {
                            setInterval(dynLayer.refresh, autoRefresh * 1000);
                        }
                        if (imageFormat)
                        {
                            dynLayer.imageFormat = imageFormat;
                        }
                        if (visibleLayers)
                        {
                            var vizLayers:Array = visibleLayers.split(",");
                            for (i = 0; i < vizLayers.length; i++)
                            {
                                vizLayers[i] = Number(vizLayers[i]); // convert to Numbers
                            }
                            dynLayer.visibleLayers = new ArrayCollection(vizLayers);
                        }
                        if (proxyUrl && useProxy)
                        {
                            dynLayer.proxyURL = proxyUrl;
                        }
                        layerObject.layer = dynLayer;
                        map.addLayer(dynLayer);
                        break;
                    }
                    case "feature":
                    {
                        var featureLayer:FeatureLayer = new FeatureLayer(url);
						featureLayer.addEventListener(GraphicEvent.GRAPHIC_ADD,fLayer_graphicAddHandler);
                        featureLayer.addEventListener(FlexEvent.HIDE, featureLayer_hideHandler);
                        featureLayer.alpha = alpha;
                        featureLayer.id = layId;
                        featureLayer.name = label;
                        featureLayer.outFields = [ '*' ]; // TODO: be smarter
                        featureLayer.token = token;
                        featureLayer.visible = visible;
                        featureLayer.useMapTime = useMapTime;
						
                        if (useAMF)
                        {
                            featureLayer.useAMF = (useAMF == "true");
                        }
                        if (mode)
                        {
                            featureLayer.mode = mode;
                        }
                        if (definitionExpression)
                        {
                            featureLayer.definitionExpression = definitionExpression;
                        }
                        if (proxyUrl && useProxy)
                        {
                            featureLayer.proxyURL = proxyUrl;
                        }
                        layerObject.layer = featureLayer;
                        map.addLayer(featureLayer);
                        break;
                    }
                    case "bing":
                    {
                        var veTiledLayer:VETiledLayer = new VETiledLayer();
                        veTiledLayer.id = layId;
                        veTiledLayer.name = label;
                        veTiledLayer.key = bingMapKey;
                        veTiledLayer.visible = visible;
                        veTiledLayer.alpha = alpha;
                        if (style)
                        {
                            veTiledLayer.mapStyle = style;
                        }
                        if (culture)
                        {
                            veTiledLayer.culture = culture;
                        }
                        if (displayLevels)
                        {
                            veTiledLayer.displayLevels = displayLevels.split(",");
                            for (i = 0; i < veTiledLayer.displayLevels.length; i++)
                            {
                                veTiledLayer.displayLevels[i] = Number(veTiledLayer.displayLevels[i]); // convert to Numbers
                            }
                        }
                        layerObject.layer = veTiledLayer;
                        map.addLayer(veTiledLayer);
                        break;
                    }
                    case "image":
                    {
                        var imgLayer:ArcGISImageServiceLayer = new ArcGISImageServiceLayer(url);
                        imgLayer.id = layId;
                        imgLayer.name = label;
                        imgLayer.alpha = alpha;
                        imgLayer.token = token;
                        imgLayer.visible = visible;
                        imgLayer.noData = noData;
                        imgLayer.useMapTime = useMapTime;
                        if (imageFormat)
                        {
                            imgLayer.imageFormat = imageFormat;
                        }
                        if (bandIds)
                        {
                            imgLayer.bandIds = bandIds.split(",");
                            for (i = 0; i < imgLayer.bandIds.length; i++)
                            {
                                imgLayer.bandIds[i] = Number(imgLayer.bandIds[i]); // convert to Numbers
                            }
                        }
                        if (proxyUrl && useProxy)
                        {
                            imgLayer.proxyURL = proxyUrl;
                        }
                        layerObject.layer = imgLayer;
                        map.addLayer(imgLayer);
                        break;
                    }
                    case "arcims":
                    {
                        var arcimsLayer:ArcIMSMapServiceLayer = new ArcIMSMapServiceLayer();
                        arcimsLayer.alpha = alpha;
                        arcimsLayer.id = layId;
                        arcimsLayer.name = label;
                        arcimsLayer.visible = visible;
                        arcimsLayer.serviceHost = serviceHost;
                        arcimsLayer.serviceName = serviceName;
                        if (autoRefresh > 0)
                        {
                            setInterval(arcimsLayer.refresh, autoRefresh * 1000);
                        }
                        if (imageFormat)
                        {
                            arcimsLayer.imageFormat = imageFormat;
                        }
                        if (visibleLayers)
                        {
                            var visLayers:Array = visibleLayers.split(",");
                            arcimsLayer.visibleLayers = new ArrayCollection(visLayers);
                        }
                        if (proxyUrl && useProxy)
                        {
                            arcimsLayer.proxyURL = proxyUrl;
                        }
                        if (username && password)
                        {
                            arcimsLayer.username = username;
                            arcimsLayer.password = password;
                        }
                        layerObject.layer = arcimsLayer;
                        map.addLayer(arcimsLayer);
                        break;
                    }
                    case "wms":
                    {
                        var wmsLayer:WMSLayer = new WMSLayer(url);
                        wmsLayer.alpha = alpha;
                        wmsLayer.id = layId;
                        wmsLayer.name = label;
                        wmsLayer.visible = visible;
                        if (wkid)
                        {
                            wmsLayer.spatialReference = new SpatialReference(wkid);
                        }
                        if (autoRefresh > 0)
                        {
                            setInterval(wmsLayer.refresh, autoRefresh * 1000);
                        }
                        if (imageFormat)
                        {
                            wmsLayer.imageFormat = imageFormat;
                        }
                        if (visibleLayers)
                        {
                            var wmsVisLayers:Array = visibleLayers.split(",");
                            wmsLayer.visibleLayers = new ArrayList(wmsVisLayers);
                        }
                        if (proxyUrl && useProxy)
                        {
                            wmsLayer.proxyURL = proxyUrl;
                        }
                        if (skipGetCapabilities)
                        {
                            wmsLayer.skipGetCapabilities = skipGetCapabilities == "true";
                        }
                        if (username && password)
                        {
                            wmsLayer.username = username;
                            wmsLayer.password = password;
                        }
                        if (version)
                        {
                            wmsLayer.version = version;
                        }
                        layerObject.layer = wmsLayer;
                        map.addLayer(wmsLayer);
                        break;
                    }
                    case "osm":
                    {
                        var osmLayer:OpenStreetMapLayer = new OpenStreetMapLayer();
                        osmLayer.alpha = alpha;
                        osmLayer.id = layId;
                        osmLayer.name = label;
                        osmLayer.visible = visible;
                        layerObject.layer = osmLayer;
                        map.addLayer(osmLayer);
                        break;
                    }
                    default:
                    {
                        Alert.show(StringUtil.substitute(getDefaultString('incorrectLayerTypeText'), "'" + type + "'"));
                        break;
                    }
这样写虽然方便,但会带来一个严重的问题:
我们在初始化地图服务,加载地图图层的时候,在地图图层还没有完全加载完成的时候,就把地图服务加到地图上了,这样很可能导致地图图层加载失败的问题了。整体来说,如果是访问外网的地图服务时,网速和浏览器很大程度上会影响地图服务的加载时间,也会很容易导致这样的问题,这里,把这个问题提出来,希望和大家一起研究更好的解决方案。

你可能感兴趣的:(调用地图服务问题)