json = L.geoJson(data, {
onEachFeature: function(feature, layer) {
layer.bindPopup(L.Util.template("<h1>{title}</h1><p>{description}</p>", {
title: feature.properties.title,
description: feature.properties.description
}));
category = feature.properties.location_type;
if (typeof categories[category] == "undefined") {
categories[category] = [];
}
categories[category].push(layer);
},
pointToLayer: function(feature, position) {
return L.marker(position, {icon: L.AwesomeMarkers.icon(styles[feature.properties.location_type])});
}
});
cluster = L.markerClusterGroup({
chunkedLoading: true,
chunkInterval: 500
});
cluster.addTo(map);
map.on("overlayadd", function(e) {
map.removeLayer(e.layer);
cluster.addLayer(e.layer);
})
map.on("overlayremove", function(e) {
cluster.removeLayer(e.layer);
})
for (var category in categories) {
overlays[styles[category].type] = L.layerGroup(categories[category]);
}