首页 > 解决方案 > 如何过滤传单地图中的工具提示?

问题描述

我有一个序列号从 100 到 999 的文件。使用这个文件,我想过滤掉三个数字以显示在地图上。我已经能够过滤多边形和圆形标记,但对于工具提示我没有成功。这是我一直在使用的代码,我应该如何解决这个问题?

var po_txt = new L.layerGroup();
$.getJSON("../data/po_txt.geojson", function(json) {

var pointLayer = L.geoJSON(null, {
pointToLayer: function(feature,latlng){

// Filter file
if (feature.properties.Po > 125 && feature.properties.Po < 128 || feature.properties.Po === 129  ) return true

// .bindTooltip can't use straight 'feature.properties.attribute'

label = String(feature.properties.Po) 
return new L.CircleMarker(latlng, {
radius: 0,
}).bindTooltip(label, {permanent: true, direction: "center", className: "my1-labels"}).openTooltip();
}
});
pointLayer.addData(json)
pointLayer.addTo(po_txt);

})

我确实设法解决了这个问题,需要为过滤器添加一个函数,下面的代码使它工作......

var po_txt = new L.layerGroup();
$.getJSON("../data/po_txt.geojson", function(json) {

// Filter
function po_filt (feature){
if (feature.properties.Po > 125 && feature.properties.Po < 128 || feature.properties.Po === 129 ) return true
}
var pointLayer = L.geoJSON(null, {
filter: po_filt,
pointToLayer: function(feature,latlng){
label = String(feature.properties.Po) // .bindTooltip can't use straight 'feature.properties.attribute'
return new L.CircleMarker(latlng, {
  radius: 0,
}).bindTooltip(label, {permanent: true, direction: "center", className: "my1-labels"}).openTooltip();
}
});
pointLayer.addData(json)
pointLayer.addTo(po_txt);

})

标签: textfilterleaflet

解决方案


推荐阅读