[Pkg-javascript-commits] [leaflet] 124/301: Add holes support to L.Polygon.setLatLngs(). Fixes #1518
Jonas Smedegaard
js at moszumanska.debian.org
Mon Jan 27 22:22:46 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository leaflet.
commit f5de36e2299bc56f427dbf8fa84adcf0cc43dc96
Author: Alexander Parshin <parshin.alexander at gmail.com>
Date: Sun Oct 13 20:17:12 2013 +0400
Add holes support to L.Polygon.setLatLngs(). Fixes #1518
---
spec/suites/layer/vector/PolygonSpec.js | 31 +++++++++++++++++++++++++++++++
src/layer/vector/Polygon.js | 15 +++++++++++++--
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/spec/suites/layer/vector/PolygonSpec.js b/spec/suites/layer/vector/PolygonSpec.js
index b0e25f8..b63e590 100644
--- a/spec/suites/layer/vector/PolygonSpec.js
+++ b/spec/suites/layer/vector/PolygonSpec.js
@@ -24,6 +24,21 @@ describe('Polygon', function() {
var polygon = new L.Polygon([]);
expect(polygon.getLatLngs()).to.eql([]);
});
+
+ it("can be initialized with holes", function () {
+ var originalLatLngs = [
+ [ //external rink
+ [0, 10], [10, 10], [10, 0]
+ ], [ //hole
+ [2, 3], [2, 4], [3, 4]
+ ]
+ ];
+
+ var polygon = new L.Polygon(originalLatLngs);
+
+ //getLatLngs() returns only external ring
+ expect(polygon.getLatLngs()).to.eql([L.latLng([0, 10]), L.latLng([10, 10]), L.latLng([10, 0])]);
+ })
});
describe("#setLatLngs", function () {
@@ -40,6 +55,22 @@ describe('Polygon', function() {
expect(sourceLatLngs).to.eql(originalLatLngs);
});
+
+ it("can be set external ring and holes", function() {
+ var latLngs = [
+ [ //external rink
+ [0, 10], [10, 10], [10, 0]
+ ], [ //hole
+ [2, 3], [2, 4], [3, 4]
+ ]
+ ];
+
+ var polygon = new L.Polygon([]);
+ polygon.setLatLngs(latLngs);
+
+ //getLatLngs() returns only external ring
+ expect(polygon.getLatLngs()).to.eql([L.latLng([0, 10]), L.latLng([10, 10]), L.latLng([10, 0])]);
+ })
});
describe("#spliceLatLngs", function () {
diff --git a/src/layer/vector/Polygon.js b/src/layer/vector/Polygon.js
index 528efd6..5fd5dd4 100644
--- a/src/layer/vector/Polygon.js
+++ b/src/layer/vector/Polygon.js
@@ -8,10 +8,12 @@ L.Polygon = L.Polyline.extend({
},
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);
@@ -52,6 +54,15 @@ L.Polygon = L.Polyline.extend({
}
},
+ 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,
newParts = [];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git
More information about the Pkg-javascript-commits
mailing list