我想知道是否可以为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图层,您可以按照this example监听'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);


希望这可以帮助!

07-24 14:49