text - 如何过滤传单地图中的工具提示?
问题描述
我有一个序列号从 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);
})
解决方案
推荐阅读
- sql-server - 使用 Alter Database 选项创建过程
- r - 如何选择与R中列表中的项目相等的行?
- intellij-idea - PhpStorm Live Templates 的 Groovy 脚本给出建议框?
- node.js - 如何将数据从mongodb发送到express js中的get方法
- android - android如何在响应错误时删除代码缓存
- python - 如何汇总引用其他数据框的总数
- php - PHP AJAX JSON - 将输入转换为 JSON 和其他 PHP 文件获取价值
- javascript - 如何为隐藏/显示编写此代码 - 添加/删除类 - 在 jQuery 中更优化?
- python - Python:如何将系列/列中的相同数字更改为其他值?
- python - 如何在 pandas DataFrame 中为给定索引级别设置值