Leaflet 是否有任何可能的方法在传单中显示geojson的属性而不显示特性?

Leaflet 是否有任何可能的方法在传单中显示geojson的属性而不显示特性?,leaflet,geojson,Leaflet,Geojson,在传单中,我可以使用以下脚本可视化geojson层 L.geoJSON('district.json', { style: myStyle, onEachFeature: function(feature, layer) { layer.bindPopup(feature.properties.name); } }).addTo(map); 上面的代码显示了地图上的特征,也显示了单击地图时的名称属性。但我想要的是不同的。我想在地图上隐藏distric

在传单中,我可以使用以下脚本可视化geojson层

L.geoJSON('district.json', {
    style: myStyle,
    onEachFeature: function(feature, layer) {
       layer.bindPopup(feature.properties.name);     
  }
}).addTo(map);
上面的代码显示了地图上的特征,也显示了单击地图时的
名称
属性。但我想要的是不同的。我想在地图上隐藏
district.json
的功能,但当我单击
功能
位置时,它应该出现在弹出内容中。我尝试了以下风格

var myStyle = {
  fillColor: rgb(0,0,0,0),
  opacity: 0,
  strokeOpacity: 0,
}

这将隐藏图层,但当我单击地图时,不会弹出任何内容。在这种情况下是否有可能的样式?

您可以使用如下圆形标记:

L.geoJSON('district.json', {
    pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, {color: 'transparent', fillColor: 'transparent', radius: 20});
    },
    onEachFeature: function(feature, layer) {
       layer.bindPopup(feature.properties.name);     
    }
}).addTo(map);

这样,可以为每个特征添加一个透明的、不可见的圆标记。您也可以尝试不同的半径值,以获得更大或更小的可点击区域。

您只需将不透明度值更改为
0.01
,这样图层将从地图上消失,但仍保留弹出内容。 为此,请按照以下方式更改myStyle变量:

var myStyle = {
  fillColor: rgb(0,0,0,0.01),
  opacity: 0.01,
  strokeOpacity: 0.01,
}

这不是欲望的情况。因为我的数据是多边形的。但无论如何解决了我的问题