在Google地图中隐藏/删除特定的GoogleMapsOverlay

我通过多选将geojson文件用于Google地图。但是当我尝试删除叠加层时,它不起作用。这是我用于添加和删除的代码。 我需要知道如何从地图中删除所选的geojson文件

    var deckOverlay ;
    deckOverlay = new deck.GoogleMapsOverlay({
                layers: [
                    new deck.GeoJsonLayer({
                        id: 'layerId',data: 'path of geojson file',filled: true,pointRadiusMinPixels: 2,opacity: 0.5,pointRadiusScale: 2000,getFillColor: f => (f.properties.COLOR),wireframe: true,pickable: true,}),+
                    new deck.ArcLayer({
                        id: 'arcs',data: Layer_Id,dataTransform: d => d.features.filter(f => f.properties.scalerank < 4),getsourcePosition: f => [-0.4531566,51.4709959],// London
                        getTargetPosition: f => f.geometry.coordinates,getsourceColor: [0,128,200],getTargetcolor: [200,80],getWidth: 1
                    })
                ]
            });   

    if (checked) {
        deckOverlay.setMap(map); // Set multiple overlays working
    }
     else {
        deckOverlay.setMap(null); // Remove Option Not Working
        deckOverlay = null; 
    }
corlins 回答:在Google地图中隐藏/删除特定的GoogleMapsOverlay

使用数据层。

要加载地图

map.data.loadGeoJson(Layer_Id); 

要删除特定图层

map.data.forEach(function (feature) {
if (feature.getProperty('myprop') == myprop) { 
map.data.remove(feature);
}
}); 

要删除所有图层

map.data.forEach(function (feature) { 
map.data.remove(feature);
}); 

仅供参考,请在json文件中使用颜色代码作为十六进制,而不是RGB或RGBA

本文链接:https://www.f2er.com/3125599.html

大家都在问