javascript - 标记geojson地图的特征:如何控制标签的位置
问题描述
我已经大大简化了代码,但问题仍然存在。
我有一个 geoJSON 地图,每个县都有一个特征。我想用县名称来标记县,该名称在属性中可用。我通过向 OnEachFeature 方法添加代码来做到这一点。标签的位置是错误的,并且在地图缩放时不会改变。
这是我的代码:
function onEachFeature(feature, layer) {
container = L.DomUtil.get('label-container')
coords = feature.geometry.coordinates[0][0];
coords2 = [coords[1],coords[0]];
container.innerHTML = "label";
var pos = map.latLngToLayerPoint(new L.latLng(coords2));
op = new L.Point(pos.x,pos.y);
L.DomUtil.setPosition(container, op);
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
});
}
解决方案
推荐阅读
- php - 这个雄辩的方法的查询范围?
- shell - csh 脚本 - 传递变量并从另一个 csh 脚本调用 csh 脚本
- docker - 在启动 docker 容器之前删除文件
- c++ - 为什么随机数生成器不在 void 函数中随机化数字,而是在 main 函数中随机化?
- twilio - 在twilio中获取来电者的号码
- php - 如何在codeigniter 4的数据库中上传具有随机名称的图像
- python-3.x - 没有找到多个包的匹配分布
- python - 为什么我不能使用这个 python 应用程序?
- symfony - Symfony - Composer 安装了 maker-bundle 并忘记了 --dev
- ios - Swift:在 ARKit 中获取人脸跟踪的 TruthDepth 相机参数