Fire change events for multi-part geometries
This commit is contained in:
@@ -28,10 +28,11 @@ describe('ol.geom.GeometryCollection', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||
|
||||
expect(multi.components.length).to.be(3);
|
||||
expect(multi.components[0]).to.be.a(ol.geom.Point);
|
||||
expect(multi.components[1]).to.be.a(ol.geom.LineString);
|
||||
expect(multi.components[2]).to.be.a(ol.geom.Polygon);
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(3);
|
||||
expect(components[0]).to.be.a(ol.geom.Point);
|
||||
expect(components[1]).to.be.a(ol.geom.LineString);
|
||||
expect(components[2]).to.be.a(ol.geom.Polygon);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -45,10 +46,10 @@ describe('ol.geom.GeometryCollection', function() {
|
||||
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||
var clone = multi.clone();
|
||||
expect(clone).to.not.be(multi);
|
||||
var components = clone.components;
|
||||
expect(components[0]).to.eql([10, 20]);
|
||||
expect(components[1]).to.eql([[10, 20], [30, 40]]);
|
||||
expect(components[2]).to.eql([outer, inner1, inner2]);
|
||||
var components = clone.getComponents();
|
||||
expect(components[0].getCoordinates()).to.eql([10, 20]);
|
||||
expect(components[1].getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
expect(components[2].getCoordinates()).to.eql([outer, inner1, inner2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -21,9 +21,10 @@ describe('ol.geom.MultiLineString', function() {
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
|
||||
expect(multi.components.length).to.be(2);
|
||||
expect(multi.components[0]).to.be.a(ol.geom.LineString);
|
||||
expect(multi.components[1]).to.be.a(ol.geom.LineString);
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(2);
|
||||
expect(components[0]).to.be.a(ol.geom.LineString);
|
||||
expect(components[1]).to.be.a(ol.geom.LineString);
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -17,9 +17,10 @@ describe('ol.geom.MultiPoint', function() {
|
||||
it('is an array of points', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
|
||||
expect(multi.components.length).to.be(2);
|
||||
expect(multi.components[0]).to.be.a(ol.geom.Point);
|
||||
expect(multi.components[1]).to.be.a(ol.geom.Point);
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(2);
|
||||
expect(components[0]).to.be.a(ol.geom.Point);
|
||||
expect(components[1]).to.be.a(ol.geom.Point);
|
||||
|
||||
});
|
||||
|
||||
@@ -56,10 +57,11 @@ describe('ol.geom.MultiPoint', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
multi.transform(forward);
|
||||
|
||||
expect(multi.components[0].get(0)).to.roughlyEqual(1113195, 1);
|
||||
expect(multi.components[0].get(1)).to.roughlyEqual(2273031, 1);
|
||||
expect(multi.components[1].get(0)).to.roughlyEqual(3339584, 1);
|
||||
expect(multi.components[1].get(1)).to.roughlyEqual(4865942, 1);
|
||||
var components = multi.getComponents();
|
||||
expect(components[0].get(0)).to.roughlyEqual(1113195, 1);
|
||||
expect(components[0].get(1)).to.roughlyEqual(2273031, 1);
|
||||
expect(components[1].get(0)).to.roughlyEqual(3339584, 1);
|
||||
expect(components[1].get(1)).to.roughlyEqual(4865942, 1);
|
||||
});
|
||||
|
||||
it('inverse transforms a multi-point', function() {
|
||||
@@ -67,10 +69,11 @@ describe('ol.geom.MultiPoint', function() {
|
||||
[[1113195, 2273031], [3339584, 4865942]]);
|
||||
multi.transform(inverse);
|
||||
|
||||
expect(multi.components[0].get(0)).to.roughlyEqual(10, 0.001);
|
||||
expect(multi.components[0].get(1)).to.roughlyEqual(20, 0.001);
|
||||
expect(multi.components[1].get(0)).to.roughlyEqual(30, 0.001);
|
||||
expect(multi.components[1].get(1)).to.roughlyEqual(40, 0.001);
|
||||
var components = multi.getComponents();
|
||||
expect(components[0].get(0)).to.roughlyEqual(10, 0.001);
|
||||
expect(components[0].get(1)).to.roughlyEqual(20, 0.001);
|
||||
expect(components[1].get(0)).to.roughlyEqual(30, 0.001);
|
||||
expect(components[1].get(1)).to.roughlyEqual(40, 0.001);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -33,9 +33,10 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
|
||||
expect(multi.components.length).to.be(2);
|
||||
expect(multi.components[0]).to.be.a(ol.geom.Polygon);
|
||||
expect(multi.components[1]).to.be.a(ol.geom.Polygon);
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(2);
|
||||
expect(components[0]).to.be.a(ol.geom.Polygon);
|
||||
expect(components[1]).to.be.a(ol.geom.Polygon);
|
||||
|
||||
});
|
||||
|
||||
@@ -69,9 +70,53 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('change event', function() {
|
||||
|
||||
var outer, inner;
|
||||
beforeEach(function() {
|
||||
outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
|
||||
});
|
||||
|
||||
it('is fired when outer ring is modified', function(done) {
|
||||
var multi = new ol.geom.MultiPolygon([[outer, inner], [outer, inner]]);
|
||||
var components = multi.getComponents();
|
||||
var bounds = multi.getBounds();
|
||||
goog.events.listen(multi, 'change', function(evt) {
|
||||
expect(evt.target).to.be(multi);
|
||||
expect(evt.oldExtent).to.eql(bounds);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 11, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var outerOne = components[0].getRings()[0];
|
||||
var outerCoords = outerOne.getCoordinates();
|
||||
outerCoords[1][0] = 11;
|
||||
outerOne.setCoordinates(outerCoords);
|
||||
});
|
||||
|
||||
it('is fired when inner ring is modified', function(done) {
|
||||
var multi = new ol.geom.MultiPolygon([[outer, inner], [outer, inner]]);
|
||||
var components = multi.getComponents();
|
||||
var bounds = multi.getBounds();
|
||||
goog.events.listen(multi, 'change', function(evt) {
|
||||
expect(evt.target).to.be(multi);
|
||||
expect(evt.oldExtent).to.eql(bounds);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 10, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var innerTwo = components[1].getRings()[1];
|
||||
var innerCoords = innerTwo.getCoordinates();
|
||||
innerCoords[1][0] = 3;
|
||||
innerTwo.setCoordinates(innerCoords);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Polygon');
|
||||
|
||||
Reference in New Issue
Block a user