ThinkGeo.com    |     Documentation    |     Premium Support

Delete a selected Featue/Shape in EditOverlay

Hello,

We have an EditOverlay map that the user can add many shapes to it.

What we would like to add is a feature that enables the user to delete any of the shapes of his choice.




What I was thinking of doing is get the current ID or index (in the EditOverlay features property) of that shape (while the shape is selected in TrackMode.Edit mode) and use the .Remove method of the collection to accomplice this.




Problem is, I cannot find in the API, a way to get the required data (ID or index).

If there is a different, easier, way to accomplish the requirements?


Thanks,

Runny



Runny,


Here is a solution for your requirement, it is a sample that shows how to remove a feature on the map. When you run the sample, please notice that after you drawn several map shapes on the map, please save them first, then select any map shapes on the map and execute the remove operation to remove any map shapes what you want. Here is the sample code below:



  protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-131.22, 55.05, -54.03, 16.91);
                Map1.MapUnit = GeographyUnit.DecimalDegree;

                WorldMapKitWmsWebOverlay worldMapKitWmsWebOverlay = new WorldMapKitWmsWebOverlay("WorldMapKitOverlay");
                Map1.CustomOverlays.Add(worldMapKitWmsWebOverlay);

                InMemoryFeatureLayer shapeLayer = new InMemoryFeatureLayer();
                shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(180, 102, 255, 102), 10, GeoColor.StandardColors.DarkGreen, 1);
                shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Green, 4, true);
                shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(180, 102, 255, 102), GeoColor.StandardColors.DarkGreen, 1);
                shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                shapeLayer.DrawingQuality = DrawingQuality.HighQuality;

                LayerOverlay dynamicOverlay = new LayerOverlay("DynamicOverlay");
                dynamicOverlay.IsBaseOverlay = false;
                dynamicOverlay.TileType = TileType.SingleTile;
                dynamicOverlay.Layers.Add("shapeLayer", shapeLayer);
                Map1.CustomOverlays.Add(dynamicOverlay);                
            }
        }

        protected void buttonSubmit_Click(object sender, ImageClickEventArgs e)
        {
            LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["DynamicOverlay"];
            InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["shapeLayer"];

            foreach (Feature feature in Map1.EditOverlay.Features)
            {
                if (!shapeLayer.InternalFeatures.Contains(feature.Id))
                {
                    shapeLayer.InternalFeatures.Add(feature.Id, feature);
                }
            }

            Map1.EditOverlay.Features.Clear();
            Map1.EditOverlay.TrackMode = TrackMode.None;
            dynamicOverlay.Redraw();
        }

        protected void buttonEditShape_Click(object sender, ImageClickEventArgs e)
        {
            LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["DynamicOverlay"];
            InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["shapeLayer"];

            foreach (Feature feature in shapeLayer.InternalFeatures)
            {
                Map1.EditOverlay.Features.Add(feature.Id, feature);
            }

            shapeLayer.InternalFeatures.Clear();
            Map1.EditOverlay.TrackMode = TrackMode.Edit;
            dynamicOverlay.Redraw();
        }

        protected void buttonDeleteShape_Click(object sender, ImageClickEventArgs e)
        {
            LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["DynamicOverlay"];
            InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["shapeLayer"];
            
            shapeLayer.InternalFeatures.Remove(Session["FeatureID"].ToString());
            //shapeLayer.InternalFeatures.Clear();
            Map1.EditOverlay.TrackMode = TrackMode.None;
            dynamicOverlay.Redraw();
        }

        protected void Map1_Click(object sender, MapClickedEventArgs e)
        {
            LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["DynamicOverlay"];
            InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["shapeLayer"];

            shapeLayer.Open();
            Collection<Feature> selectedFeatures = shapeLayer.QueryTools.GetFeaturesContaining(e.Position, ReturningColumnsType.NoColumns);
            shapeLayer.Close();

            Session["FeatureID"] = selectedFeatures[0].Id;
        }

If you have any more questions please let me know,


Thanks,


Scott,



Thanks Scott, 
  
 There seems to be a problem with the attached file. 
 The include cs file only initiates a map, the class is called “DisplayASimpleMap” and that’s exactly what it does. 
  
 Runny 


Runny,


I'm sorry for that, please check the new attachment again, it is exact what you need,


Thanks,


Scott,



002_001_MapShapes.zip (3.16 KB)

Scott,


Thank you so much.

It works like a charm.


Runny.



Runny, 
  
 That’s great!  
  
 If you have any more questions please let me know, 
  
 Thanks, 
  
 Scott,