/// <summary> /// Removes a layer using layer handle and raises a Layer removed event. /// </summary> /// <param name="layerHandle"></param> public void RemoveLayer(int layerHandle) { try { MapLayerDictionary[layerHandle].Dispose(); MapLayerDictionary.Remove(layerHandle); _axmap.RemoveLayer(layerHandle); _axmap.Redraw(); //fire the layer deleted event if (LayerRemoved != null) { LayerEventArg lp = new LayerEventArg(layerHandle, layerRemoved: true); LayerRemoved(this, lp); } //if the layer removed is the current layer, then make the current layer null if (CurrentMapLayer != null && layerHandle == _currentMapLayer.Handle) { _currentMapLayer = null; } } catch (KeyNotFoundException) { //ignore } catch (Exception ex) { Logger.Log(ex); } }
/// <summary> /// gets the layer in the map and retrieves the corresponding layer item in the dictionary. Fires an event after a layer item is read /// </summary> public void ReadLayers() { for (int n = 0; n < _axmap.NumLayers; n++) { var h = _axmap.get_LayerHandle(n); if (MapLayerDictionary.ContainsKey(h) && MapLayerDictionary[h].VisibleInLayersUI) { //if there is a listener to the event if (LayerRead != null) { //get the corresponding layer item in the dictionary var item = MapLayerDictionary[h]; //fill up the event argument class with the layer item LayerEventArg lp = new LayerEventArg(item.Handle, item.Name, item.Visible, item.VisibleInLayersUI, item.LayerType); LayerRead(this, lp); } } } }
/// <summary> /// handles editing of layer name and layer visibility /// </summary> /// <param name="layerHandle"></param> /// <param name="layerName"></param> /// <param name="visible"></param> /// <param name="isShown"></param> public void EditLayer(int layerHandle, string layerName, bool visible, bool isShown = true) { if (MapLayerDictionary.ContainsKey(layerHandle)) { var ly = MapLayerDictionary[layerHandle]; ly.Name = layerName; ly.Visible = visible; ly.VisibleInLayersUI = isShown; } _axmap.set_LayerName(layerHandle, layerName); _axmap.set_LayerVisible(layerHandle, visible); if (OnLayerVisibilityChanged != null) { LayerEventArg lp = new LayerEventArg(layerHandle); lp.LayerVisible = visible; lp.LayerName = layerName; OnLayerVisibilityChanged(this, lp); } _axmap.Redraw(); }
public void SetAsPointLayerFromDatabase(MapLayer ly) { ly.IsPointDatabaseLayer = true; List <int> forRemove = new List <int>(); foreach (MapLayer ml in MapLayerDictionary.Values) { if (ml.IsPointDatabaseLayer && ml.Handle != ly.Handle) { forRemove.Add(ml.Handle); } } if (forRemove.Count > 0) { foreach (var item in forRemove) { MapLayerDictionary.Remove(item); _axmap.RemoveLayer(item); } RefreshLayers(); } }
public bool RemoveLayerByKey(string layerKey) { if (LayerDictionary.Count > 0) { List <int> layerHandles = new List <int>(); int counter = 0; foreach (var item in LayerDictionary.Values) { if (item.LayerKey == layerKey) { layerHandles.Add(item.Handle); } } foreach (var h in layerHandles) { MapLayerDictionary[h].Dispose(); MapLayerDictionary.Remove(h); _axmap.RemoveLayer(h); if (LayerRemoved != null) { LayerEventArg lp = new LayerEventArg(h, layerRemoved: true); LayerRemoved(this, lp); } counter++; } if (counter > 0) { _axmap.Redraw(); } return(counter > 0); } return(false); }
/// <summary> /// Sets up a mapLayer object from a newly added map layer and adds it to the layers dictionary /// </summary> /// <param name="layerHandle"></param> /// <param name="layerName"></param> /// <param name="Visible"></param> /// <param name="ShowInLayerUI"></param> /// <param name="gp"></param> /// <param name="layerType"></param> /// <param name="fileName"></param> /// <returns></returns> private MapLayer SetMapLayer(int layerHandle, string layerName, bool Visible, bool ShowInLayerUI, GeoProjection gp, string layerType = "ShapefileClass", string fileName = "") { var mapLayer = new MapLayer(layerHandle, layerName, Visible, ShowInLayerUI, this); mapLayer.LayerType = layerType; mapLayer.FileName = _axmap.get_LayerFilename(layerHandle); if (mapLayer.FileName.Length == 0) { mapLayer.FileName = fileName; } mapLayer.GeoProjectionName = gp.Name; mapLayer.LayerPosition = _axmap.get_LayerPosition(layerHandle); mapLayer.LayerObject = _axmap.get_GetObject(layerHandle); mapLayer.Labels = _axmap.get_LayerLabels(layerHandle); MapLayerDictionary.Add(layerHandle, mapLayer); _axmap.Redraw(); set_MapLayer(layerHandle); return(mapLayer); }
public bool Exists(int layerHandle) { return(MapLayerDictionary.ContainsKey(layerHandle)); }