相关疑难解决方法(0)

如何删除包含它的topojson图层时的传单标签

我正在尝试创建一个可视化某些数据的交互式地图.

我使用了传单贴图和topojson图层.接下来,我尝试使用leaflet标签插件在每个topojson多边形上添加静态标签,即标签应始终在那里,不应对mouseover事件做出反应.

我尝试使用实现bindLabel()方法noHide:true,但它似乎没有工作.因此,我在传单(geojson)多边形上实现了提供给这个问题的简单标签的解决方案.我成功地添加了静态标签.

然后,我有一个函数删除click事件上的topojson多边形.我本来应该删除这个特殊多边形上的标签,但它似乎无法实现.

这是我添加topojson图层和标签的方法:

function addRegions(map) {
    var regionLayer = new L.TopoJSON();
    $.getJSON('region.topo.json').done(addRegionData);

    function addRegionData(topoData) {
        regionLayer.addData(topoData);
        regionLayer.addTo(map);
        regionLayer.eachLayer(addLabel);
        regionLayer.eachLayer(handleLayer);
    }
    function handleLayer(layer) {
        layer.on({
            click: clickAction
        });
    }

// Here's the code for adding label
    function addLabel(layer) {
        var label = new L.Label();  
        label.setContent(layer.feature.properties.REGION);
        label.setLatLng(layer.getBounds().getCenter());
        map.showLabel(label);
    }

// Here's the code that removes a polygon when it is clicked and retains the previously removed polygon
    function clickAction(e) {
        regionLayer.eachLayer(function(layer){
            map.addLayer(layer); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery leaflet topojson

5
推荐指数
1
解决办法
1646
查看次数

标签 统计

javascript ×1

jquery ×1

leaflet ×1

topojson ×1