我想知道是否有办法为 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"
});
}
});
Run Code Online (Sandbox Code Playgroud)
尝试了上面的代码,但它不起作用。
小智 1
对于 GeoJSON 层,您可以监听“featureparse”事件来绑定弹出窗口,如本示例所示。沿着这些思路:
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);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
15262 次 |
| 最近记录: |