Merge pull request #1563 from twpayne/revision-in-observable
Move dispatchChangeEvent and getRevision into ol.Observable
This commit is contained in:
@@ -41,12 +41,6 @@ ol.Feature = function(opt_geometryOrValues) {
|
||||
*/
|
||||
this.geometryName_ = 'geometry';
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.revision_ = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {goog.events.Key}
|
||||
@@ -76,15 +70,6 @@ ol.Feature = function(opt_geometryOrValues) {
|
||||
goog.inherits(ol.Feature, ol.Object);
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.Feature.prototype.dispatchChangeEvent = function() {
|
||||
++this.revision_;
|
||||
this.dispatchEvent(goog.events.EventType.CHANGE);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.geom.Geometry|undefined} Geometry.
|
||||
*/
|
||||
@@ -114,14 +99,6 @@ ol.Feature.prototype.getGeometryName = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Revision.
|
||||
*/
|
||||
ol.Feature.prototype.getRevision = function() {
|
||||
return this.revision_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.feature.FeatureStyleFunction|undefined} Style function.
|
||||
*/
|
||||
|
||||
@@ -88,14 +88,14 @@ ol.geom.Circle.prototype.getCenter = function() {
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.Circle.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.revision) {
|
||||
if (this.extentRevision != this.getRevision()) {
|
||||
var flatCoordinates = this.flatCoordinates;
|
||||
var radius = flatCoordinates[this.stride] - flatCoordinates[0];
|
||||
this.extent = ol.extent.createOrUpdate(
|
||||
flatCoordinates[0] - radius, flatCoordinates[1] - radius,
|
||||
flatCoordinates[0] + radius, flatCoordinates[1] + radius,
|
||||
this.extent);
|
||||
this.extentRevision = this.revision;
|
||||
this.extentRevision = this.getRevision();
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
|
||||
@@ -2,7 +2,6 @@ goog.provide('ol.geom.Geometry');
|
||||
goog.provide('ol.geom.GeometryType');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.functions');
|
||||
goog.require('ol.Observable');
|
||||
|
||||
@@ -43,12 +42,6 @@ ol.geom.Geometry = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.revision = 0;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.Extent|undefined}
|
||||
@@ -129,15 +122,6 @@ ol.geom.Geometry.prototype.containsCoordinate = function(coordinate) {
|
||||
ol.geom.Geometry.prototype.containsXY = goog.functions.FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.geom.Geometry.prototype.dispatchChangeEvent = function() {
|
||||
++this.revision;
|
||||
this.dispatchEvent(goog.events.EventType.CHANGE);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent=} opt_extent Extent.
|
||||
* @return {ol.Extent} extent Extent.
|
||||
@@ -145,14 +129,6 @@ ol.geom.Geometry.prototype.dispatchChangeEvent = function() {
|
||||
ol.geom.Geometry.prototype.getExtent = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Revision.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getRevision = function() {
|
||||
return this.revision;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {ol.geom.Geometry} Simplified geometry.
|
||||
|
||||
@@ -91,7 +91,7 @@ ol.geom.GeometryCollection.prototype.containsXY = function(x, y) {
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.GeometryCollection.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.revision) {
|
||||
if (this.extentRevision != this.getRevision()) {
|
||||
var extent = ol.extent.createOrUpdateEmpty(this.extent);
|
||||
var geometries = this.geometries_;
|
||||
var i, ii;
|
||||
@@ -99,7 +99,7 @@ ol.geom.GeometryCollection.prototype.getExtent = function(opt_extent) {
|
||||
ol.extent.extend(extent, geometries[i].getExtent());
|
||||
}
|
||||
this.extent = extent;
|
||||
this.extentRevision = this.revision;
|
||||
this.extentRevision = this.getRevision();
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
@@ -127,10 +127,10 @@ ol.geom.GeometryCollection.prototype.getGeometriesArray = function() {
|
||||
*/
|
||||
ol.geom.GeometryCollection.prototype.getSimplifiedGeometry =
|
||||
function(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision != this.revision) {
|
||||
if (this.simplifiedGeometryRevision != this.getRevision()) {
|
||||
goog.object.clear(this.simplifiedGeometryCache);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.revision;
|
||||
this.simplifiedGeometryRevision = this.getRevision();
|
||||
}
|
||||
if (squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
|
||||
@@ -56,10 +56,10 @@ ol.geom.LinearRing.prototype.closestPointXY =
|
||||
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.revision) {
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.revision;
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return ol.geom.closest.getClosestPoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
|
||||
@@ -56,10 +56,10 @@ ol.geom.LineString.prototype.closestPointXY =
|
||||
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.revision) {
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.revision;
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return ol.geom.closest.getClosestPoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
|
||||
@@ -66,10 +66,10 @@ ol.geom.MultiLineString.prototype.closestPointXY =
|
||||
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.revision) {
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.revision;
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return ol.geom.closest.getsClosestPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
|
||||
@@ -76,10 +76,10 @@ ol.geom.MultiPolygon.prototype.closestPointXY =
|
||||
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.revision) {
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(ol.geom.closest.getssMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.revision;
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return ol.geom.closest.getssClosestPoint(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride,
|
||||
@@ -126,12 +126,12 @@ ol.geom.MultiPolygon.prototype.getEndss = function() {
|
||||
* @return {Array.<ol.Coordinate>} Interior points.
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.getInteriorPoints = function() {
|
||||
if (this.interiorPointsRevision_ != this.revision) {
|
||||
if (this.interiorPointsRevision_ != this.getRevision()) {
|
||||
var ys = ol.geom.flat.linearRingssMidYs(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
this.interiorPoints_ = ol.geom.flat.linearRingssGetInteriorPoints(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride, ys);
|
||||
this.interiorPointsRevision_ = this.revision;
|
||||
this.interiorPointsRevision_ = this.getRevision();
|
||||
}
|
||||
return this.interiorPoints_;
|
||||
};
|
||||
|
||||
@@ -65,10 +65,10 @@ ol.geom.Point.prototype.getCoordinates = function() {
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.Point.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.revision) {
|
||||
if (this.extentRevision != this.getRevision()) {
|
||||
this.extent = ol.extent.createOrUpdateFromCoordinate(
|
||||
this.flatCoordinates, this.extent);
|
||||
this.extentRevision = this.revision;
|
||||
this.extentRevision = this.getRevision();
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
|
||||
@@ -76,10 +76,10 @@ ol.geom.Polygon.prototype.closestPointXY =
|
||||
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.revision) {
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.revision;
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return ol.geom.closest.getsClosestPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
@@ -126,12 +126,12 @@ ol.geom.Polygon.prototype.getEnds = function() {
|
||||
* @return {ol.Coordinate} Interior point.
|
||||
*/
|
||||
ol.geom.Polygon.prototype.getInteriorPoint = function() {
|
||||
if (this.interiorPointRevision_ != this.revision) {
|
||||
if (this.interiorPointRevision_ != this.getRevision()) {
|
||||
var extent = this.getExtent();
|
||||
var y = (extent[1] + extent[3]) / 2;
|
||||
this.interiorPoint_ = ol.geom.flat.linearRingsGetInteriorPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, y);
|
||||
this.interiorPointRevision_ = this.revision;
|
||||
this.interiorPointRevision_ = this.getRevision();
|
||||
}
|
||||
return this.interiorPoint_;
|
||||
};
|
||||
|
||||
@@ -87,10 +87,10 @@ ol.geom.SimpleGeometry.prototype.containsXY = goog.functions.FALSE;
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.revision) {
|
||||
if (this.extentRevision != this.getRevision()) {
|
||||
this.extent = ol.extent.createOrUpdateFromFlatCoordinates(
|
||||
this.flatCoordinates, this.stride, this.extent);
|
||||
this.extentRevision = this.revision;
|
||||
this.extentRevision = this.getRevision();
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
@@ -118,10 +118,10 @@ ol.geom.SimpleGeometry.prototype.getLayout = function() {
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry =
|
||||
function(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision != this.revision) {
|
||||
if (this.simplifiedGeometryRevision != this.getRevision()) {
|
||||
goog.object.clear(this.simplifiedGeometryCache);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.revision;
|
||||
this.simplifiedGeometryRevision = this.getRevision();
|
||||
}
|
||||
// If squaredTolerance is negative or if we know that simplification will not
|
||||
// have any effect then just return this.
|
||||
|
||||
@@ -3,7 +3,6 @@ goog.provide('ol.layer.LayerProperty');
|
||||
goog.provide('ol.layer.LayerState');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.math');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.Object');
|
||||
@@ -75,14 +74,6 @@ ol.layer.Base = function(options) {
|
||||
goog.inherits(ol.layer.Base, ol.Object);
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.layer.Base.prototype.dispatchChangeEvent = function() {
|
||||
this.dispatchEvent(goog.events.EventType.CHANGE);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Brightness.
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@ goog.provide('ol.Observable');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventTarget');
|
||||
goog.require('goog.events.EventType');
|
||||
|
||||
|
||||
|
||||
@@ -15,12 +16,36 @@ goog.require('goog.events.EventTarget');
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.Observable = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.revision_ = 0;
|
||||
|
||||
};
|
||||
goog.inherits(ol.Observable, goog.events.EventTarget);
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.Observable.prototype.dispatchChangeEvent = function() {
|
||||
++this.revision_;
|
||||
this.dispatchEvent(goog.events.EventType.CHANGE);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Revision.
|
||||
*/
|
||||
ol.Observable.prototype.getRevision = function() {
|
||||
return this.revision_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Listen for a certain type of event.
|
||||
* @param {string|Array.<string>} type The event type or array of event types.
|
||||
|
||||
@@ -74,25 +74,10 @@ ol.source.Source = function(options) {
|
||||
this.state_ = goog.isDef(options.state) ?
|
||||
options.state : ol.source.State.READY;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.revision_ = 0;
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.Source, ol.Observable);
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.source.Source.prototype.dispatchChangeEvent = function() {
|
||||
++this.revision_;
|
||||
this.dispatchEvent(goog.events.EventType.CHANGE);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
@@ -144,14 +129,6 @@ ol.source.Source.prototype.getProjection = function() {
|
||||
ol.source.Source.prototype.getResolutions = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Revision.
|
||||
*/
|
||||
ol.source.Source.prototype.getRevision = function() {
|
||||
return this.revision_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.source.State} State.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user