Leaflet 传单js:如何为L.CircleMarker创建工具提示?

Leaflet 传单js:如何为L.CircleMarker创建工具提示?,leaflet,Leaflet,我想知道是否有办法设置L.CircleMarker的工具提示 var geojsonLayerVessel = new L.GeoJSON(null, { pointToLayer: function (latlng){ return new L.CircleMarker(latlng, { radius: 5, fillColor: "#ff7800", color: "#000", weight: 1,

我想知道是否有办法设置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”事件以绑定弹出窗口,如所示。大致如下:

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);

希望这有帮助

这不适用于
电路标记器
。 但是您可以创建一个小的
DivIcon
,并将其设置为圆角样式。
DivIcon
s确实支持
'title'
选项

要作为pointToLayer提供的函数:

function (latlng){
    return L.marker(latlng, 
                    { icon : L.divIcon({ className : 'circle',
                                         iconSize : [ 5, 5 ]}),
                      title: 'test'});
}
以及div的样式:

div.circle {
    background-color: #ff7800;
    border-color: black;
    border-radius: 3px;
    border-style: solid;
    border-width: 1px;
    width:5px;
    height:5px;
}

问题是添加工具提示,而不是弹出窗口。标题仅在标记有图标时添加,而不是添加到圆圈标记。flup的小提琴已经过时。对于那些仍然好奇的人,请参阅更新的小提琴: