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); } }
/// <summary> /// Opens the specified layer. /// </summary> /// <param name="layer">The layer.</param> /// <param name="map">The map.</param> public static void TryDeserialization(ILayer layer, IMap map) { // Is there a way to simplify this method, which requires use of different interfaces for different types? FeatureLayer featureLayer = layer as FeatureLayer; if (featureLayer != null) { if (featureLayer.DataSet != null && !String.IsNullOrEmpty(featureLayer.DataSet.Filename)) { Open(featureLayer.DataSet.Filename, map, featureLayer); return; } } MapImageLayer imageLayer = layer as MapImageLayer; if (imageLayer != null) { if (imageLayer.DataSet != null && !String.IsNullOrEmpty(imageLayer.DataSet.Filename)) { Open(imageLayer.DataSet.Filename, map, imageLayer); return; } } }
private static Layer GetImageLayer(dynamic layer) { Layer mapLayer = new MapImageLayer(ImageData.Open(layer["Path"])); // DeserializeLayer not implemented. return(mapLayer); }
private void BaseMapLayerRemoveItem(object sender, EventArgs e) { if (_baseMapLayer != null) { _baseMapLayer.RemoveItem -= BaseMapLayerRemoveItem; } _baseMapLayer = null; _serviceDropDown.SelectedItem = _emptyProvider; App.Map.MapFrame.ViewExtentsChanged -= MapFrameExtentsChanged; }
/// <summary> /// /// </summary> private void DisableBasemapLayer() { RemoveBasemapLayer(_baseMapLayer); RemoveBasemapLayer(_featureSetLayer); _baseMapLayer = null; _basemapImage = null; _featureSetLayer = null; App.Map.MapFrame.ViewExtentsChanged -= MapFrameExtentsChanged; }
private void DisableBasemapLayer() { RemoveBasemapLayer(_baseMapLayer); RemoveBasemapLayer(_featureSetLayer); _optionsAction.Enabled = false; _baseMapLayer = null; _featureSetLayer = null; App.Map.MapFrame.ViewExtentsChanged -= MapFrameExtentsChanged; }
private void OnDataMenuClickEventHandler(object sender, EventArgs e) { var act = ((SimpleActionItem)sender).Caption; //MessageBox.Show("Clicked " + act); switch (act) { case "Download...": D4EMDataDownload.DownloadDataPlugin.DSProject = appManager.SerializationManager; var plugin = new D4EMDataDownload.DownloadDataPlugin(); plugin.Initialize(appManager, 0); var handled = true; plugin.Show("mnuDownloadDataD4EM", ref handled); break; case "Open...": var lFilesOnly = new System.Collections.ArrayList(1); lFilesOnly.Add("File"); var src = atcDataManager.UserSelectDataSource(lFilesOnly); if (src != null) { atcDataManager.OpenDataSource(src, "", null); } break; case "Manage...": atcDataManager.UserManage(); break; case "New...": break; case "Save In...": break; case "Open Large Grid": string gridfilename = @"D:\Data\gis\BigSiouxRiver_atDellRapids\Terrain\Wa21_clipped_projected.Wa21_clipped_ProjectRaster1.tif"; var gip = new DotSpatial.Data.Rasters.GdalExtension.GdalImageProvider(); //var gip = new DotSpatial.Data.Rasters.GdalExtension.GdalRasterProvider(); var imageData = gip.Open(gridfilename); var imgLayer = new MapImageLayer(imageData); //var imgLayer = new MapRasterLayer(imageData); appManager.Map.Layers.Add(imgLayer); //var mapgridlayer = new MapImageLayer(); //var symLayers = new System.Collections.Generic.List<DotSpatial.Symbology.ILayer>(); //ILayer imapgrid = mapgridlayer.OpenLayer(gridfilename, false, symLayers, appManager.ProgressHandler); //appManager.Map.Layers.Add(imapgrid); break; } }
/// <summary> /// Deserializes the WebMap settings and loads the corresponding basemap. /// </summary> /// <param name="sender">Sender that raised the event.</param> /// <param name="e">The event args.</param> 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", Resources.None); if (basemapName.Equals(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 == Resources.Legend_Title); if (tmpLayer != null) { RemoveBasemapLayer(tmpLayer); } } else { _baseMapLayer = (MapImageLayer)App.Map.MapFrame.GetAllLayers().FirstOrDefault(layer => layer.LegendText == 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); } }
public static IMapLayer GetMapLayer(string dataPath) { IMapLayer mapLayer = null; IDataSet dataSet = OpenFile(dataPath); if (dataSet != null) { if (dataSet is IFeatureSet featureSet) { switch (featureSet.FeatureType) { case FeatureType.Point: case FeatureType.MultiPoint: mapLayer = new MapPointLayer(featureSet); break; case FeatureType.Line: mapLayer = new MapLineLayer(featureSet); break; case FeatureType.Polygon: mapLayer = new MapPolygonLayer(featureSet); break; } } else if (dataSet is IImageData imageSet) { mapLayer = new MapImageLayer(imageSet); } else if (dataSet is IRaster raster) { mapLayer = new MapRasterLayer(raster); } else if (dataSet is ISelfLoadSet selfLoadSet) { mapLayer = selfLoadSet.GetLayer(); } } return(mapLayer); }
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(Resources.nodata, new Extent(1, 1, 2, 2)); _baseMapLayer = new MapImageLayer(tempImageData) { Projection = App.Map.Projection, LegendText = Resources.Legend_Title }; _baseMapLayer.RemoveItem += BaseMapLayerRemoveItem; AddBasemapLayerToMap(); } App.Map.MapFrame.ViewExtentsChanged -= MapFrameExtentsChanged; 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(Properties.Resources.None)) { if (_baseMapLayer != null) { DisableBasemapLayer(); _serviceDropDown.SelectedItem = _emptyProvider; } } else { //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> /// Deserializes beginning from the given root. /// </summary> /// <param name="xmlRoot">Root to use as string point.</param> 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 { var type = (object)fs.GetType().ToString(); Trace.WriteLine("Unsupported FeatureSet Type: " + type); } 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); } }