我有一个序列号从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);
})