/// <summary> /// Adds the specified image data as a new layer to the map. /// </summary> /// <param name="image">The image to add as a layer</param> /// <returns>the IMapImageLayer interface for the layer that was added to the map.</returns> public IMapImageLayer Add(IImageData image) { if (image.Height == 0 || image.Width == 0) { return(null); } MapImageLayer il = new MapImageLayer(image); base.Add(il); return(il); }
public virtual IMapLayer GetMapLayer(IDataSet dataSet) { IMapLayer mapLayer = null; var ss = dataSet as ISelfLoadSet; if (ss != null) { mapLayer = ss.GetLayer(); } var fs = dataSet as IFeatureSet; if (fs != null) { mapLayer = GetMapFeatureLayer(fs); } var r = dataSet as IRaster; if (r != null) { mapLayer = new MapRasterLayer(r); } var id = dataSet as IImageData; if (id != null) { if (id.Height == 0 || id.Width == 0) { return(null); } mapLayer = new MapImageLayer(id); } return(mapLayer); }
/// <summary> /// /// </summary> private void EnableBasemapLayer() { if (_baseMapLayer == null) { //Need to first initialize and add the basemap layer synchronously (it will fail if done in // another thread. //First create a temporary imageData with an Envelope (otherwise adding to the map will fail) var tempImageData = new InRamImageData(Properties.Resources.nodata, new Extent(1, 1, 2, 2)); _baseMapLayer = new MapImageLayer(tempImageData) { Projection = App.Map.Projection, LegendText = Properties.Resources.Legend_Title }; _baseMapLayer.RemoveItem += BaseMapLayerRemoveItem; AddBasemapLayerToMap(); } App.Map.MapFrame.ViewExtentsChanged += MapFrameExtentsChanged; }
private void SerializationManagerDeserializing(object sender, SerializingEventArgs e) { try { var opacity = App.SerializationManager.GetCustomSetting(PluginName + "_Opacity", "100"); var basemapName = App.SerializationManager.GetCustomSetting(PluginName + "_BasemapName", Properties.Resources.None); //Set opacity _opacityDropDown.SelectedItem = opacity; _opacity = Convert.ToInt16(opacity); _baseMapLayer = (MapImageLayer)App.Map.MapFrame.GetAllLayers().FirstOrDefault(layer => layer.LegendText == Properties.Resources.Legend_Title); if (basemapName.Equals("None")) { if (_baseMapLayer != null) { DisableBasemapLayer(); _provider = _emptyProvider; _serviceDropDown.SelectedItem = _provider; } } else { //hack: need to set provider to original object, not a new one. _provider = ServiceProvider.GetDefaultServiceProviders().FirstOrDefault(p => p.Name.Equals(basemapName, StringComparison.InvariantCultureIgnoreCase)); _serviceDropDown.SelectedItem = _provider; EnableBasemapFetching(_provider.Name, _provider.Url); } } catch (Exception ex) { Debug.Print(ex.StackTrace); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BaseMapLayerRemoveItem(object sender, EventArgs e) { _baseMapLayer = null; _serviceDropDown.SelectedItem = _emptyProvider; App.Map.MapFrame.ViewExtentsChanged -= MapFrameExtentsChanged; }
/// <summary> /// /// </summary> private void DisableBasemapLayer() { RemoveBasemapLayer(_baseMapLayer); RemoveBasemapLayer(_featureSetLayer); _baseMapLayer = null; _featureSetLayer = null; App.Map.MapFrame.ViewExtentsChanged -= MapFrameExtentsChanged; }
public void Deserialize(dynamic xmlRoot) { var mapwin4Section = xmlRoot.MapWindow4; var mapwingisSection = xmlRoot.MapWinGIS; _map.MapFrame.ProjectionString = mapwin4Section["ProjectProjection"]; if (!Convert.ToBoolean(mapwin4Section["ViewBackColor_UseDefault"])) { var mapControl = _map as Control; if (mapControl != null) mapControl.BackColor = LegacyDeserializer.GetColor(mapwin4Section["ViewBackColor"]); _map.Invalidate(); } // Deserialize layers var layersDescs = mapwingisSection.Layers.Elements(); var allLayers = new Dictionary<int, List<ILayer>>(); // key: Group Name. Value: layers foreach (var layer in mapwin4Section.Layers.Elements()) { var name = (string)layer["Name"]; var groupInd = Convert.ToInt32(layer["GroupIndex"]); if (!allLayers.ContainsKey(groupInd)) allLayers[groupInd] = new List<ILayer>(); var listLayers = allLayers[groupInd]; IMapLayer layerToAdd = null; foreach (var layersDesc in layersDescs) { if (layersDesc["LayerName"] == name) { var lt = (string) layersDesc["LayerType"]; switch (lt) { case "Image": layerToAdd = new MapImageLayer(ImageData.Open(layersDesc["Filename"])); break; case "Shapefile": var fs = FeatureSet.OpenFile(layersDesc["Filename"]); if (fs is PointShapefile) { layerToAdd = new MapPointLayer(fs); } else if (fs is PolygonShapefile) { layerToAdd = new MapPolygonLayer(fs); } else if (fs is LineShapefile) { layerToAdd = new MapLineLayer(fs); } else { Trace.WriteLine("Unsupported FeatureSet Type: " + fs.GetType()); } break; default: Trace.WriteLine("Unsupported LayerType: " + lt); break; } break; } } if (layerToAdd != null) { layerToAdd.IsExpanded = Convert.ToBoolean(layer["Expanded"]); listLayers.Add(layerToAdd); } } // Deserialize groups foreach (var group in mapwin4Section.Groups.Elements()) { var gInd = Convert.ToInt32(group["Position"]); var g = new MapGroup { LegendText = group["Name"], IsExpanded = Convert.ToBoolean(group["Expanded"]) }; List<ILayer> gl; if (allLayers.TryGetValue(gInd, out gl)) { foreach (var layer in gl) { g.Add(layer); } } _map.MapFrame.Layers.Add(g); } }
/// <summary> /// Deserializes the WebMap settings and loads the corresponding basemap. /// </summary> private void SerializationManagerDeserializing(object sender, SerializingEventArgs e) { try { if (_baseMapLayer != null) //disable BaseMap because we might be loading a project that doesn't have a basemap { DisableBasemapLayer(); _serviceDropDown.SelectedItem = _emptyProvider; } //Set opacity var opacity = App.SerializationManager.GetCustomSetting(PluginName + "_Opacity", "100"); _opacityDropDown.SelectedItem = opacity; _opacity = Convert.ToInt16(opacity); var basemapName = App.SerializationManager.GetCustomSetting(PluginName + "_BasemapName", Properties.Resources.None); if (basemapName.Equals(Properties.Resources.None)) // make sure there is no basemap layer that shouldn't be there { var tmpLayer = (MapImageLayer)App.Map.MapFrame.GetAllLayers().FirstOrDefault(layer => layer.LegendText == Properties.Resources.Legend_Title); if (tmpLayer != null) RemoveBasemapLayer(tmpLayer); } else { _baseMapLayer = (MapImageLayer)App.Map.MapFrame.GetAllLayers().FirstOrDefault(layer => layer.LegendText == Properties.Resources.Legend_Title); if (_baseMapLayer != null) _baseMapLayer.Projection = WebMercProj; // changed by jany_(2015-07-09) set the projection because if it is not set we produce a cross thread exception when DotSpatial tries to show the projection dialog //hack: need to set provider to original object, not a new one. _serviceDropDown.SelectedItem = _serviceDropDown.Items.OfType<ServiceProvider>() .FirstOrDefault(p => p.Name.Equals(basemapName, StringComparison.InvariantCultureIgnoreCase)); var pp = CurrentProvider; if (pp != null) { EnableBasemapFetching(pp); } } } catch (Exception ex) { Debug.Print(ex.StackTrace); } }
/// <summary> /// Adds the specified image data as a new layer to the map. /// </summary> /// <param name="image">The image to add as a layer</param> /// <returns>the IMapImageLayer interface for the layer that was added to the map.</returns> public IMapImageLayer Add(IImageData image) { if (image.Height == 0 || image.Width == 0) return null; MapImageLayer il = new MapImageLayer(image); base.Add(il); return il; }
private static Layer GetImageLayer(dynamic layer) { Layer mapLayer = new MapImageLayer(ImageData.Open(layer["Path"])); // DeserializeLayer not implemented. return mapLayer; }
private void SerializationManagerDeserializing(object sender, SerializingEventArgs e) { var opacity = App.SerializationManager.GetCustomSetting(PluginName + "_Opacity", "100"); var basemapName = App.SerializationManager.GetCustomSetting(PluginName + "_BasemapName", resources.None); //Set opacity _opacityDropDown.SelectedItem = opacity; _opacity = Convert.ToInt16(opacity); _baseMapLayer = (MapImageLayer)App.Map.MapFrame.GetAllLayers().FirstOrDefault(layer => layer.LegendText == resources.Legend_Title); if (basemapName == "None") { if (_baseMapLayer != null) { DisableBasemapLayer(); _provider = _emptyProvider; _serviceDropDown.SelectedItem = _provider; } } else { //hack: need to set provider to original object, not a new one. _provider = ServiceProvider.GetDefaultServiceProviders().FirstOrDefault(p => p.Name == basemapName); _serviceDropDown.SelectedItem = _provider; EnableBasemapFetching(_provider.Name, _provider.Url); } }