[Pkg-javascript-commits] [leaflet-markercluster] 179/479: Make getNearObject always return the closest point to make the clusters do stupid things less often
Jonas Smedegaard
dr at jones.dk
Thu Oct 16 16:00:27 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository leaflet-markercluster.
commit c1aff5cba2f3f2d245737867683a92ba6f8dff52
Author: danzel <danzel at localhost.geek.nz>
Date: Mon Aug 27 13:02:45 2012 +1200
Make getNearObject always return the closest point to make the clusters do stupid things less often
---
src/DistanceGrid.js | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/DistanceGrid.js b/src/DistanceGrid.js
index 70df5fb..e7632fd 100644
--- a/src/DistanceGrid.js
+++ b/src/DistanceGrid.js
@@ -74,7 +74,9 @@ L.DistanceGrid.prototype = {
getNearObject: function (point) {
var x = this._getCoord(point.x),
y = this._getCoord(point.y),
- i, j, k, row, cell, len, obj;
+ i, j, k, row, cell, len, obj, dist,
+ closestDistSq = this._sqCellSize,
+ closest = null;
for (i = y - 1; i <= y + 1; i++) {
row = this._grid[i];
@@ -86,16 +88,17 @@ L.DistanceGrid.prototype = {
for (k = 0, len = cell.length; k < len; k++) {
obj = cell[k];
- if (this._sqDist(obj._dGridPoint, point) < this._sqCellSize) {
- return obj;
+ dist = this._sqDist(obj._dGridPoint, point);
+ if (dist < closestDistSq) {
+ closestDistSq = dist;
+ closest = obj;
}
}
}
}
}
}
-
- return null;
+ return closest;
},
_getCoord: function (x) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet-markercluster.git
More information about the Pkg-javascript-commits
mailing list