Skip to content

Instantly share code, notes, and snippets.

@ns-1m
Forked from mourner/geojson.js
Created July 8, 2012 02:40
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 ns-1m/3069082 to your computer and use it in GitHub Desktop.
Save ns-1m/3069082 to your computer and use it in GitHub Desktop.
Leaflet GeoJSON API proposal
var geojson = L.geoJson(data, {
// style for all vector layers (color, opacity, etc.) (optional)
getStyle: 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 layer (optional)
onEachLayer: 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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment