4

我想知道是否有办法为 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"
    });
}
}); 

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

4

2 回答 2

1

这不适用于CircleMarkers. 但是你可以创建一点DivIcon并用圆角设计它。 DivIcons 确实支持该'title'选项。

http://jsfiddle.net/63teycsq/1/

作为 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;
}
于 2013-01-26T14:18:17.650 回答
0

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

希望这可以帮助!

于 2012-06-27T20:49:40.573 回答