Merge pull request #1390 from twpayne/vector-api-misc-fixes
[vector-api] Miscellaneous vector fixes
This commit is contained in:
@@ -1,2 +1 @@
|
|||||||
@exportProperty ol.format.Format.prototype.readProjection
|
@exportProperty ol.format.Format.prototype.readProjection
|
||||||
@exportProperty ol.format.Format.prototype.readStyleFunction
|
|
||||||
|
|||||||
@@ -67,16 +67,6 @@ ol.format.Format.prototype.readGeometry = goog.abstractMethod;
|
|||||||
ol.format.Format.prototype.readProjection = goog.abstractMethod;
|
ol.format.Format.prototype.readProjection = goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Document|Node|Object|string} source Source.
|
|
||||||
* @return {function(ol.Feature, number): Array.<ol.style.Style>} Style
|
|
||||||
* function.
|
|
||||||
*/
|
|
||||||
ol.format.Format.prototype.readStyleFunction = function(source) {
|
|
||||||
return goog.functions.NULL;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {Node|Object|string} Result.
|
* @return {Node|Object|string} Result.
|
||||||
|
|||||||
@@ -173,6 +173,14 @@ ol.geom.GeometryCollection.prototype.getType = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean} Is empty.
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.isEmpty = function() {
|
||||||
|
return goog.array.isEmpty(this.geometries_);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array.<ol.geom.Geometry>} geometries Geometries.
|
* @param {Array.<ol.geom.Geometry>} geometries Geometries.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ goog.provide('ol.source.Vector');
|
|||||||
goog.provide('ol.source.VectorEvent');
|
goog.provide('ol.source.VectorEvent');
|
||||||
goog.provide('ol.source.VectorEventType');
|
goog.provide('ol.source.VectorEventType');
|
||||||
|
|
||||||
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.events');
|
goog.require('goog.events');
|
||||||
goog.require('goog.events.Event');
|
goog.require('goog.events.Event');
|
||||||
goog.require('goog.events.EventType');
|
goog.require('goog.events.EventType');
|
||||||
|
goog.require('goog.object');
|
||||||
goog.require('ol.source.Source');
|
goog.require('ol.source.Source');
|
||||||
goog.require('ol.structs.RBush');
|
goog.require('ol.structs.RBush');
|
||||||
|
|
||||||
@@ -48,6 +50,12 @@ ol.source.Vector = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
this.rBush_ = new ol.structs.RBush();
|
this.rBush_ = new ol.structs.RBush();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Object.<string, ol.Feature>}
|
||||||
|
*/
|
||||||
|
this.nullGeometryFeatures_ = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Object.<string, goog.events.Key>}
|
* @type {Object.<string, goog.events.Key>}
|
||||||
@@ -74,8 +82,13 @@ ol.source.Vector.prototype.addFeature = function(feature) {
|
|||||||
goog.asserts.assert(!(featureKey in this.featureChangeKeys_));
|
goog.asserts.assert(!(featureKey in this.featureChangeKeys_));
|
||||||
this.featureChangeKeys_[featureKey] = goog.events.listen(feature,
|
this.featureChangeKeys_[featureKey] = goog.events.listen(feature,
|
||||||
goog.events.EventType.CHANGE, this.handleFeatureChange_, false, this);
|
goog.events.EventType.CHANGE, this.handleFeatureChange_, false, this);
|
||||||
var extent = feature.getGeometry().getExtent();
|
var geometry = feature.getGeometry();
|
||||||
this.rBush_.insert(extent, feature);
|
if (goog.isNull(geometry)) {
|
||||||
|
this.nullGeometryFeatures_[goog.getUid(feature).toString()] = feature;
|
||||||
|
} else {
|
||||||
|
var extent = geometry.getExtent();
|
||||||
|
this.rBush_.insert(extent, feature);
|
||||||
|
}
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new ol.source.VectorEvent(ol.source.VectorEventType.ADDFEATURE, feature));
|
new ol.source.VectorEvent(ol.source.VectorEventType.ADDFEATURE, feature));
|
||||||
this.dispatchChangeEvent();
|
this.dispatchChangeEvent();
|
||||||
@@ -140,7 +153,12 @@ ol.source.Vector.prototype.forEachFeatureInExtent =
|
|||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
*/
|
*/
|
||||||
ol.source.Vector.prototype.getAllFeatures = function() {
|
ol.source.Vector.prototype.getAllFeatures = function() {
|
||||||
return this.rBush_.getAll();
|
var features = this.rBush_.getAll();
|
||||||
|
if (!goog.object.isEmpty(this.nullGeometryFeatures_)) {
|
||||||
|
goog.array.extend(
|
||||||
|
features, goog.object.getValues(this.nullGeometryFeatures_));
|
||||||
|
}
|
||||||
|
return features;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -212,6 +230,14 @@ ol.source.Vector.prototype.getClosestFeatureToCoordinate =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.Extent} Extent.
|
||||||
|
*/
|
||||||
|
ol.source.Vector.prototype.getExtent = function() {
|
||||||
|
return this.rBush_.getExtent();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {goog.events.Event} event Event.
|
* @param {goog.events.Event} event Event.
|
||||||
* @private
|
* @private
|
||||||
@@ -227,7 +253,8 @@ ol.source.Vector.prototype.handleFeatureChange_ = function(event) {
|
|||||||
* @return {boolean} Is empty.
|
* @return {boolean} Is empty.
|
||||||
*/
|
*/
|
||||||
ol.source.Vector.prototype.isEmpty = function() {
|
ol.source.Vector.prototype.isEmpty = function() {
|
||||||
return this.rBush_.isEmpty();
|
return this.rBush_.isEmpty() &&
|
||||||
|
goog.object.isEmpty(this.nullGeometryFeatures_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -235,7 +262,12 @@ ol.source.Vector.prototype.isEmpty = function() {
|
|||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
*/
|
*/
|
||||||
ol.source.Vector.prototype.removeFeature = function(feature) {
|
ol.source.Vector.prototype.removeFeature = function(feature) {
|
||||||
this.rBush_.remove(feature);
|
var featureKey = goog.getUid(feature).toString();
|
||||||
|
if (featureKey in this.nullGeometryFeatures_) {
|
||||||
|
delete this.nullGeometryFeatures_[featureKey];
|
||||||
|
} else {
|
||||||
|
this.rBush_.remove(feature);
|
||||||
|
}
|
||||||
this.removeFeatureInternal_(feature);
|
this.removeFeatureInternal_(feature);
|
||||||
this.dispatchChangeEvent();
|
this.dispatchChangeEvent();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -522,6 +522,15 @@ ol.structs.RBush.prototype.getAllInExtent = function(extent) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Extent=} opt_extent Extent.
|
||||||
|
* @return {ol.Extent} Extent.
|
||||||
|
*/
|
||||||
|
ol.structs.RBush.prototype.getExtent = function(opt_extent) {
|
||||||
|
return ol.extent.returnOrUpdate(this.root_.extent, opt_extent);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {T} value Value.
|
* @param {T} value Value.
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
Reference in New Issue
Block a user