/// <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 knfex) { //ignore } catch (Exception ex) { Logger.Log(ex.Message, "MapLayersHandler", "RemoveLayer"); } }
/// <summary> /// Removes a layer from the list of layers /// </summary> internal bool RemoveLayer(int layerHandle, bool batch) { int groupIndex, layerIndex; Layer lyr = FindLayerByHandle(layerHandle, out groupIndex, out layerIndex); if (lyr == null) { return(false); } var grp = GetGroup(groupIndex); grp.LayersList.RemoveAt(layerIndex); _map.RemoveLayer(layerHandle); if (layerHandle == _selectedLayerHandle && !batch) { _selectedLayerHandle = _map.NumLayers > 0 ? _map.get_LayerHandle(_map.NumLayers - 1) : -1; FireEvent(this, LayerSelected, new LayerEventArgs(_selectedLayerHandle)); } if (!batch) { grp.RecalcHeight(); Redraw(); } FireEvent(this, LayerRemoved, new LayerEventArgs(layerHandle)); return(true); }
public bool StopEditingLayer(bool saveEdits = false) { if (CurrentEditingLayer == null) { // there is nothing to save... return(false); } saveAndCloseWhenFinish = false; AxMap.ShapeEditor.SaveChanges(); if (saveEdits) { if (!SaveEdits()) { //return false; } } var sf = AxMap.get_Shapefile(CurrentEditingLayer.Handle); var ogrLayer = AxMap.get_OgrLayer(CurrentEditingLayer.Handle); if (ogrLayer != null) { ogrLayer.ReloadFromSource(); // show the editing layer (with all Polygons) sf = AxMap.get_Shapefile(((ResTBPostGISLayer)CurrentEditingLayer).EditingLayerHandle); AxMap.RemoveLayer(((ResTBPostGISLayer)CurrentEditingLayer).EditingLayerHandle); AxMap.set_LayerVisible(CurrentEditingLayer.Handle, true); } bool returnBool = sf.StopEditingShapes(); AxMap.ChooseLayer -= AxMap_ChooseLayer; AxMap.AfterShapeEdit -= _map_AfterShapeEdit; AxMap.BeforeDeleteShape -= _map_BeforeDeleteShape; AxMap.BeforeShapeEdit -= _map_BeforeShapeEdit; AxMap.ShapeValidationFailed -= _map_ShapeValidationFailed; AxMap.ValidateShape -= _map_ValidateShape; MapControlTools.Redraw(true); Events.MapControl_LayerChange layerChange = new Events.MapControl_LayerChange() { Layer = this.CurrentEditingLayer, LayerChangeReason = Events.LayerChangeReason.EditedLayer }; On_LayerChange(layerChange); Events.MapControl_EditingStateChange editingStateChange = new Events.MapControl_EditingStateChange() { EditingState = Events.EditingState.StopEditing, EditingLayer = CurrentEditingLayer }; On_EditingStateChange(editingStateChange); _currentEditingLayer = null; AxMap.CursorMode = tkCursorMode.cmPan; return(returnBool); }
public void RemoveLayer() { if (layerHandle != -1) { map.RemoveLayer(layerHandle); sf = new Shapefile(); sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT); layerHandle = -1; } }
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); }
public bool RemoveLayer(string name) { ILayer removeLayer = MapControlTools.Layers.Where(m => m.Name == name).FirstOrDefault(); if (removeLayer == null) { return(false); } if (removeLayer.GetType() == typeof(ResTBDamagePotentialLayer)) { AxMap.RemoveLayer(((ResTBDamagePotentialLayer)removeLayer).PointHandle); AxMap.RemoveLayer(((ResTBDamagePotentialLayer)removeLayer).LineHandle); AxMap.RemoveLayer(((ResTBDamagePotentialLayer)removeLayer).PolygonHandle); } else if (removeLayer.GetType() == typeof(ResTBRiskMapLayer)) { AxMap.RemoveLayer(((ResTBRiskMapLayer)removeLayer).PointHandle); AxMap.RemoveLayer(((ResTBRiskMapLayer)removeLayer).LineHandle); AxMap.RemoveLayer(((ResTBRiskMapLayer)removeLayer).PolygonHandle); } else { AxMap.RemoveLayer(removeLayer.Handle); } if (MapControlTools.EditingTool.CurrentEditingLayer?.GetType() == typeof(ResTBPostGISLayer)) { AxMap.RemoveLayer(((ResTBPostGISLayer)MapControlTools.EditingTool.CurrentEditingLayer).EditingLayerHandle); } MapControlTools.Layers.Remove(removeLayer); Events.MapControl_LayerChange layerchange = new Events.MapControl_LayerChange() { LayerChangeReason = Events.LayerChangeReason.RemoveLayer, Layer = removeLayer }; On_LayerChange(layerchange); return(true); }
public virtual bool Remove(int layerHandle) { _axMap.RemoveLayer(layerHandle); return(_axMap.get_LayerPosition(layerHandle) != -1); }