Skip to content

Instantly share code, notes, and snippets.

@codeofsumit
Last active January 2, 2019 12:29
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 codeofsumit/3f35a0ea4933cac28a1960a5838f5747 to your computer and use it in GitHub Desktop.
Save codeofsumit/3f35a0ea4933cac28a1960a5838f5747 to your computer and use it in GitHub Desktop.
Create a leaflet layer from geoJSON supporting circles
import { forEach } from 'lodash';
createLayersFromJson(data) {
const layers = [];
forEach(data, (geo, id) => {
L.geoJSON(geo, {
pointToLayer: (feature, latlng) => {
if (feature.properties.radius) {
return new L.Circle(latlng, feature.properties.radius);
} else {
return new L.Marker(latlng);
}
},
onEachFeature: (feature, layer) => {
layer.push(layer);
},
});
});
return layers;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment