summaryrefslogtreecommitdiffstats
path: root/debian/missing-sources/leaflet.markercluster.js/DistanceGrid.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:45:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:45:13 +0000
commit3c99fde45db83b531c41c350ed4d0ac2a3c40c62 (patch)
treead5257daf9e41556ed73875ab56b69162dffdac1 /debian/missing-sources/leaflet.markercluster.js/DistanceGrid.js
parentAdding upstream version 1.1.0. (diff)
downloadicingaweb2-module-map-debian/1.1.0-3.tar.xz
icingaweb2-module-map-debian/1.1.0-3.zip
Adding debian version 1.1.0-3.debian/1.1.0-3debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/missing-sources/leaflet.markercluster.js/DistanceGrid.js')
-rw-r--r--debian/missing-sources/leaflet.markercluster.js/DistanceGrid.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/debian/missing-sources/leaflet.markercluster.js/DistanceGrid.js b/debian/missing-sources/leaflet.markercluster.js/DistanceGrid.js
new file mode 100644
index 0000000..eee7411
--- /dev/null
+++ b/debian/missing-sources/leaflet.markercluster.js/DistanceGrid.js
@@ -0,0 +1,118 @@
+
+L.DistanceGrid = function (cellSize) {
+ this._cellSize = cellSize;
+ this._sqCellSize = cellSize * cellSize;
+ this._grid = {};
+ this._objectPoint = { };
+};
+
+L.DistanceGrid.prototype = {
+
+ addObject: function (obj, point) {
+ var x = this._getCoord(point.x),
+ y = this._getCoord(point.y),
+ grid = this._grid,
+ row = grid[y] = grid[y] || {},
+ cell = row[x] = row[x] || [],
+ stamp = L.Util.stamp(obj);
+
+ this._objectPoint[stamp] = point;
+
+ cell.push(obj);
+ },
+
+ updateObject: function (obj, point) {
+ this.removeObject(obj);
+ this.addObject(obj, point);
+ },
+
+ //Returns true if the object was found
+ removeObject: function (obj, point) {
+ var x = this._getCoord(point.x),
+ y = this._getCoord(point.y),
+ grid = this._grid,
+ row = grid[y] = grid[y] || {},
+ cell = row[x] = row[x] || [],
+ i, len;
+
+ delete this._objectPoint[L.Util.stamp(obj)];
+
+ for (i = 0, len = cell.length; i < len; i++) {
+ if (cell[i] === obj) {
+
+ cell.splice(i, 1);
+
+ if (len === 1) {
+ delete row[x];
+ }
+
+ return true;
+ }
+ }
+
+ },
+
+ eachObject: function (fn, context) {
+ var i, j, k, len, row, cell, removed,
+ grid = this._grid;
+
+ for (i in grid) {
+ row = grid[i];
+
+ for (j in row) {
+ cell = row[j];
+
+ for (k = 0, len = cell.length; k < len; k++) {
+ removed = fn.call(context, cell[k]);
+ if (removed) {
+ k--;
+ len--;
+ }
+ }
+ }
+ }
+ },
+
+ getNearObject: function (point) {
+ var x = this._getCoord(point.x),
+ y = this._getCoord(point.y),
+ i, j, k, row, cell, len, obj, dist,
+ objectPoint = this._objectPoint,
+ closestDistSq = this._sqCellSize,
+ closest = null;
+
+ for (i = y - 1; i <= y + 1; i++) {
+ row = this._grid[i];
+ if (row) {
+
+ for (j = x - 1; j <= x + 1; j++) {
+ cell = row[j];
+ if (cell) {
+
+ for (k = 0, len = cell.length; k < len; k++) {
+ obj = cell[k];
+ dist = this._sqDist(objectPoint[L.Util.stamp(obj)], point);
+ if (dist < closestDistSq ||
+ dist <= closestDistSq && closest === null) {
+ closestDistSq = dist;
+ closest = obj;
+ }
+ }
+ }
+ }
+ }
+ }
+ return closest;
+ },
+
+ _getCoord: function (x) {
+ var coord = Math.floor(x / this._cellSize);
+ return isFinite(coord) ? coord : x;
+ },
+
+ _sqDist: function (p, p2) {
+ var dx = p2.x - p.x,
+ dy = p2.y - p.y;
+ return dx * dx + dy * dy;
+ }
+};