New StackOverflow Question: Does anyone know how to remove geoJson polygon from a layer with mapboxgl?

3 views
Skip to first unread message

stacko...@mg.bodar.com

unread,
Mar 7, 2017, 5:10:44 AM3/7/17
to total...@googlegroups.com

Does anyone know how to remove geoJson polygon from a layer with mapboxgl?

Asked by z3non on 2017-01-21T08:11:08Z

Reply on StackOverflow

I am running into some difficulties to remove a geojon polygon from a layer with mapboxGL.

Here the following code to add my geoson polygons where array_geo is a polygon geometry. Adding the polygon works like a charm, but I still did not find how to delete my polygons. The only trick I found is to use the removeLayer(id) function which delete the entire layer.

var id="mylayer";
itemObj = {
    type:"Feature",
    properties: {
            description: description,
            type: 23
    },
    geometry: {
        type: "Polygon",
        coordinates: array_geo
    },

};
mpolygons.push(itemObj);
map.addSource(id,{
    "type":"geojson",
    "data":{
    "type":"FeatureCollection",
    "features":mypolygons
}

self.map.addLayer({
    "id": id,
    "source":id,
    "type":"fill",
    "layout": {'visibility':'visible'},
    "paint": {
        'fill-color': '#088',
        //'fill-opacity': 0.8
    }
})

Thanks !

Reply on StackOverflow
Reply all
Reply to author
Forward
0 new messages