From f9c0f12f238ec1543015cd567a308b515005cc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Thu, 24 Apr 2014 20:58:50 +0200 Subject: [PATCH] Remove skippeFeatures collection --- src/ol/interaction/selectinteraction.js | 12 ++--- src/ol/map.js | 66 ++++++++----------------- 2 files changed, 24 insertions(+), 54 deletions(-) diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index dde093bd85..10739142d6 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -184,16 +184,12 @@ ol.interaction.Select.prototype.setMap = function(map) { var currentMap = this.getMap(); var selectedFeatures = this.featureOverlay_.getFeatures(); if (!goog.isNull(currentMap)) { - selectedFeatures.forEach(function(feature) { - currentMap.getSkippedFeatures().remove(feature); - }); + selectedFeatures.forEach(currentMap.unskipFeature, currentMap); } goog.base(this, 'setMap', map); this.featureOverlay_.setMap(map); if (!goog.isNull(map)) { - selectedFeatures.forEach(function(feature) { - map.getSkippedFeatures().push(feature); - }); + selectedFeatures.forEach(map.skipFeature, map); } }; @@ -223,7 +219,7 @@ ol.interaction.Select.prototype.addFeature_ = function(evt) { var map = this.getMap(); goog.asserts.assertInstanceof(feature, ol.Feature); if (!goog.isNull(map)) { - map.getSkippedFeatures().push(feature); + map.skipFeature(feature); } }; @@ -237,6 +233,6 @@ ol.interaction.Select.prototype.removeFeature_ = function(evt) { var map = this.getMap(); goog.asserts.assertInstanceof(feature, ol.Feature); if (!goog.isNull(map)) { - map.getSkippedFeatures().remove(feature); + map.unskipFeature(feature); } }; diff --git a/src/ol/map.js b/src/ol/map.js index 63273cbf4f..de4181a09b 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -362,18 +362,6 @@ ol.Map = function(options) { goog.bind(this.getTilePriority, this), goog.bind(this.handleTileChange_, this)); - /** - * Features to skip at rendering time. - * @type {ol.Collection} - * @private - */ - this.skippedFeatures_ = new ol.Collection(); - goog.events.listen(this.skippedFeatures_, ol.CollectionEventType.ADD, - this.handleSkippedFeaturesAdd_, false, this); - goog.events.listen(this.skippedFeatures_, ol.CollectionEventType.REMOVE, - this.handleSkippedFeaturesRemove_, false, this); - this.registerDisposable(this.skippedFeatures_); - /** * Uids of features to skip at rendering time. * @type {Object.} @@ -821,16 +809,6 @@ ol.Map.prototype.getTilePriority = }; -/** - * Get the collection of features to skip. - * @return {ol.Collection} Features collection. - * @todo stability experimental - */ -ol.Map.prototype.getSkippedFeatures = function() { - return this.skippedFeatures_; -}; - - /** * @param {goog.events.BrowserEvent} browserEvent Browser event. * @param {string=} opt_type Type. @@ -930,30 +908,6 @@ ol.Map.prototype.handleSizeChanged_ = function() { }; -/** - * @private - * @param {ol.CollectionEvent} event Collection "add" event. - */ -ol.Map.prototype.handleSkippedFeaturesAdd_ = function(event) { - var feature = /** @type {ol.Feature} */ (event.element); - var featureUid = goog.getUid(feature).toString(); - this.skippedFeatureUids_[featureUid] = true; - this.render(); -}; - - -/** - * @private - * @param {ol.CollectionEvent} event Collection "remove" event. - */ -ol.Map.prototype.handleSkippedFeaturesRemove_ = function(event) { - var feature = /** @type {ol.Feature} */ (event.element); - var featureUid = goog.getUid(feature).toString(); - delete this.skippedFeatureUids_[featureUid]; - this.render(); -}; - - /** * @private */ @@ -1348,6 +1302,16 @@ goog.exportProperty( ol.Map.prototype.setView); +/** + * @param {ol.Feature} feature Feature. + */ +ol.Map.prototype.skipFeature = function(feature) { + var featureUid = goog.getUid(feature).toString(); + this.skippedFeatureUids_[featureUid] = true; + this.render(); +}; + + /** * Force a recalculation of the map viewport size. This should be called when * third-party code changes the size of the map viewport. @@ -1371,6 +1335,16 @@ ol.Map.prototype.updateSize = function() { }; +/** + * @param {ol.Feature} feature Feature. + */ +ol.Map.prototype.unskipFeature = function(feature) { + var featureUid = goog.getUid(feature).toString(); + delete this.skippedFeatureUids_[featureUid]; + this.render(); +}; + + /** * @typedef {{controls: ol.Collection, * deviceOptions: olx.DeviceOptions,