I'm trying to create a cluster with categories using PruneCluster around my GeoJSON layers.
As the example in GitHub They are creating randomly some markers then adding them to the cluster.
I did the same, I got the coords from a GeoJSON layer, stored it in a variable then added it to Prunecluster as follows :
leafletView.BuildLeafletClusterIcon = function(cluster) {
var e = new L.Icon.MarkerCluster();
e.stats = cluster.stats;
e.population = cluster.population;
return e;
};
var colors = ['rgb(10, 94, 219)', 'rgb(253, 152, 1)', 'rgb(3, 180, 11)'],
pi2 = Math.PI * 2;
L.Icon.MarkerCluster = L.Icon.extend({
options: {
iconSize: new L.Point(44, 44),
className: 'prunecluster leaflet-markercluster-icon'
},
createIcon: function() {
// based on L.Icon.Canvas from shramov/leaflet-plugins (BSD licence)
var e = document.createElement('canvas');
this._setIconStyles(e, 'icon');
var s = this.options.iconSize;
e.width = s.x;
e.height = s.y;
this.draw(e.getContext('2d'), s.x, s.y);
return e;
},
createShadow: function() {
return null;
},
draw: function(canvas, width, height) {
var lol = 0;
var start = 0;
for (var i = 0, l = colors.length; i < l; ++i) {
var size = this.stats[i] / this.population;
if (size > 0) {
canvas.beginPath();
canvas.moveTo(22, 22);
canvas.fillStyle = colors[i];
var from = start + 0.14,
to = start + size * pi2;
if (to < from) {
from = start;
}
canvas.arc(22, 22, 22, from, to);
start = start + size * pi2;
canvas.lineTo(22, 22);
canvas.fill();
canvas.closePath();
}
}
canvas.beginPath();
canvas.fillStyle = 'white';
canvas.arc(22, 22, 18, 0, Math.PI * 2);
canvas.fill();
canvas.closePath();
canvas.fillStyle = '#555';
canvas.textAlign = 'center';
canvas.textBaseline = 'middle';
canvas.font = 'bold 12px sans-serif';
canvas.fillText(this.population, 22, 22, 40);
}
});
let myLayerOptionsArbre = {
pointToLayer: createCustomIcon,
onEachFeature: function(feature, layer) {
layer.bindTooltip(feature.properties.titre);
layer.on({
click: onMarkerClick
});
coordsArb.push(feature.geometry.coordinates);
}
}
var arb = arbres
var arbre = new L.GeoJSON(arb, myLayerOptionsArbre)
var ap = {}
for (var i = 0; i < coordsAP.length; i++) {
ap = new PruneCluster.Marker(coordsAP[i][1], coordsAP[i][0]);
console.log(typeof ap)
console.log("hey", coordsAP[i][1])
ap.category = AIRES_PROTEGEES;
leafletView.RegisterMarker(ap);
}
leafletView.ProcessView();
mymap.addLayer(leafletView)
Now on my map I have the clusters around new markers and the GeoJSON layers. When I read the doc, I found that Prunecluster does not support GeoJSON.
Now if I just work with markers, How can I attach them to the properties of the geojson features, because I'm building custom popups with the function onMarkerClick
called when a geojson feature is clicked.
So if you have an idea about how to achieve that I would be pleased.
onEachFeature
option of GeoJSON layer creation?