Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 爱奥尼亚+;传单如何在重画之前清除现有图层?_Ionic Framework_Leaflet_Leaflet.draw - Fatal编程技术网

Ionic framework 爱奥尼亚+;传单如何在重画之前清除现有图层?

Ionic framework 爱奥尼亚+;传单如何在重画之前清除现有图层?,ionic-framework,leaflet,leaflet.draw,Ionic Framework,Leaflet,Leaflet.draw,我正在使用我的ionic应用程序的传单在上传的平面图上绘制多边形。一切都很顺利。在重新绘制地图之前,我很难清除现有的多边形,这会导致多个图层堆叠起来 以下是我目前正在做的事情: .ts文件 ngOnInit() { // get saved polygons from db ... .subscribe((res => { res.forEach(data => { this.drawPolygon(data);

我正在使用我的ionic应用程序的传单在上传的平面图上绘制多边形。一切都很顺利。在重新绘制地图之前,我很难清除现有的多边形,这会导致多个图层堆叠起来

以下是我目前正在做的事情:

.ts文件

ngOnInit() {
    // get saved polygons from db
   ...
   .subscribe((res => {
       res.forEach(data => {
           this.drawPolygon(data);
       });
   }));
}

...


// Draw each of the saved polygons
drawPolygon(data) {
    if (data.polygon.geometry) {
        let shape = {
            polygon: data,
            type: data.polygon.type,
            geometry: {
                type: data.polygon.geometry.type,
                coordinates: data.polygon.geometry.coordinates
            },
            properties: {}
        };

        // Remove all existing layers


        L.geoJSON(shape, {
            onEachFeature: this.onEachFeature.bind(this),
        }).addTo(this.myMay);
    }
}


// onEachFeature method to trigger popover
onEachFeature(feature, layer) {
    layer.on('click', event => {
        let popover = this.popoverCtrl.create('MyComponent', {
        layer: feature
    });

    popover.present();

    }, this);
}
我已经尝试了各种方法
removeLayer
clearLayers
,甚至在没有运气的情况下删除了地图。非常感谢您的任何建议

编辑


如果我在完成所有操作后进行页面刷新,则所有附加层都将被删除,而单个层将保持原样。

若要删除所有层,假设您的地图对象称为myMap,则以下代码将起作用:

myMap.eachLayer(function (layer) {
    myMap.removeLayer(layer);
});

不过,我不会把它放在drawPolygon中——在添加新地图之前,ngOnInit或调用它的地方似乎是清除地图数据的更好地方。

谢谢你的建议。我一定有什么安排,高飞。在您的帮助下,我可以删除我的地图图层,但没有绘制的图层(多边形)。