lib/leaflet/src/layer/vector/Polygon.js in leaflet-js-0.6.beta4 vs lib/leaflet/src/layer/vector/Polygon.js in leaflet-js-0.7.0
- old
+ new
@@ -6,14 +6,16 @@
options: {
fill: true
},
initialize: function (latlngs, options) {
- var i, len, hole;
-
L.Polyline.prototype.initialize.call(this, latlngs, options);
+ this._initWithHoles(latlngs);
+ },
+ _initWithHoles: function (latlngs) {
+ var i, len, hole;
if (latlngs && L.Util.isArray(latlngs[0]) && (typeof latlngs[0][0] !== 'number')) {
this._latlngs = this._convertLatLngs(latlngs[0]);
this._holes = latlngs.slice(1);
for (i = 0, len = this._holes.length; i < len; i++) {
@@ -25,11 +27,11 @@
}
// filter out last point if its equal to the first one
latlngs = this._latlngs;
- if (latlngs[0].equals(latlngs[latlngs.length - 1])) {
+ if (latlngs.length >= 2 && latlngs[0].equals(latlngs[latlngs.length - 1])) {
latlngs.pop();
}
},
projectLatlngs: function () {
@@ -47,9 +49,18 @@
this._holePoints[i] = [];
for (j = 0, len2 = this._holes[i].length; j < len2; j++) {
this._holePoints[i][j] = this._map.latLngToLayerPoint(this._holes[i][j]);
}
+ }
+ },
+
+ setLatLngs: function (latlngs) {
+ if (latlngs && L.Util.isArray(latlngs[0]) && (typeof latlngs[0][0] !== 'number')) {
+ this._initWithHoles(latlngs);
+ return this.redraw();
+ } else {
+ return L.Polyline.prototype.setLatLngs.call(this, latlngs);
}
},
_clipPoints: function () {
var points = this._originalPoints,