/// <summary> /// handles shapefiles added to the map /// </summary> /// <param name="layer"></param> /// <param name="layerName"></param> /// <param name="visible"></param> /// <param name="showInLayerUI"></param> /// <param name="layerHandle"></param> /// <returns></returns> public int AddLayer(object layer, string layerName, bool visible, bool showInLayerUI, string fileName = "", fad3MappingMode mappingMode = fad3MappingMode.defaultMode, string layerKey = "", bool rejectIfExisting = false) { if (rejectIfExisting && layerName.Length > 0 && Exists(layerName)) { return(get_MapLayer(layerName).Handle); } int h = 0; GeoProjection gp = new GeoProjection(); var layerType = layer.GetType().Name; switch (layerType) { case "ShapefileClass": h = _axmap.AddLayer((Shapefile)layer, visible); gp = ((Shapefile)layer).GeoProjection; //LineWidthFix.FixLineWidth((Shapefile)layer); break; case "ImageClass": h = _axmap.AddLayer((MapWinGIS.Image)layer, visible); gp = ((MapWinGIS.Image)layer).GeoProjection; break; case "GridClass": h = _axmap.AddLayer((Grid)layer, visible); gp = _axmap.GeoProjection; break; } _axmap.set_LayerName(h, layerName); _currentMapLayer = SetMapLayer(h, layerName, visible, showInLayerUI, gp, layerType, fileName); _currentMapLayer.LayerKey = layerKey; _currentMapLayer.MappingMode = mappingMode; if (LayerRead != null) { LayerEventArg lp = new LayerEventArg(h, layerName, visible, showInLayerUI, _currentMapLayer.LayerType); LayerRead(this, lp); } return(h); }
/// <summary> /// handles a shapefile added to the map using file open dialog /// </summary> /// <param name="sf"></param> /// <returns></returns> public int AddLayer(Shapefile sf, string layerName = "", bool isVisible = true, bool uniqueLayer = false, fad3MappingMode mappingMode = fad3MappingMode.defaultMode) { if (uniqueLayer) { RemoveLayer(layerName); } var h = _axmap.AddLayer(sf, isVisible); if (h >= 0) { if (layerName.Length == 0) { layerName = Path.GetFileName(sf.Filename); } _axmap.set_LayerName(h, layerName); _currentMapLayer = SetMapLayer(h, layerName, isVisible, true, sf.GeoProjection, "ShapefileClass", sf.Filename); _currentMapLayer.MappingMode = mappingMode; if (LayerRead != null) { LayerEventArg lp = new LayerEventArg(h, layerName, true, true, _currentMapLayer.LayerType); LayerRead(this, lp); } LineWidthFix.FixLineWidth(sf); } else { int reprojectedCount = 0; //if(sf.ReprojectInPlace(_axmap.GeoProjection,ref reprojectedCount)) var sfr = sf.Reproject(_axmap.GeoProjection, reprojectedCount); if (reprojectedCount > 0) { h = _axmap.AddLayer(sfr, isVisible); if (h > 0) { if (layerName.Length == 0) { layerName = Path.GetFileName(sf.Filename); } _axmap.set_LayerName(h, layerName); _currentMapLayer = SetMapLayer(h, layerName, isVisible, true, sf.GeoProjection, "ShapefileClass", sf.Filename); _currentMapLayer.MappingMode = mappingMode; if (LayerRead != null) { LayerEventArg lp = new LayerEventArg(h, layerName, true, true, _currentMapLayer.LayerType); LayerRead(this, lp); } LineWidthFix.FixLineWidth(sf); } } } return(h); }
/// <summary> /// handles a shapefile added to the map using file open dialog /// </summary> /// <param name="sf"></param> /// <returns></returns> public int AddLayer(Shapefile sf, string layerName = "", bool isVisible = true, bool uniqueLayer = false, fad3MappingMode mappingMode = fad3MappingMode.defaultMode, string layerKey = "", bool rejectIfExisting = false, bool showInLayersUI = true) { if (rejectIfExisting && layerName.Length > 0 && Exists(layerName)) { var handle = get_MapLayer(layerName).Handle; MapLayerDictionary[handle].LayerObject = sf; return(handle); } if (uniqueLayer) { RemoveLayer(layerName); } var h = _axmap.AddLayer(sf, isVisible); if (h >= 0) { if (layerName.Length == 0) { layerName = Path.GetFileName(sf.Filename); } _axmap.set_LayerName(h, layerName); _axmap.set_LayerKey(h, layerKey); _currentMapLayer = SetMapLayer(h, layerName, isVisible, true, sf.GeoProjection, "ShapefileClass", sf.Filename); _currentMapLayer.LayerKey = layerKey; _currentMapLayer.MappingMode = mappingMode; _currentMapLayer.VisibleInLayersUI = showInLayersUI; if (LayerRead != null) { LayerEventArg lp = new LayerEventArg(h, layerName, isVisible, showInLayersUI, _currentMapLayer.LayerType); LayerRead(this, lp); } //LineWidthFix.FixLineWidth(sf); } else { int reprojectedCount = 0; //if(sf.ReprojectInPlace(_axmap.GeoProjection,ref reprojectedCount)) var sfr = sf.Reproject(_axmap.GeoProjection, reprojectedCount); if (reprojectedCount > 0) { h = _axmap.AddLayer(sfr, isVisible); if (h > 0) { if (layerName.Length == 0) { layerName = Path.GetFileName(sf.Filename); } _axmap.set_LayerName(h, layerName); _currentMapLayer = SetMapLayer(h, layerName, isVisible, true, sf.GeoProjection, "ShapefileClass", sf.Filename); _currentMapLayer.LayerKey = layerKey; _currentMapLayer.MappingMode = mappingMode; if (LayerRead != null) { LayerEventArg lp = new LayerEventArg(h, layerName, isVisible, showInLayersUI, _currentMapLayer.LayerType); LayerRead(this, lp); } //LineWidthFix.FixLineWidth(sf); } } } return(h); }