Map stores skippedFeatures instead of layers

This commit is contained in:
Antoine Abt
2014-03-19 14:53:41 +01:00
parent e91db0f9af
commit 0d87516135
5 changed files with 32 additions and 95 deletions
+4
View File
@@ -92,6 +92,10 @@ oli.FrameState.prototype.postRenderFunctions;
oli.FrameState.prototype.size; oli.FrameState.prototype.size;
/** @type {Array.<number>} */
oli.FrameState.prototype.skippedFeaturesIds;
/** @type {ol.TileQueue} */ /** @type {ol.TileQueue} */
oli.FrameState.prototype.tileQueue; oli.FrameState.prototype.tileQueue;
+7 -31
View File
@@ -7,7 +7,6 @@ goog.require('ol.Feature');
goog.require('ol.FeatureOverlay'); goog.require('ol.FeatureOverlay');
goog.require('ol.events.condition'); goog.require('ol.events.condition');
goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Interaction');
goog.require('ol.layer.Vector');
@@ -90,12 +89,6 @@ ol.interaction.Select = function(options) {
style: options.style style: options.style
}); });
/**
* @private
* @type {Object}
*/
this.featuresLayerHash_ = {};
}; };
goog.inherits(ol.interaction.Select, ol.interaction.Interaction); goog.inherits(ol.interaction.Select, ol.interaction.Interaction);
@@ -127,7 +120,7 @@ ol.interaction.Select.prototype.handleMapBrowserEvent =
* @param {ol.layer.Layer} layer Layer. * @param {ol.layer.Layer} layer Layer.
*/ */
function(feature, layer) { function(feature, layer) {
this.addFeature_(feature, layer, add, remove, toggle); this.addFeature_(feature, add, remove, toggle);
return feature; return feature;
}, this, this.layerFilter_); }, this, this.layerFilter_);
if (!goog.isDef(feature) && !add && !remove) { if (!goog.isDef(feature) && !add && !remove) {
@@ -139,17 +132,15 @@ ol.interaction.Select.prototype.handleMapBrowserEvent =
/** /**
* @param {?ol.Feature|undefined} feature Feature. * @param {?ol.Feature|undefined} feature Feature.
* @param {ol.layer.Layer} layer Layer.
* @param {Boolean} add Add * @param {Boolean} add Add
* @param {Boolean} remove Remove * @param {Boolean} remove Remove
* @param {Boolean} toggle Toggle * @param {Boolean} toggle Toggle
* @private * @private
* @todo stability experimental * @todo stability experimental
*/ */
ol.interaction.Select.prototype.addFeature_ = function(feature, layer, add, ol.interaction.Select.prototype.addFeature_ = function(feature, add,
remove, toggle) { remove, toggle) {
var features = this.featureOverlay_.getFeatures(), var features = this.featureOverlay_.getFeatures(),
hash = this.featuresLayerHash_,
uid, index = -1, uid, index = -1,
i, ii; i, ii;
if ((!goog.isDef(feature) || goog.isNull(feature)) && !add) { if ((!goog.isDef(feature) || goog.isNull(feature)) && !add) {
@@ -176,14 +167,10 @@ ol.interaction.Select.prototype.addFeature_ = function(feature, layer, add,
if (remove) { if (remove) {
return; return;
} }
if (index >= 0) { if (index == -1) {
goog.array.insert(hash[uid], layer); features.push(feature);
return; this.getMap().getSkippedFeatures().push(feature);
} }
features.push(feature);
goog.asserts.assertInstanceof(layer, ol.layer.Vector);
layer.getSkippedFeatures().push(feature);
hash[uid] = [layer];
}; };
@@ -193,19 +180,8 @@ ol.interaction.Select.prototype.addFeature_ = function(feature, layer, add,
* @todo stability experimental * @todo stability experimental
*/ */
ol.interaction.Select.prototype.removeFeature_ = function(feature) { ol.interaction.Select.prototype.removeFeature_ = function(feature) {
var features = this.featureOverlay_.getFeatures(), this.featureOverlay_.getFeatures().remove(feature);
hash = this.featuresLayerHash_, this.getMap().getSkippedFeatures().remove(feature);
uid = goog.getUid(feature),
i, ii, layer;
features.remove(feature);
for (i = 0, ii = hash[uid].length; i < ii; i++) {
layer = hash[uid][i];
if (!goog.isNull(layer)) {
goog.asserts.assertInstanceof(layer, ol.layer.Vector);
layer.getSkippedFeatures().remove(feature);
}
}
delete hash[uid];
}; };
-56
View File
@@ -1,11 +1,7 @@
goog.provide('ol.layer.Vector'); goog.provide('ol.layer.Vector');
goog.require('goog.array'); goog.require('goog.array');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.object'); goog.require('goog.object');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.feature'); goog.require('ol.feature');
goog.require('ol.layer.Layer'); goog.require('ol.layer.Layer');
@@ -45,25 +41,6 @@ ol.layer.Vector = function(opt_options) {
this.setStyle(options.style); this.setStyle(options.style);
} }
/**
* Collection of Features to skip drawing.
* @type {ol.Collection}
* @private
*/
this.skippedFeatures_ = new ol.Collection();
/**
* Array of Feature ids to skip drawing.
* @type {Array.<number>}
* @private
*/
this.skippedFeaturesIds_ = [];
goog.events.listen(this.skippedFeatures_, [
ol.CollectionEventType.REMOVE,
ol.CollectionEventType.ADD
], this.updateSkippedFeaturesArray_, false, this);
}; };
goog.inherits(ol.layer.Vector, ol.layer.Layer); goog.inherits(ol.layer.Vector, ol.layer.Layer);
@@ -102,36 +79,3 @@ ol.layer.Vector.prototype.setStyle = function(style) {
this.styleFunction_ = ol.feature.createStyleFunction(style); this.styleFunction_ = ol.feature.createStyleFunction(style);
this.dispatchChangeEvent(); this.dispatchChangeEvent();
}; };
/**
* Update Features Ids internal array.
* @private
*/
ol.layer.Vector.prototype.updateSkippedFeaturesArray_ = function() {
this.skippedFeaturesIds_ = goog.array.map(
this.skippedFeatures_.getArray(), goog.getUid);
// Dont use dispatchChangeEvent here because we dont want the batch
// to be re-created, just replayed.
this.dispatchEvent(goog.events.EventType.CHANGE);
};
/**
* Get the collection of features to be skipped.
* @return {ol.Collection} Features collection.
* @todo stability experimental
*/
ol.layer.Vector.prototype.getSkippedFeatures = function() {
return this.skippedFeatures_;
};
/**
* Get the features ids to be skipped.
* @return {Array.<number>} Array of features Ids
* @todo stability experimental
*/
ol.layer.Vector.prototype.getSkippedFeaturesIds = function() {
return this.skippedFeaturesIds_;
};
+19
View File
@@ -359,6 +359,13 @@ ol.Map = function(options) {
goog.bind(this.getTilePriority, this), goog.bind(this.getTilePriority, this),
goog.bind(this.handleTileChange_, this)); goog.bind(this.handleTileChange_, this));
/**
* Collection of Features to skip drawing.
* @type {ol.Collection}
* @private
*/
this.skippedFeatures_ = new ol.Collection();
goog.events.listen( goog.events.listen(
this, ol.Object.getChangeEventType(ol.MapProperty.LAYERGROUP), this, ol.Object.getChangeEventType(ol.MapProperty.LAYERGROUP),
this.handleLayerGroupChanged_, false, this); this.handleLayerGroupChanged_, false, this);
@@ -797,6 +804,16 @@ ol.Map.prototype.getTilePriority =
}; };
/**
* Get the collection of features to be skipped.
* @return {ol.Collection} Features collection.
* @todo stability experimental
*/
ol.Map.prototype.getSkippedFeatures = function() {
return this.skippedFeatures_;
};
/** /**
* @param {goog.events.BrowserEvent} browserEvent Browser event. * @param {goog.events.BrowserEvent} browserEvent Browser event.
* @param {string=} opt_type Type. * @param {string=} opt_type Type.
@@ -1181,6 +1198,8 @@ ol.Map.prototype.renderFrame_ = function(time) {
pixelToCoordinateMatrix: this.pixelToCoordinateMatrix_, pixelToCoordinateMatrix: this.pixelToCoordinateMatrix_,
postRenderFunctions: [], postRenderFunctions: [],
size: size, size: size,
skippedFeaturesIds: goog.array.map(
this.skippedFeatures_.getArray(), goog.getUid),
tileQueue: this.tileQueue_, tileQueue: this.tileQueue_,
time: time, time: time,
usedTiles: {}, usedTiles: {},
@@ -95,13 +95,10 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame =
} else { } else {
replayContext = context; replayContext = context;
} }
goog.asserts.assertInstanceof(layer, ol.layer.Vector);
var skippedFeaturesIds = layer.getSkippedFeaturesIds();
goog.asserts.assert(goog.isArray(skippedFeaturesIds));
replayContext.globalAlpha = layerState.opacity; replayContext.globalAlpha = layerState.opacity;
replayGroup.replay( replayGroup.replay(
replayContext, frameState.extent, frameState.pixelRatio, transform, replayContext, frameState.extent, frameState.pixelRatio, transform,
frameState.view2DState.rotation, skippedFeaturesIds); frameState.view2DState.rotation, frameState.skippedFeaturesIds);
if (replayContext != context) { if (replayContext != context) {
this.dispatchRenderEvent(replayContext, frameState, transform); this.dispatchRenderEvent(replayContext, frameState, transform);
@@ -126,11 +123,8 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
var resolution = frameState.view2DState.resolution; var resolution = frameState.view2DState.resolution;
var rotation = frameState.view2DState.rotation; var rotation = frameState.view2DState.rotation;
var layer = this.getLayer(); var layer = this.getLayer();
goog.asserts.assertInstanceof(layer, ol.layer.Vector);
var skippedFeaturesIds = layer.getSkippedFeaturesIds();
goog.asserts.assert(goog.isArray(skippedFeaturesIds));
return this.replayGroup_.forEachGeometryAtPixel(extent, resolution, return this.replayGroup_.forEachGeometryAtPixel(extent, resolution,
rotation, coordinate, skippedFeaturesIds, rotation, coordinate, frameState.skippedFeaturesIds,
/** /**
* @param {ol.geom.Geometry} geometry Geometry. * @param {ol.geom.Geometry} geometry Geometry.
* @param {Object} data Data. * @param {Object} data Data.