"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/layer/vector/Polygon.js" between
Leaflet-1.8.0.tar.gz and Leaflet-1.9.0.tar.gz

About: Leaflet is a JavaScript library for mobile-friendly interactive maps.

Polygon.js  (Leaflet-1.8.0):Polygon.js  (Leaflet-1.9.0)
skipping to change at line 64 skipping to change at line 64
export var Polygon = Polyline.extend({ export var Polygon = Polyline.extend({
options: { options: {
fill: true fill: true
}, },
isEmpty: function () { isEmpty: function () {
return !this._latlngs.length || !this._latlngs[0].length; return !this._latlngs.length || !this._latlngs[0].length;
}, },
// @method getCenter(): LatLng
// Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid))
of the Polygon.
getCenter: function () { getCenter: function () {
// throws error when not yet added to map as this center calculat ion requires projected coordinates // throws error when not yet added to map as this center calculat ion requires projected coordinates
if (!this._map) { if (!this._map) {
throw new Error('Must add layer to map before using getCe nter()'); throw new Error('Must add layer to map before using getCe nter()');
} }
return PolyUtil.polygonCenter(this._defaultShape(), this._map.opt
var i, j, p1, p2, f, area, x, y, center, ions.crs);
points = this._rings[0],
len = points.length;
if (!len) { return null; }
// polygon centroid algorithm; only uses the first ring if there
are multiple
area = x = y = 0;
for (i = 0, j = len - 1; i < len; j = i++) {
p1 = points[i];
p2 = points[j];
f = p1.y * p2.x - p2.y * p1.x;
x += (p1.x + p2.x) * f;
y += (p1.y + p2.y) * f;
area += f * 3;
}
if (area === 0) {
// Polygon is so small that all points are on same pixel.
center = points[0];
} else {
center = [x / area, y / area];
}
return this._map.layerPointToLatLng(center);
}, },
_convertLatLngs: function (latlngs) { _convertLatLngs: function (latlngs) {
var result = Polyline.prototype._convertLatLngs.call(this, latlng s), var result = Polyline.prototype._convertLatLngs.call(this, latlng s),
len = result.length; len = result.length;
// remove last point if it equals first one // remove last point if it equals first one
if (len >= 2 && result[0] instanceof LatLng && result[0].equals(r esult[len - 1])) { if (len >= 2 && result[0] instanceof LatLng && result[0].equals(r esult[len - 1])) {
result.pop(); result.pop();
} }
 End of changes. 2 change blocks. 
29 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)