npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leaflet-label

v0.2.1-0

Published

Labels for leaflet maps

Downloads

2,693

Readme

Leaflet.label

NOTE: lastest Leaflet.label master requires Leaflet 0.7-dev

Leaflet.label is plugin for adding labels to markers & shapes on leaflet powered maps.

Check out the demo.

##Usage examples

If you want to just bind a label to marker that will show when the mouse is over it, it's really easy:

L.marker([-37.7772, 175.2606]).bindLabel('Look revealing label!').addTo(map);

Path overlays works the same:

L.polyline([
	[-37.7612, 175.2756],
	[-37.7702, 175.2796],
	[-37.7802, 175.2750],
]).bindLabel('Even polylines can have labels.').addTo(map)	

If you would prefer the label to be always visible set the noHide: true option and call showLabel() once added to the map:

L.marker([-37.785, 175.263])
	.bindLabel('A sweet static label!', { noHide: true })
	.addTo(map);

##Options

When you call bindLabel() you can pass in an options object. These options are:

  • noHide: doesn't attach event handler for showing/hiding the label on mouseover/out.
  • className: the css class to add to the label element
  • direction: one of left|right(default)|auto. The direction the label displays in relation to the marker. auto will choose the optimal direction depending on the position of the marker.
  • pane: which map pane to put the label into. By default, the markerPane will be used for markers, and the popupPane for other objects.

E.g. To create a static label that automatically positions the label

var myIcon = L.icon({
	iconUrl: 'my-icon.png',
	iconSize: [20, 20],
	iconAnchor: [10, 10],
	labelAnchor: [6, 0] // as I want the label to appear 2px past the icon (10 + 2 - 6)
});
L.marker([-37.7772, 175.2606], {
	icon: myIcon
}).bindLabel('My label', {
	noHide: true,
	direction: 'auto'
});

##Positioning the label for custom icons

The label is positioned relative to the L.Icon's iconAnchor option. To reposition the label set the labelAnchor option of your icon. By default labelAnchor is set so the label will show vertically centered for the default icon (L.Icon.Default).

E.g. Vertically center an icon with iconAnchor set as the center of the icon:

var myIcon = L.icon({
	iconUrl: 'my-icon.png',
	iconSize: [20, 20],
	iconAnchor: [10, 10],
	labelAnchor: [6, 0] // as I want the label to appear 2px past the icon (10 + 2 - 6)
});
L.marker([-37.7772, 175.2606], {
	icon: myIcon
}).bindLabel('Look revealing label!').addTo(map);

When positioning the label L.Label includes a 6px horizontal padding. you will need to take this into account when setting labelAnchor.

##Setting the opacity of a label

You can set the opacity of a label by calling the setOpacity method on L.Marker. By default the opacity will either be 0 or 1.

// Sets opacity of marker to 0.3 and opacity of label to 1
markerLabel.setOpacity(0.3);

// Sets opacity of marker to 0.3 and opacity of label to 0.3
markerLabel.setOpacity(0.3, true);

// Sets opacity of marker to 0 and opacity of label to 0
markerLabel.setOpacity(0);
markerLabel.setOpacity(0, true);

// Sets opacity of marker to 1 and opacity of label to 1
markerLabel.setOpacity(1);
markerLabel.setOpacity(1, true);

##Alternative label plugin

My previous label plugin is still available at https://github.com/jacobtoye/Leaflet.iconlabel. This plugin is a little harder to use, however if you want to have both the icon and label bound to the same event this plugin is for you.