Merge pull request #1467 from jfirebaugh/1459

Normalize polygon holes (fixes #1459)
This commit is contained in:
Vladimir Agafonkin 2013-02-27 08:33:53 -08:00
commit ff479f055e

View File

@ -8,11 +8,20 @@ L.Polygon = L.Polyline.extend({
}, },
initialize: function (latlngs, options) { initialize: function (latlngs, options) {
var i, len, hole;
L.Polyline.prototype.initialize.call(this, latlngs, options); L.Polyline.prototype.initialize.call(this, latlngs, options);
if (latlngs && L.Util.isArray(latlngs[0]) && (typeof latlngs[0][0] !== 'number')) { if (latlngs && L.Util.isArray(latlngs[0]) && (typeof latlngs[0][0] !== 'number')) {
this._latlngs = this._convertLatLngs(latlngs[0]); this._latlngs = this._convertLatLngs(latlngs[0]);
this._holes = latlngs.slice(1); this._holes = latlngs.slice(1);
for (i = 0, len = this._holes.length; i < len; i++) {
hole = this._holes[i] = this._convertLatLngs(this._holes[i]);
if (hole[0].equals(hole[hole.length - 1])) {
hole.pop();
}
}
} }
// filter out last point if its equal to the first one // filter out last point if its equal to the first one