fix canvas polygon click on border

This commit is contained in:
Mourner 2011-06-21 14:46:16 +03:00
parent 436915617a
commit 032ee9331b
2 changed files with 7 additions and 5 deletions

View File

@ -16,7 +16,7 @@ L.Polygon.include(L.Path.SVG || !L.Path.CANVAS ? {} : {
// TODO optimization: check if within bounds first // TODO optimization: check if within bounds first
if (L.Polyline.prototype._containsPoint.call(this, p)) { if (L.Polyline.prototype._containsPoint.call(this, p, true)) {
// click on polygon border // click on polygon border
return true; return true;
} }

View File

@ -8,13 +8,15 @@ L.Polyline.include(L.Path.SVG || !L.Path.CANVAS ? {} : {
} }
}, },
_containsPoint: function(p) { _containsPoint: function(p, closed) {
var i, j, len, len2, dist, part; var i, j, k, len, len2, dist, part;
for (i = 0, len = this._parts.length; i < len; i++) { for (i = 0, len = this._parts.length; i < len; i++) {
part = this._parts[i]; part = this._parts[i];
for (j = 0, len2 = part.length; j < len2 - 1; j++) { for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
dist = L.LineUtil.pointToSegmentDistance(p, part[j], part[j+1]); if (!closed && (j === 0)) { continue; }
dist = L.LineUtil.pointToSegmentDistance(p, part[k], part[j]);
if (dist <= this.options.weight / 2) { if (dist <= this.options.weight / 2) {
return true; return true;