Skip to content

Instantly share code, notes, and snippets.

@jacobtoye
Created September 5, 2013 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobtoye/6454046 to your computer and use it in GitHub Desktop.
Save jacobtoye/6454046 to your computer and use it in GitHub Desktop.
Adding Leaflet.label to a Leaflet map using GeoJSON as the data source
var data = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "two"
},
"geometry": {
"type": "Point",
"coordinates": [
175.27266025543213,
-37.796627531656064
]
}
},
{
"type": "Feature",
"properties": {
"name": "three"
},
"geometry": {
"type": "Point",
"coordinates": [
175.27497768402097,
-37.787369160539605
]
}
},
{
"type": "Feature",
"properties": {
"name": "one"
},
"geometry": {
"type": "Point",
"coordinates": [
175.26300430297852,
-37.78740307610388
]
}
}
]
}
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18}),
map = new L.Map('map', {layers: [cloudmade], center: new L.LatLng(-37.7972, 175.2756), zoom: 15 });
L.geoJson(data, {
pointToLayer: function (feature, latLng) {
return L.label({ noHide: true }, this)
.setContent(feature.properties.name)
.setLatLng(latLng);
}
}).addTo(map);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment