gpt4 book ai didi

传单 js : how to create tooltips for L. CircleMarker?

转载 作者:行者123 更新时间:2023-12-02 13:42:49 25 4
gpt4 key购买 nike

我想知道是否有办法为 L.CircleMarker 设置工具提示?

var geojsonLayerVessel = new L.GeoJSON(null, {
pointToLayer: function (latlng){
return new L.CircleMarker(latlng, {
radius: 5,
fillColor: "#ff7800",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8,
title: "test"
});
}
});

尝试了上面的代码,但不起作用。

最佳答案

对于 GeoJSON 层,您可以监听“featureparse”事件来绑定(bind)弹出窗口,如 this example 。大致如下:

var geoJsonLayer = new L.GeoJSON(null,{
pointToLayer: function (latlng){
return new L.CircleMarker(latlng, {
radius: 5,
fillColor: "#ff7800",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8,
});

geoJsonLayer.on('featureparse', function(e){
//Now you can bind popups to features in the layer, and you have access to
//attributes on the GeoJSON object through e.properties:
e.layer.bindPopup('Hello! ' + e.properties.someProperty);
});

//now you add some some data to your layer and add it to the map....
geoJsonLayer.addGeoJSON(someGeoJson);
map.addLayer(geoJsonLayer);

希望这有帮助!

关于传单 js : how to create tooltips for L. CircleMarker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11222538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com