Created
July 6, 2012 21:40
-
-
Save mourner/3062900 to your computer and use it in GitHub Desktop.
Leaflet GeoJSON API proposal
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 geojson = L.geoJson(data, { | |
// style for all vector layers (color, opacity, etc.), either function or object (optional) | |
style: function (feature) { | |
return feature.properties && feature.properties.style; | |
}, | |
// function for creating layers for GeoJSON point features (optional) | |
pointToLayer: function (feature, latlng) { | |
return L.marker(latlng, { | |
icon: myCustomIcon, | |
title: feature.properties && feature.properties.name | |
}); | |
}, | |
// function that gets called on every created feature layer (optional) | |
onEachFeature: function (feature, layer) { | |
var content = feature.properties && feature.properties.popupContent; | |
if (content) { | |
layer.bindPopup(content); | |
} | |
}, | |
// function that decides whether to show a feature or not (optional) | |
filter: function (feature, layer) { | |
return !(feature.properties && feature.properties.isHidden); | |
} | |
}).addTo(map); | |
// add more GeoJSON data | |
geojson.addData(moreData); | |
map.fitBounds(geojson.getBounds()); |
Thanks for sharing this code this really help to solve my problem.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
all goes on 'layeradd' event, hope I'm not too late.