0

I am able to add label to circlemarker like this

L.circleMarker(points[i],{title: 'unselected'}).bindLabel('Destination').addTo(map);

This adds label which appears on mouse hover on circle marker.

But I want to add static label which will appear regardless of mouse is on that circle marker or not.

I am referring this demo http://leaflet.github.com/Leaflet.label/ for adding static label to circle marker but some how I am not able to do it. It is working fine with markers but with circle Markers static label is not working.

Also is there any other method to add label on circle marker ?

2 Answers 2

2

I guess it's already too late to answer, but just for clarification:

The developer himself explains why it is not yet possible to add static labels to polygons.

Leaflet.label just doesn't support static labels for Vectors. I didn't add it as it is hard to decide where to place the label. E.g. If the vector covers more than the screen the label might not be visible even thought the vector is. Where should the label be shown? This could be different for the different shape. E.G. first point for polygon, center for circles, corner for rectangles.

See here: https://github.com/Leaflet/Leaflet.label/issues/15

EDIT: For your information, I solved my own problem by using the "L.divIcon" function that comes with Leaflet built-in. I had to input each and every coordinate for the labels I need to put by hand, and adding each within a loop function.

1

I guess what you want to use is the onEachFeature function. See the docs for more info. Here is an example of mine with an on click event. Feel free to adapt it to your needs (like on('load')) maybe.

function onEachFeature(feature, layer) {
    layer.on('click', function (e) {
        var id = feature.properties.id
        layer.bindLabel(feature.properties.XXX)
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.