Setting Marker Titles

2,716 views
Skip to first unread message

Scott Vanderbilt

unread,
Oct 8, 2012, 11:19:39 PM10/8/12
to leafl...@googlegroups.com
I'm just starting to use Leaflet, so please excuse the elementary question.

Is there a way to set Marker titles after creation? Marker does have methods for setting the icon, coordinates, and opacity, but I see no similar method for title. Which strikes me as a rather odd omission, so I'm figuring there must be some other manner of accomplishing this task that's just not popping out at me.

Thanks in advance.


Paulo Vieira

unread,
Oct 9, 2012, 1:45:40 PM10/9/12
to leafl...@googlegroups.com
On Tue, Oct 9, 2012 at 4:19 AM, Scott Vanderbilt <data...@gmail.com> wrote:
I'm just starting to use Leaflet, so please excuse the elementary question.

Is there a way to set Marker titles after creation? Marker does have methods for setting the icon, coordinates, and opacity, but I see no similar method for title. Which strikes me as a rather odd omission, so I'm figuring there must be some other manner of accomplishing this task that's just not popping out at me.

It seems there's no method for that. You can do it directly this way:

  var myMarker = L.marker([lat, lng], {'title':'initial title'}).addTo(map);
  // do stuff
  myMarker._icon.title = "another title";

But it's ugly and might not work in the next releases.

Take a look also at the excellent plugin Leaflet.label, which is a much better solution:



Scott Vanderbilt

unread,
Oct 9, 2012, 3:56:50 PM10/9/12
to leafl...@googlegroups.com
Paulo:

Thank you for that. I was told the same thing on the IRC channel as well. The Leaflet.label plug-in is a perfect solution. It also gives me a way to label PolyLines, which is another goal I wanted to accomplish.

Cheers.

- Scott
 
Reply all
Reply to author
Forward
0 new messages