Add setCoordinates for linestring and dispatch change event
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
goog.provide('ol.geom.LineString');
|
goog.provide('ol.geom.LineString');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.events.EventType');
|
||||||
goog.require('ol.CoordinateArray');
|
goog.require('ol.CoordinateArray');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom');
|
goog.require('ol.geom');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.Geometry');
|
||||||
|
goog.require('ol.geom.GeometryEvent');
|
||||||
goog.require('ol.geom.GeometryType');
|
goog.require('ol.geom.GeometryType');
|
||||||
|
|
||||||
|
|
||||||
@@ -108,6 +110,19 @@ ol.geom.LineString.prototype.distanceFromCoordinate = function(coordinate) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the linestring coordinates.
|
||||||
|
* @param {ol.CoordinateArray} coordinates Coordinates array.
|
||||||
|
*/
|
||||||
|
ol.geom.LineString.prototype.setCoordinates = function(coordinates) {
|
||||||
|
var oldBounds = this.bounds_;
|
||||||
|
this.bounds_ = null;
|
||||||
|
this.coordinates_ = coordinates;
|
||||||
|
this.dispatchEvent(new ol.geom.GeometryEvent(goog.events.EventType.CHANGE,
|
||||||
|
this, oldBounds));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
@@ -118,5 +133,5 @@ ol.geom.LineString.prototype.transform = function(transform) {
|
|||||||
coord = coordinates[i];
|
coord = coordinates[i];
|
||||||
transform(coord, coord, coord.length);
|
transform(coord, coord, coord.length);
|
||||||
}
|
}
|
||||||
this.bounds_ = null;
|
this.setCoordinates(coordinates); // for change event
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,6 +34,35 @@ describe('ol.geom.LineString', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#setCoordinates()', function() {
|
||||||
|
|
||||||
|
it('updates the coordinates', function() {
|
||||||
|
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||||
|
line.setCoordinates([[30, 40], [50, 60]]);
|
||||||
|
expect(line.getCoordinates()).to.eql([[30, 40], [50, 60]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalidates bounds', function() {
|
||||||
|
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||||
|
line.setCoordinates([[30, 40], [50, 60]]);
|
||||||
|
expect(line.getBounds()).to.eql([30, 40, 50, 60]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('triggers a change event', function(done) {
|
||||||
|
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||||
|
expect(line.getBounds()).to.eql([10, 20, 30, 40]);
|
||||||
|
goog.events.listen(line, 'change', function(evt) {
|
||||||
|
expect(evt.target).to.equal(line);
|
||||||
|
expect(evt.oldExtent).to.eql([10, 20, 30, 40]);
|
||||||
|
expect(evt.target.getBounds()).to.eql([30, 40, 50, 60]);
|
||||||
|
expect(evt.target.getCoordinates()).to.eql([[30, 40], [50, 60]]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
line.setCoordinates([[30, 40], [50, 60]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#transform()', function() {
|
describe('#transform()', function() {
|
||||||
|
|
||||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||||
@@ -67,6 +96,7 @@ describe('ol.geom.LineString', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goog.require('goog.events');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
|
|||||||
Reference in New Issue
Block a user