Add setCoordinates for point and dispatch change event
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
goog.provide('ol.geom.Point');
|
goog.provide('ol.geom.Point');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.events.EventType');
|
||||||
goog.require('ol.Coordinate');
|
goog.require('ol.Coordinate');
|
||||||
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');
|
||||||
|
|
||||||
|
|
||||||
@@ -71,11 +73,24 @@ ol.geom.Point.prototype.getType = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the point coordinates.
|
||||||
|
* @param {ol.Coordinate} coordinates Coordinates array.
|
||||||
|
*/
|
||||||
|
ol.geom.Point.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
|
||||||
*/
|
*/
|
||||||
ol.geom.Point.prototype.transform = function(transform) {
|
ol.geom.Point.prototype.transform = function(transform) {
|
||||||
var coordinates = this.getCoordinates();
|
var coordinates = this.getCoordinates();
|
||||||
transform(coordinates, coordinates, coordinates.length);
|
transform(coordinates, coordinates, coordinates.length);
|
||||||
this.bounds_ = null;
|
this.setCoordinates(coordinates); // for change event
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,6 +34,35 @@ describe('ol.geom.Point', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#setCoordinates()', function() {
|
||||||
|
|
||||||
|
it('updates the coordinates', function() {
|
||||||
|
var point = new ol.geom.Point([10, 20]);
|
||||||
|
point.setCoordinates([30, 40]);
|
||||||
|
expect(point.getCoordinates()).to.eql([30, 40]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalidates bounds', function() {
|
||||||
|
var point = new ol.geom.Point([10, 20]);
|
||||||
|
point.setCoordinates([30, 40]);
|
||||||
|
expect(point.getBounds()).to.eql([30, 40, 30, 40]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('triggers a change event', function(done) {
|
||||||
|
var point = new ol.geom.Point([10, 20]);
|
||||||
|
expect(point.getBounds()).to.eql([10, 20, 10, 20]);
|
||||||
|
goog.events.listen(point, 'change', function(evt) {
|
||||||
|
expect(evt.target).to.equal(point);
|
||||||
|
expect(evt.oldExtent).to.eql([10, 20, 10, 20]);
|
||||||
|
expect(evt.target.getBounds()).to.eql([30, 40, 30, 40]);
|
||||||
|
expect(evt.target.getCoordinates()).to.eql([30, 40]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
point.setCoordinates([30, 40]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#transform()', function() {
|
describe('#transform()', function() {
|
||||||
|
|
||||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||||
@@ -57,6 +86,7 @@ describe('ol.geom.Point', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goog.require('goog.events');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.Geometry');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
|
|||||||
Reference in New Issue
Block a user