Witam,
w jaki sposób mogę pobrać środki punktów siatki stworzonej przez d3-hexbin.js według dokumentacji odpowiada za to funkcja # hexbin.centers(). Załączam poniżej część mojego kodu ponieważ funkcja nie zwraca mi punktów siatki.
Funkcja hexbin.centers();
hexbin.centers = function() {
var centers = [],
j = Math.round(y0 / dy),
i = Math.round(x0 / dx);
for (var y = j * dy; y < y1 + r; y += dy, ++j) {
for (var x = i * dx + (j & 1) * dx / 2; x < x1 + dx / 2; x += dx) {
centers.push([x, y]);
}
}
return centers;
};
Moj kod wywołania siatki
// Create the hex layout
this._hexLayout = d3_hexbin()
.radius(this.options.radius)
.x(function(d) { return d.point[0]; })
.y(function(d) { return d.point[1]; });
zwracanie punktow siatki
centers: function() {
var points_table = [];
points_table = this._hexLayout.centers();
for (let i=0; i<points_table.length; i++) {
console.log('licznik pętli: ' + i);
console.log('element: ' + points_table[i]);
}
return points_table;
},
Odwolanie sie do funkcji
var hexLayer = L.hexbinLayer(options).addTo(map)
hexLayer.centers();