From 8003c4ba5aa7f6212c650cd6a0e8c38c0d01410b Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 15 Dec 2013 15:30:56 +0100 Subject: [PATCH 1/5] Remove ol.format.Format#readStyleFunction --- src/ol/format/format.exports | 1 - src/ol/format/format.js | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/src/ol/format/format.exports b/src/ol/format/format.exports index 0d0fdfb024..b739fdbdb7 100644 --- a/src/ol/format/format.exports +++ b/src/ol/format/format.exports @@ -1,2 +1 @@ @exportProperty ol.format.Format.prototype.readProjection -@exportProperty ol.format.Format.prototype.readStyleFunction diff --git a/src/ol/format/format.js b/src/ol/format/format.js index 4e3c0a055a..b426dbaebc 100644 --- a/src/ol/format/format.js +++ b/src/ol/format/format.js @@ -67,16 +67,6 @@ ol.format.Format.prototype.readGeometry = goog.abstractMethod; ol.format.Format.prototype.readProjection = goog.abstractMethod; -/** - * @param {Document|Node|Object|string} source Source. - * @return {function(ol.Feature, number): Array.} Style - * function. - */ -ol.format.Format.prototype.readStyleFunction = function(source) { - return goog.functions.NULL; -}; - - /** * @param {ol.Feature} feature Feature. * @return {Node|Object|string} Result. From 5729ebbd79b918496ef34f656718297a20780b25 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 15 Dec 2013 23:04:42 +0100 Subject: [PATCH 2/5] Add ol.geom.GeometryCollection#isEmpty --- src/ol/geom/geometrycollection.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ol/geom/geometrycollection.js b/src/ol/geom/geometrycollection.js index 7765699b0c..3357e84184 100644 --- a/src/ol/geom/geometrycollection.js +++ b/src/ol/geom/geometrycollection.js @@ -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.} geometries Geometries. */ From 47e2dd53ce6f84e5a53060c130d227b3ab281afb Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 15 Dec 2013 22:33:14 +0100 Subject: [PATCH 3/5] Add ol.structs.RBush#getExtent --- src/ol/structs/rbush.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index 8f45d27cb6..7e8ff0ff50 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -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. * @private From 975e0c0576ec4cdc04204819f2726a40b1d6c76a Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 15 Dec 2013 23:11:07 +0100 Subject: [PATCH 4/5] Add ol.source.Vector#getExtent --- src/ol/source/vectorsource.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ol/source/vectorsource.js b/src/ol/source/vectorsource.js index 776dd2f7b2..d002278ebb 100644 --- a/src/ol/source/vectorsource.js +++ b/src/ol/source/vectorsource.js @@ -212,6 +212,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. * @private From 451051047767be3ff4542466fbe754845eeffdc9 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 15 Dec 2013 23:10:38 +0100 Subject: [PATCH 5/5] Handle features with null geometries in ol.source.Vector --- src/ol/source/vectorsource.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/ol/source/vectorsource.js b/src/ol/source/vectorsource.js index d002278ebb..11079daf57 100644 --- a/src/ol/source/vectorsource.js +++ b/src/ol/source/vectorsource.js @@ -6,10 +6,12 @@ goog.provide('ol.source.Vector'); goog.provide('ol.source.VectorEvent'); goog.provide('ol.source.VectorEventType'); +goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.events'); goog.require('goog.events.Event'); goog.require('goog.events.EventType'); +goog.require('goog.object'); goog.require('ol.source.Source'); goog.require('ol.structs.RBush'); @@ -48,6 +50,12 @@ ol.source.Vector = function(opt_options) { */ this.rBush_ = new ol.structs.RBush(); + /** + * @private + * @type {Object.} + */ + this.nullGeometryFeatures_ = {}; + /** * @private * @type {Object.} @@ -74,8 +82,13 @@ ol.source.Vector.prototype.addFeature = function(feature) { goog.asserts.assert(!(featureKey in this.featureChangeKeys_)); this.featureChangeKeys_[featureKey] = goog.events.listen(feature, goog.events.EventType.CHANGE, this.handleFeatureChange_, false, this); - var extent = feature.getGeometry().getExtent(); - this.rBush_.insert(extent, feature); + var geometry = feature.getGeometry(); + if (goog.isNull(geometry)) { + this.nullGeometryFeatures_[goog.getUid(feature).toString()] = feature; + } else { + var extent = geometry.getExtent(); + this.rBush_.insert(extent, feature); + } this.dispatchEvent( new ol.source.VectorEvent(ol.source.VectorEventType.ADDFEATURE, feature)); this.dispatchChangeEvent(); @@ -140,7 +153,12 @@ ol.source.Vector.prototype.forEachFeatureInExtent = * @return {Array.} Features. */ 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; }; @@ -235,7 +253,8 @@ ol.source.Vector.prototype.handleFeatureChange_ = function(event) { * @return {boolean} Is empty. */ ol.source.Vector.prototype.isEmpty = function() { - return this.rBush_.isEmpty(); + return this.rBush_.isEmpty() && + goog.object.isEmpty(this.nullGeometryFeatures_); }; @@ -243,7 +262,12 @@ ol.source.Vector.prototype.isEmpty = function() { * @param {ol.Feature} feature 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.dispatchChangeEvent(); };