From 832b43ac587553372264046a98f769beb06d4b6f Mon Sep 17 00:00:00 2001 From: Per Liedman Date: Mon, 28 Dec 2015 20:53:26 +0100 Subject: [PATCH] Use all projected coords when calculating Polyline's pixel bounds. Close #3968. Close #4020. --- src/layer/vector/Polyline.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/layer/vector/Polyline.js b/src/layer/vector/Polyline.js index 14afad2f..bcb7ff79 100644 --- a/src/layer/vector/Polyline.js +++ b/src/layer/vector/Polyline.js @@ -129,23 +129,22 @@ L.Polyline = L.Path.extend({ }, _project: function () { + var pxBounds = new L.Bounds(); this._rings = []; - this._projectLatlngs(this._latlngs, this._rings); + this._projectLatlngs(this._latlngs, this._rings, pxBounds); - // project bounds as well to use later for Canvas hit detection/etc. var w = this._clickTolerance(), - p = new L.Point(w, -w); + p = new L.Point(w, w); if (this._bounds.isValid()) { - this._pxBounds = new L.Bounds( - this._map.latLngToLayerPoint(this._bounds.getSouthWest())._subtract(p), - this._map.latLngToLayerPoint(this._bounds.getNorthEast())._add(p)); + pxBounds.min._subtract(p); + pxBounds.max._add(p); + this._pxBounds = pxBounds; } }, // recursively turns latlngs into a set of rings with projected coordinates - _projectLatlngs: function (latlngs, result) { - + _projectLatlngs: function (latlngs, result, projectedBounds) { var flat = latlngs[0] instanceof L.LatLng, len = latlngs.length, i, ring; @@ -154,11 +153,12 @@ L.Polyline = L.Path.extend({ ring = []; for (i = 0; i < len; i++) { ring[i] = this._map.latLngToLayerPoint(latlngs[i]); + projectedBounds.extend(ring[i]); } result.push(ring); } else { for (i = 0; i < len; i++) { - this._projectLatlngs(latlngs[i], result); + this._projectLatlngs(latlngs[i], result, projectedBounds); } } },