none
Remove ploygon from Shapes RRS feed

  • Question

  • Hi,

    We have plot the shape using geojson file. Now we want to remove any particular polygon. How can we achieve this. Anyone have sample code for this.

    Here is some part of code that we used to plot shape.

      var shapes = Microsoft.Maps.GeoJson.read(geoJsonText);

       map.entities.push(shapes);

    Here is plotted shape and we wanted to remove the highlighted polygon.

    Waiting for reply.

    Thanks!


    Balasaheb

    Monday, May 21, 2018 6:40 AM

All replies

  • Can what you are looking for a bit?   I can see the redbox is mainly covering polygon but it is overlapping multiple polygon.

    Are you looking to just remove the full polygon or remove the area covered by the red box?

    Did you want the ability to delete any polygon as needed or just to remove this single polygon once?

    Once we have more context we can provide the appropriate code sample.

    Monday, May 21, 2018 1:53 PM
    Moderator
  • Hi Stephen,

    Thanks for your reply.

    We wanted to remove full polygon. We wanted to remove single polygon once. 

    Thanks!


    Balasaheb

    Monday, May 21, 2018 2:32 PM
  • One way to do that would be to use metadata property if you're using that, see here: https://msdn.microsoft.com/en-us/library/mt712645.aspx.
    You could loop through your shapes to check for matching name in metadata, and than remove it.

    Tuesday, May 22, 2018 2:17 PM
    Moderator
  • If you have a reference to the polygon you want to remove (i.e. you clicked it). You can simply pass the polygon into the map.entities.remove function and it will be removed from the map. For example:

    Microsoft.Maps.Events.addHandler(polygon, 'click', function (e) { 
    	map.entities.remove(e.target);
    });


    [Blog] [twitter] [LinkedIn]

    Wednesday, May 23, 2018 4:36 PM