-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
closestLayerPoint doesn't find point on the edge between last and first point of Polygon #9098
Comments
Fix, that worked for me. L.Polygon.prototype.closestLayerPoint = function(p) {
let minPoint = L.Polyline.prototype.closestLayerPoint.call(this, p);
let minDistance = minPoint ? minPoint.distance * minPoint.distance : Infinity;
const closest = L.LineUtil._sqClosestPointOnSegment;
for (let j = 0, jLen = this._parts.length; j < jLen; j++) {
const len = this._parts[j].length;
if (len == 0)
continue;
const sqDist = closest(p, this._parts[j][0], this._parts[j][len-1], true);
if (sqDist < minDistance) {
minDistance = sqDist;
minPoint = closest(p, this._parts[j][0], this._parts[j][len-1]);
}
}
if (minPoint) {
minPoint.distance = Math.sqrt(minDistance);
}
return minPoint;
} |
Hey @se-ti can you tell me , how i can work on this issue |
Fix it? |
Have raised a PR for this one |
Sorry, @MadhukarRagaji, your fix is a no go. There's a difference between _parts and latlngs arrays when clipping occures. So i'd expect wierd bugs with your (and my fix too) when polygon doesn't fit in screen, like country borders often do. |
ah, what if we handle this as a specific edge case just for a polygon? |
ah okay will update if I find something |
See my comments on reproducing clipping errors below your pr. |
Checklist
Steps to reproduce
Reason: Even though Polygon extends Polyline, it doesn't fix polyline's closestLayerPoint method,
which doesn't take into account the edge [length-1, 0].
Leaflet/src/layer/vector/Polyline.js
Line 98 in 641a382
That's correct for polyline, but not for polygon.
Expected behavior
since point [0, 0.5] lies on the edge [[0, 0], [0, 1]], i'd expect closestLayerPoint to return point, that would be reprojected back to [0, 0.5]
Current behavior
closestLayerPoint returns point, that is reprojected back to [0.25, 0.25].
Minimal example reproducing the issue
https://plnkr.co/edit/BmMqSBJYM3QoOiO6
Environment
The text was updated successfully, but these errors were encountered: