Created
September 5, 2013 18:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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