private void SetInternalLayer(ESRI.ArcGIS.Client.Layer layer) { _internalLayer = layer; SetFeatureLayerPropsFromLayerInfo(_internalLayer as FeatureLayer); if (_internalLayer.InitializationFailure != null) { ConnectionStatus = LayerConnectionStatus.InitializationFailed; } else if (_mapSpatialReference == null) // initialized independent of the map { ConnectionStatus = LayerConnectionStatus.Connected; } else { if (SpatialReference.AreEqual(_mapSpatialReference, _internalLayer.SpatialReference, false)) { ConnectionStatus = LayerConnectionStatus.Connected; } else if (Type == LayerType.ArcGISDynamicMapServiceLayer || Type == LayerType.ArcGISImageServiceLayer || Type == LayerType.ArcGISFeatureServiceLayer) { ConnectionStatus = LayerConnectionStatus.Connected; } } }
private void ClickMapButton_Click_1(object sender, RoutedEventArgs e) { if (_mapWidget != null) { _mapWidget.Map.MouseClick += Map_MouseClick; } if (_graphicsLayer != null) { _graphicsLayer.Graphics.Clear(); } int id = -1; for (int i = 0; i < _mapWidget.Map.Layers.Count; i++) { client.Layer player = _mapWidget.Map.Layers[i]; if (player.ID == "Farthest On Circle") { id = i; } } if (id != -1) { _mapWidget.Map.Layers.RemoveAt(id); } }
} // public string getFieldAlias(string fieldname) /// <summary> /// create Layer according to its Type /// </summary> /// <param name="id"></param> /// <param name="vis"></param> /// <returns></returns> private Layer createLayer(string id, bool vis) { string typ = lyrType; ESRI.ArcGIS.Client.Layer res = null; if (typ == "ArcGISTiledMapServiceLayer") { var lr = new ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer(); lr.Url = lyrUrl; lr.ProxyURL = proxy; res = lr; } else if (typ == "OpenStreetMapLayer") { var lr = new ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer(); res = lr; } else if (typ == "ArcGISDynamicMapServiceLayer") { var lr = new ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer(); lr.Url = lyrUrl; lr.ProxyURL = proxy; res = lr; } else if (typ == "FeatureLayer") { var lr = new ESRI.ArcGIS.Client.FeatureLayer(); lr.Url = lyrUrl; lr.ProxyUrl = proxy; res = lr; } else if (typ == "GraphicsLayer") { var gl = setContent(id, lyrUrl); res = gl; } if (res != null) { ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsPopupEnabled(res, popupOn); // sublayers popups on/off if (identifyLayerIds.Length <= 3) { ; } else { var xmlszn = new System.Xml.Serialization.XmlSerializer(typeof(System.Collections.ObjectModel.Collection <int>)); var sr = new StringReader(identifyLayerIds); var ids = xmlszn.Deserialize(sr) as System.Collections.ObjectModel.Collection <int>; ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetIdentifyLayerIds(res, ids); } } return(res); } // private Layer createLayer(string id, bool vis)
} // private Layer createLayer(string id, bool vis) private void getLyrSignature(Map map, ESRI.ArcGIS.Client.Layer l) { // get all Layer parameters string typ = lyr.GetType().ToString(); string[] parts = typ.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 0) { typ = parts[parts.Length - 1]; } lyrType = typ; lyrName = MapApplication.GetLayerName(l); popupOn = ESRI.ArcGIS.Client.Extensibility.LayerProperties.GetIsPopupEnabled(l); // sublayers popups on/off http://forums.arcgis.com/threads/58106-Popup-for-visible-layers-only?highlight=popups var ids = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetIdentifyLayerIds(l); //var ids = new System.Collections.ObjectModel.Collection<int>(); var xmlszn = new System.Xml.Serialization.XmlSerializer(typeof(System.Collections.ObjectModel.Collection <int>)); var sw = new StringWriter(); xmlszn.Serialize(sw, ids); identifyLayerIds = string.Format("{0}", sw.ToString().Trim()); if (typ == "ArcGISTiledMapServiceLayer") { var lr = (ArcGISTiledMapServiceLayer)lyr; lyrUrl = lr.Url; proxy = lr.ProxyURL; } else if (typ == "OpenStreetMapLayer") { var lr = lyr as ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer; lyrUrl = "http://www.openstreetmap.org/"; } else if (typ == "ArcGISDynamicMapServiceLayer") { var lr = (ArcGISDynamicMapServiceLayer)lyr; lyrUrl = lr.Url; proxy = lr.ProxyURL; imageFormat = lr.ImageFormat; } else if (typ == "FeatureLayer") { var lr = (FeatureLayer)lyr; lyrUrl = lr.Url; renderer = getRenderer(lr); proxy = lr.ProxyUrl; } else if (typ == "GraphicsLayer") { var lr = (GraphicsLayer)lyr; lyrUrl = getContent(lr); renderer = getRenderer(lr); proxy = ""; } return; } // private string getLyrSignature(Map map, ESRI.ArcGIS.Client.Layer lyr)
private void DoneButton_Click(object sender, RoutedEventArgs e) { try { RunButton.IsEnabled = false; // When the user is finished with the toolbar, revert to the configured toolbar. if (_mapWidget != null) { _mapWidget.Map.MouseClick -= Map_MouseClick; _mapWidget.SetToolbar(null); } int id = -1; int id2 = -1; for (int i = 0; i < _mapWidget.Map.Layers.Count; i++) { client.Layer player = _mapWidget.Map.Layers[i]; if (player.ID == "AircraftCommunicationCoverageMap") { id = i; } if (player.ID == "AircraftCommunicationGraphics") { id2 = i; } } if (id != -1) { _mapWidget.Map.Layers.RemoveAt(id); } if (id2 != -1) { _mapWidget.Map.Layers.RemoveAt(id2 - 1); } if (_graphicsLayer != null) { _graphicsLayer.Graphics.Clear(); } if (pWin != null) { pWin.Close(); } if (_dtLegends != null) { _dtLegends.Clear(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
public VLayer(Layer l) { lyr = l; getLyrSignature(null, l); if (MapApplication.Current.SelectedLayer != null && MapApplication.Current.SelectedLayer.ID == lyr.ID) { this.selected = true; } }
public VLayer(VLayerDescription ld) { lyr = null; lyrName = ld.name; lyrUrl = ld.url; lyrType = ld.type; selected = false; proxy = ld.proxy; helpCreateLayer(ld.id, true); } // public VLayer(VLayerDescription ld)
} // public void cloneLayer() private void helpCreateLayer(string id, bool vis) { lyr = createLayer(id, vis); if (lyr == null) { throw new Exception(string.Format( "VLayer.helpCreateLayer, can't create layer [{0}, {1}]", id, lyrUrl)); } lyr.Visible = vis; lyr.ID = id; } // private void helpCreateLayer(string id, bool vis)
} // public VLayer(VLayerDescription ld) public VLayer(JsonObject js) { lyr = null; lyrName = js["name"]; lyrUrl = js["url"]; lyrType = js["type"]; proxy = getFromJson(js, "proxy"); selected = getBoolFromJson(js, "selected"); popupOn = getBoolFromJson(js, "popupEnabled"); identifyLayerIds = getFromJson(js, "identifyLayerIds"); helpCreateLayer(js["id"], js["visible"]); } // public VLayer(JsonObject js)
private void ClearButton_Click(object sender, RoutedEventArgs e) { try { int id = -1; int id2 = -1; for (int i = 0; i < _mapWidget.Map.Layers.Count; i++) { client.Layer player = _mapWidget.Map.Layers[i]; if (player.ID == "AircraftCommunicationCoverageMap") { id = i; } if (player.ID == "AircraftCommunicationGraphics") { id2 = i; } } if (id != -1) { _mapWidget.Map.Layers.RemoveAt(id); } if (id2 != -1) { _mapWidget.Map.Layers.RemoveAt(id2 - 1); } if (_graphicsLayer != null) { _graphicsLayer.Graphics.Clear(); } if (pWin != null) { pWin.Close(); } if (_mapWidget != null) { _mapWidget.Map.MouseClick -= Map_MouseClick; } RunButton.IsEnabled = false; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
public VLayer(VLayerDescription ld) { lyr = null; lyrName = ld.name; lyrUrl = ld.url; lyrType = ld.type; selected = false; proxy = ld.proxy; if (ld.imageFormat == "PNG32") { imageFormat = ArcGISDynamicMapServiceLayer.RestImageFormat.PNG32; } helpCreateLayer(ld.id, true); } // public VLayer(VLayerDescription ld)
} // public VLayer(VLayerDescription ld) public VLayer(JsonObject js) //var vLyr = new VLayer(jsLyr); { lyr = null; lyrName = js["name"]; lyrUrl = js["url"]; lyrType = js["type"]; proxy = getFromJson(js, "proxy"); selected = getBoolFromJson(js, "selected"); popupOn = getBoolFromJson(js, "popupEnabled"); identifyLayerIds = getFromJson(js, "identifyLayerIds"); renderer = getFromJson(js, "renderer"); try { _opacity = getFromJson(js, "opacity"); } catch (Exception ex) { string.Format("VLayer(JsonObject) can't find 'opacity': {0}", ex.Message).clog(); } try { imageFormat = (ArcGISDynamicMapServiceLayer.RestImageFormat)(int) getFromJson(js, "ImageFormat"); } catch (Exception ex) { string.Format("VLayer(JsonObject) can't find 'ImageFormat': {0}", ex.Message).clog(); } helpCreateLayer(js["id"], js["visible"]); } // public VLayer(JsonObject js)
public override void CreateLayerAsync(Resource resource, SpatialReference mapSpatialReference, object userState) { if (resource == null) { return; } ESRI.ArcGIS.Client.Layer layer = null; switch (resource.ResourceType) { case ResourceType.MapServer: case ResourceType.FeatureServer: { string url = resource.Url; if (resource.ResourceType == ResourceType.FeatureServer) { int i = url.LastIndexOf(string.Format("/{0}", ResourceType.FeatureServer.ToString())); if (i >= 0) { url = url.Remove(i); url = string.Format("{0}/{1}", url, ResourceType.MapServer.ToString()); } } _service = ServiceFactory.CreateService(ResourceType.MapServer, url, resource.ProxyUrl); if (_service != null) { _service.ServiceDetailsDownloadFailed += (o, e) => { OnCreateLayerFailed(e); }; _service.ServiceDetailsDownloadCompleted += (o, e) => { MapService mapService = o as MapService; if (mapService.ServiceInfo == null) { OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionUnableToRetrieveMapServiceDetails), e.UserState)); return; } if (mapService.ServiceInfo.TileInfo != null && mapService.ServiceInfo.SingleFusedMapCache) { #region Create tiled layer if (mapSpatialReference != null && !mapSpatialReference.Equals(mapService.ServiceInfo.SpatialReference)) { OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionCachedMapServiceSpatialReferenceDoesNotMatch), e.UserState)); return; } layer = new ArcGISTiledMapServiceLayer() { Url = url, ProxyURL = getCleanProxyUrl(mapService.ProxyUrl), }; if (mapService.ServiceInfo.TileInfo.LODs != null) { double maxResolution = 0; double minResolution = 0; foreach (LODInfo lod in mapService.ServiceInfo.TileInfo.LODs) { if (lod.Resolution > maxResolution) { maxResolution = lod.Resolution; } if (minResolution <= 0 || minResolution > lod.Resolution) { minResolution = lod.Resolution; } } if (maxResolution > 0) { layer.MaximumResolution = maxResolution * 4; } if (minResolution > 0) { layer.MinimumResolution = minResolution / 4; } } #endregion } else { #region create dynamic layer layer = new ArcGISDynamicMapServiceLayer() { Url = url, ProxyURL = getCleanProxyUrl(mapService.ProxyUrl), }; #endregion } //Set layer's attached properties if (layer != null) { layer.SetValue(MapApplication.LayerNameProperty, resource.DisplayName); layer.SetValue(Core.LayerExtensions.DisplayUrlProperty, url); if (!string.IsNullOrEmpty(resource.ProxyUrl)) { Core.LayerExtensions.SetUsesProxy(layer, true); } layer.ID = Guid.NewGuid().ToString("N"); } OnCreateLayerCompleted(new CreateLayerCompletedEventArgs() { Layer = layer, UserState = e.UserState }); }; _service.GetServiceDetails(null); } } break; case ResourceType.ImageServer: { layer = new ArcGISImageServiceLayer() { Url = resource.Url, ProxyURL = getCleanProxyUrl(resource.ProxyUrl), ID = Guid.NewGuid().ToString("N"), }; //Set layer's attached properties layer.SetValue(MapApplication.LayerNameProperty, resource.DisplayName); layer.SetValue(Core.LayerExtensions.DisplayUrlProperty, resource.Url); if (!string.IsNullOrEmpty(resource.ProxyUrl)) { Core.LayerExtensions.SetUsesProxy(layer, true); } // Need to declare handler separate from lambda expression to avoid erroneous // "use of unassigned variable" build error EventHandler <EventArgs> initialized = null; // Need to populate the layer's metadata to handle initialization of image format // and band IDs initialized = (o, e) => { layer.Initialized -= initialized; ArcGISImageServiceLayer imageLayer = (ArcGISImageServiceLayer)layer; if (imageLayer.Version < 10) { // Pre v10, band IDs must be specified explicitly. But no more than // 3 can be used. Just take up to the first 3 by default. List <int> bandIDs = new List <int>(); for (int i = 0; i < imageLayer.BandCount; i++) { bandIDs.Add(i); if (i == 2) { break; } } imageLayer.BandIds = bandIDs.ToArray(); // Use png format to support transparency imageLayer.ImageFormat = ArcGISImageServiceLayer.ImageServiceImageFormat.PNG8; } else { // At v10 and later, band IDs do not need to be specified, and jpg/png // format introduces some intelligence about which format is best imageLayer.ImageFormat = ArcGISImageServiceLayer.ImageServiceImageFormat.JPGPNG; } OnCreateLayerCompleted(new CreateLayerCompletedEventArgs() { Layer = layer, UserState = userState }); }; EventHandler <EventArgs> initFailed = null; initFailed = (o, e) => { layer.InitializationFailed -= initFailed; OnCreateLayerCompleted(new CreateLayerCompletedEventArgs() { Layer = layer, UserState = userState }); }; layer.Initialized += initialized; layer.InitializationFailed += initFailed; layer.Initialize(); } break; case ResourceType.Layer: case ResourceType.EditableLayer: { featureLayer = new Layer(resource.Url, resource.ProxyUrl); featureLayer.GetLayerDetailsFailed += (o, e) => { OnCreateLayerFailed(e); }; featureLayer.GetLayerDetailsCompleted += (o, e) => { if (e.LayerDetails == null) { OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionUnableToRetrieveLayerDetails), e.UserState)); return; } if (Utility.RasterLayer.Equals(e.LayerDetails.Type)) { OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionRasterLayersNotSupported), e.UserState)); return; } else if (Utility.ImageServerLayer.Equals(e.LayerDetails.Type)) { OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionImageServerLayersNotSupported), e.UserState)); return; } if (Utility.CapabilitiesSupportsQuery(e.LayerDetails.Capabilities) == false) { OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionLayerDoesNotSupportQuery), e.UserState)); return; } GeometryType GeometryType = GeometryType.Unknown; switch (e.LayerDetails.GeometryType) { case "esriGeometryPoint": GeometryType = GeometryType.Point; break; case "esriGeometryMultipoint": GeometryType = GeometryType.MultiPoint; break; case "esriGeometryPolyline": GeometryType = GeometryType.Polyline; break; case "esriGeometryPolygon": GeometryType = GeometryType.Polygon; break; } FeatureLayer newFeatureLayer = new FeatureLayer() { Url = featureLayer.Uri, ProxyUrl = getCleanProxyUrl(featureLayer.ProxyUrl), ID = Guid.NewGuid().ToString("N"), Mode = FeatureLayer.QueryMode.OnDemand, Renderer = new ESRI.ArcGIS.Mapping.Core.Symbols.HiddenRenderer() }; newFeatureLayer.SetValue(MapApplication.LayerNameProperty, resource.DisplayName); newFeatureLayer.SetValue(Core.LayerExtensions.DisplayUrlProperty, resource.Url); newFeatureLayer.SetValue(Core.LayerExtensions.GeometryTypeProperty, GeometryType); if (!string.IsNullOrEmpty(resource.ProxyUrl)) { Core.LayerExtensions.SetUsesProxy(newFeatureLayer, true); } if (e.LayerDetails.Fields != null) { Collection <ESRI.ArcGIS.Mapping.Core.FieldInfo> fields = FieldInfosFromFields(e.LayerDetails.Fields); newFeatureLayer.SetValue(Core.LayerExtensions.FieldsProperty, fields); Core.LayerExtensions.SetDisplayField(newFeatureLayer, e.LayerDetails.DisplayField); } newFeatureLayer.OutFields.Add("*"); // Get all fields at configuration time OnCreateLayerCompleted(new CreateLayerCompletedEventArgs() { Layer = newFeatureLayer, UserState = e.UserState, GeometryType = GeometryType }); }; featureLayer.GetLayerDetails(userState); } break; default: throw new Exception(string.Format(Resources.Strings.ExceptionCannotCreateLayerForResourceType, resource.ResourceType.ToString())); } }
public VLayer(Layer l) { lyr = l; getLyrSignature(null, l); }
public string identifyLayerIds = ""; // sublayers id's with popups enabled public VLayer() { lyr = null; }
/// <summary> /// Initializes the layer by creating the appropriate ESRI.ArcGIS.Client.Layer and /// holding onto it (_internalLayer). /// </summary> public void InitializeAsync(Map map, object userState, EventHandler <LayerInitializedEventArgs> callback) { if (_internalLayer != null) { return; } ConnectionStatus = LayerConnectionStatus.NotConnected; // determine the layer type - TODO - change this when the web map format supports Bing and OSM // TileLayer.LayerType bingLayerType = TileLayer.LayerType.Aerial; switch (LayerDescription.LayerType) { case "BingMapsAerial": bingLayerType = TileLayer.LayerType.Aerial; Type = LayerType.BingLayer; break; case "BingMapsRoad": bingLayerType = TileLayer.LayerType.Road; Type = LayerType.BingLayer; break; case "BingMapsHybrid": bingLayerType = TileLayer.LayerType.AerialWithLabels; Type = LayerType.BingLayer; break; case "OpenStreetMap": Type = LayerType.OpenStreetMapLayer; break; default: if (LayerDescription.Service is ImageService) { Type = LayerType.ArcGISImageServiceLayer; } else if (LayerDescription.Service is FeatureLayerService) { Type = LayerType.ArcGISFeatureServiceLayer; } else { bool tiled = LayerDescription.Service is MapService && ((MapService)LayerDescription.Service).IsTiled && (map.SpatialReference == null || map.SpatialReference.Equals(((MapService)LayerDescription.Service).SpatialReference)); Type = tiled ? LayerType.ArcGISTiledMapServiceLayer : LayerType.ArcGISDynamicMapServiceLayer; // if the service's spatial reference is different from the map's spatial reference, always set the layer type to be // ArcGISDynamicMapServiceLayer if (map != null && LayerDescription.Service != null) { if (!SpatialReference.AreEqual(LayerDescription.Service.SpatialReference, map.SpatialReference, true)) { Type = LayerType.ArcGISDynamicMapServiceLayer; } } } break; } // now create the appropriate ESRI.ArcGIS.Client.Layer // string proxy = (LayerDescription.Service != null && LayerDescription.Service.RequiresProxy) ? ArcGISOnlineEnvironment.ConfigurationUrls.ProxyServerEncoded : null; if (Type == LayerType.ArcGISTiledMapServiceLayer) { ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer() { Url = this.Url, ProxyURL = proxy }; _internalLayer = tiledLayer; MapService mapService = LayerDescription.Service as MapService; if (mapService != null && mapService.TileInfo != null && mapService.TileInfo.LODs != null) { double maxResolution = 0; double minResolution = 0; foreach (LODInfo lod in mapService.TileInfo.LODs) { if (lod.Resolution > maxResolution) { maxResolution = lod.Resolution; } if (minResolution <= 0 || minResolution > lod.Resolution) { minResolution = lod.Resolution; } } if (maxResolution > 0) { tiledLayer.MaximumResolution = maxResolution * 4; } if (minResolution > 0) { tiledLayer.MinimumResolution = minResolution / 4; } } } else if (Type == LayerType.ArcGISDynamicMapServiceLayer) { _internalLayer = new ArcGISDynamicMapServiceLayer() { Url = this.Url, ProxyURL = proxy } } ; else if (Type == LayerType.ArcGISImageServiceLayer) { int[] bandIds = ((ImageService)LayerDescription.Service).BandCount < 4 ? null : new int[] { 0, 1, 2 }; _internalLayer = new ArcGISImageServiceLayer() { Url = this.Url, ProxyURL = proxy, ImageFormat = ArcGISImageServiceLayer.ImageServiceImageFormat.PNG8, BandIds = bandIds }; } else if (Type == LayerType.ArcGISFeatureServiceLayer) { _internalLayer = new FeatureLayer() { Url = this.Url, ProxyUrl = proxy, Mode = LayerDescription.QueryMode, OutFields = new ESRI.ArcGIS.Client.Tasks.OutFields() { "*" }, Renderer = new ESRI.ArcGIS.Mapping.Core.Symbols.HiddenRenderer() }; } else if (Type == LayerType.OpenStreetMapLayer) { _internalLayer = new OpenStreetMapLayer(); } else if (Type == LayerType.BingLayer) { TileLayer tileLayer = new TileLayer() { LayerStyle = bingLayerType }; tileLayer.Token = ArcGISOnlineEnvironment.BingToken; tileLayer.ServerType = ServerType.Production; _internalLayer = tileLayer; } _internalLayer.Visible = LayerDescription.Visible; _internalLayer.Opacity = LayerDescription.Opacity; if (!string.IsNullOrEmpty(LayerDescription.Title)) { _internalLayer.SetValue(ESRI.ArcGIS.Client.Extensibility.MapApplication.LayerNameProperty, LayerDescription.Title); } if (LayerDescription.IsReference) { ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetIsReferenceLayer(_internalLayer, true); } // remember the map's spatial reference in order to determine after initialization // if the layer will work properly // if (map != null) { _mapSpatialReference = map.SpatialReference; } _internalLayer.Initialized += _internalLayer_Initialized; _internalLayer.InitializationFailed += _internalLayer_InitializationFailed; _initializationCallState = new CallState() { Callback = callback, UserState = userState }; _internalLayer.Initialize(); }
/// <summary> /// Initializes the layer by creating the appropriate ESRI.ArcGIS.Client.Layer and /// holding onto it (_internalLayer). /// </summary> public void InitializeAsync(Map map, object userState, EventHandler<LayerInitializedEventArgs> callback) { if (_internalLayer != null) return; ConnectionStatus = LayerConnectionStatus.NotConnected; // determine the layer type - TODO - change this when the web map format supports Bing and OSM // TileLayer.LayerType bingLayerType = TileLayer.LayerType.Aerial; switch (LayerDescription.LayerType) { case "BingMapsAerial": bingLayerType = TileLayer.LayerType.Aerial; Type = LayerType.BingLayer; break; case "BingMapsRoad": bingLayerType = TileLayer.LayerType.Road; Type = LayerType.BingLayer; break; case "BingMapsHybrid": bingLayerType = TileLayer.LayerType.AerialWithLabels; Type = LayerType.BingLayer; break; case "OpenStreetMap": Type = LayerType.OpenStreetMapLayer; break; default: if (LayerDescription.Service is ImageService) Type = LayerType.ArcGISImageServiceLayer; else if (LayerDescription.Service is FeatureLayerService) Type = LayerType.ArcGISFeatureServiceLayer; else { bool tiled = LayerDescription.Service is MapService && ((MapService)LayerDescription.Service).IsTiled && (map.SpatialReference == null || map.SpatialReference.Equals(((MapService)LayerDescription.Service).SpatialReference)); Type = tiled ? LayerType.ArcGISTiledMapServiceLayer : LayerType.ArcGISDynamicMapServiceLayer; // if the service's spatial reference is different from the map's spatial reference, always set the layer type to be // ArcGISDynamicMapServiceLayer if (map != null && LayerDescription.Service != null) if (!SpatialReference.AreEqual(LayerDescription.Service.SpatialReference, map.SpatialReference, true)) Type = LayerType.ArcGISDynamicMapServiceLayer; } break; } // now create the appropriate ESRI.ArcGIS.Client.Layer // string proxy = (LayerDescription.Service != null && LayerDescription.Service.RequiresProxy) ? ArcGISOnlineEnvironment.ConfigurationUrls.ProxyServerEncoded : null; if (Type == LayerType.ArcGISTiledMapServiceLayer) { ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer() { Url = this.Url, ProxyURL = proxy }; _internalLayer = tiledLayer; MapService mapService = LayerDescription.Service as MapService; if (mapService != null && mapService.TileInfo != null && mapService.TileInfo.LODs != null) { double maxResolution = 0; double minResolution = 0; foreach (LODInfo lod in mapService.TileInfo.LODs) { if (lod.Resolution > maxResolution) maxResolution = lod.Resolution; if (minResolution <= 0 || minResolution > lod.Resolution) minResolution = lod.Resolution; } if (maxResolution > 0) tiledLayer.MaximumResolution = maxResolution * 4; if (minResolution > 0) tiledLayer.MinimumResolution = minResolution / 4; } } else if (Type == LayerType.ArcGISDynamicMapServiceLayer) _internalLayer = new ArcGISDynamicMapServiceLayer() { Url = this.Url, ProxyURL = proxy }; else if (Type == LayerType.ArcGISImageServiceLayer) { int[] bandIds = ((ImageService)LayerDescription.Service).BandCount < 4 ? null : new int[] { 0, 1, 2 }; _internalLayer = new ArcGISImageServiceLayer() { Url = this.Url, ProxyURL = proxy, ImageFormat = ArcGISImageServiceLayer.ImageServiceImageFormat.PNG8, BandIds = bandIds }; } else if (Type == LayerType.ArcGISFeatureServiceLayer) { _internalLayer = new FeatureLayer() { Url = this.Url, ProxyUrl = proxy, Mode = LayerDescription.QueryMode, OutFields = new ESRI.ArcGIS.Client.Tasks.OutFields() { "*" }, Renderer = new ESRI.ArcGIS.Mapping.Core.Symbols.HiddenRenderer() }; } else if (Type == LayerType.OpenStreetMapLayer) _internalLayer = new OpenStreetMapLayer(); else if (Type == LayerType.BingLayer) { TileLayer tileLayer = new TileLayer() { LayerStyle = bingLayerType }; tileLayer.Token = ArcGISOnlineEnvironment.BingToken; tileLayer.ServerType = ServerType.Production; _internalLayer = tileLayer; } _internalLayer.Visible = LayerDescription.Visible; _internalLayer.Opacity = LayerDescription.Opacity; if (!string.IsNullOrEmpty(LayerDescription.Title)) _internalLayer.SetValue(ESRI.ArcGIS.Client.Extensibility.MapApplication.LayerNameProperty, LayerDescription.Title); if (LayerDescription.IsReference) ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetIsReferenceLayer(_internalLayer, true); // remember the map's spatial reference in order to determine after initialization // if the layer will work properly // if (map != null) _mapSpatialReference = map.SpatialReference; _internalLayer.Initialized += _internalLayer_Initialized; _internalLayer.InitializationFailed += _internalLayer_InitializationFailed; _initializationCallState = new CallState() { Callback = callback, UserState = userState }; _internalLayer.Initialize(); }
public void Add(string sLink, string sID) { ArcGISServiceType myType = ArcGISServiceType.Unknown; if (sLink.ToUpper().IndexOf("SERVICE=WMS") > 0) { myType = ArcGISServiceType.WMS; } else if (sLink.ToUpper().IndexOf("IMAGESERVER") > 0) { myType = ArcGISServiceType.ImageServer; } else if (sLink.ToUpper().IndexOf("ARCGIS/REST") > 0) { if (sLink.ToUpper().IndexOf("MAPSERVER") > 0) { myType = ArcGISServiceType.ArcGIS; } } _status = "Adding new service..."; ESRI.ArcGIS.Client.Layer layer = null; switch (myType) { case ArcGISServiceType.ArcGIS: layer = new ArcGISDynamicMapServiceLayer(); ArcGISDynamicMapServiceLayer temp = layer as ArcGISDynamicMapServiceLayer; temp.InitializationFailed += new EventHandler <EventArgs>(layer_InitializationFailed); temp.Initialized += new EventHandler <EventArgs>(temp_Initialized); temp.Url = sLink; temp.ID = sID; break; case ArcGISServiceType.ImageServer: layer = new ArcGISImageServiceLayer(); ArcGISImageServiceLayer imageServer = layer as ArcGISImageServiceLayer; imageServer.Url = sLink; imageServer.ID = sID; imageServer.Initialized += new EventHandler <EventArgs>(temp_Initialized); imageServer.InitializationFailed += new EventHandler <EventArgs>(imageServer_InitializationFailed); break; case ArcGISServiceType.WMS: layer = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer(); ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer wmsLayer = layer as ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer; wmsLayer.InitializationFailed += new EventHandler <EventArgs>(wmsLayer_InitializationFailed); wmsLayer.Initialized += new EventHandler <EventArgs>(temp_Initialized); string [] layers = new string[1]; layers[0] = "1"; wmsLayer.Layers = layers; wmsLayer.Url = CleanWMSSErvices(sLink); wmsLayer.ID = sID; break; case ArcGISServiceType.IMS: layer = new ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer(); ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer imsLayer = layer as ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer; imsLayer.InitializationFailed += new EventHandler <EventArgs>(imsLayer_InitializationFailed); imsLayer.Initialized += new EventHandler <EventArgs>(temp_Initialized); imsLayer.ID = sID; imsLayer.ServiceHost = sLink; imsLayer.ServiceHost = sLink; break; } if (layer != null) { _mapServicesID.Add(layer.ID); _map.Layers.Add(layer); } }