I have a GeoJSON dataset which has points and polygons. I have a simple Leaflet code which reads them into a map, like this:
var MyLayer = new L.GeoJSON.AJAX("/UrbanSyntax/Desarrollo/twitter/data/boxtest.json", {
pointToLayer: function(feature, latlng) {
return new L.CircleMarker(latlng, {
radius: 3,
fillOpacity: 0.75,
color: getColor(feature.properties.created_at)
});
},
onEachFeature: function(feature, layer) {
layer.bindPopup(
feature.properties.created_at + '<br />'
+ feature.geometry.coordinates + '<br />'
+ feature.properties.user )
}
});
Most of the data are polygons, but I need to translate them to points (the polygon center) to simplify the map. I don't want to change the original GeoJSON when it's parsed since those polygons might be needed later.
I don't know where to "inject" code to read the polygon bounds, calculate a center and send a latlng to make a circlemarker. As it is now, the code reads the points and polygons in the json ok, but there are too many polygons in the data so the browser freezes. It works all right when I filter out the polys from the JSON and just map the points. I'm running out of ideas, and Leaflet documentation is so scarce in the JSON chapter... I just need a way to put an if in the pointToLayer code, separate the points from the polys, and map them all as points.
Any ideas?