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

View File

@@ -92,6 +92,10 @@ oli.FrameState.prototype.postRenderFunctions;
oli.FrameState.prototype.size;
/** @type {Array.<number>} */
oli.FrameState.prototype.skippedFeaturesIds;
/** @type {ol.TileQueue} */
oli.FrameState.prototype.tileQueue;

View File

@@ -7,7 +7,6 @@ goog.require('ol.Feature');
goog.require('ol.FeatureOverlay');
goog.require('ol.events.condition');
goog.require('ol.interaction.Interaction');
goog.require('ol.layer.Vector');
@@ -90,12 +89,6 @@ ol.interaction.Select = function(options) {
style: options.style
});
/**
* @private
* @type {Object}
*/
this.featuresLayerHash_ = {};
};
goog.inherits(ol.interaction.Select, ol.interaction.Interaction);
@@ -127,7 +120,7 @@ ol.interaction.Select.prototype.handleMapBrowserEvent =
* @param {ol.layer.Layer} layer Layer.
*/
function(feature, layer) {
this.addFeature_(feature, layer, add, remove, toggle);
this.addFeature_(feature, add, remove, toggle);
return feature;
}, this, this.layerFilter_);
if (!goog.isDef(feature) && !add && !remove) {
@@ -139,17 +132,15 @@ ol.interaction.Select.prototype.handleMapBrowserEvent =
/**
* @param {?ol.Feature|undefined} feature Feature.
* @param {ol.layer.Layer} layer Layer.
* @param {Boolean} add Add
* @param {Boolean} remove Remove
* @param {Boolean} toggle Toggle
* @private
* @todo stability experimental
*/
ol.interaction.Select.prototype.addFeature_ = function(feature, layer, add,
ol.interaction.Select.prototype.addFeature_ = function(feature, add,
remove, toggle) {
var features = this.featureOverlay_.getFeatures(),
hash = this.featuresLayerHash_,
uid, index = -1,
i, ii;
if ((!goog.isDef(feature) || goog.isNull(feature)) && !add) {
@@ -176,14 +167,10 @@ ol.interaction.Select.prototype.addFeature_ = function(feature, layer, add,
if (remove) {
return;
}
if (index >= 0) {
goog.array.insert(hash[uid], layer);
return;
if (index == -1) {
features.push(feature);
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
*/
ol.interaction.Select.prototype.removeFeature_ = function(feature) {
var features = this.featureOverlay_.getFeatures(),
hash = this.featuresLayerHash_,
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];
this.featureOverlay_.getFeatures().remove(feature);
this.getMap().getSkippedFeatures().remove(feature);
};

View File

@@ -1,11 +1,7 @@
goog.provide('ol.layer.Vector');
goog.require('goog.array');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.object');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.feature');
goog.require('ol.layer.Layer');
@@ -45,25 +41,6 @@ ol.layer.Vector = function(opt_options) {
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);
@@ -102,36 +79,3 @@ ol.layer.Vector.prototype.setStyle = function(style) {
this.styleFunction_ = ol.feature.createStyleFunction(style);
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_;
};

View File

@@ -359,6 +359,13 @@ ol.Map = function(options) {
goog.bind(this.getTilePriority, this),
goog.bind(this.handleTileChange_, this));
/**
* Collection of Features to skip drawing.
* @type {ol.Collection}
* @private
*/
this.skippedFeatures_ = new ol.Collection();
goog.events.listen(
this, ol.Object.getChangeEventType(ol.MapProperty.LAYERGROUP),
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 {string=} opt_type Type.
@@ -1181,6 +1198,8 @@ ol.Map.prototype.renderFrame_ = function(time) {
pixelToCoordinateMatrix: this.pixelToCoordinateMatrix_,
postRenderFunctions: [],
size: size,
skippedFeaturesIds: goog.array.map(
this.skippedFeatures_.getArray(), goog.getUid),
tileQueue: this.tileQueue_,
time: time,
usedTiles: {},

View File

@@ -95,13 +95,10 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame =
} else {
replayContext = context;
}
goog.asserts.assertInstanceof(layer, ol.layer.Vector);
var skippedFeaturesIds = layer.getSkippedFeaturesIds();
goog.asserts.assert(goog.isArray(skippedFeaturesIds));
replayContext.globalAlpha = layerState.opacity;
replayGroup.replay(
replayContext, frameState.extent, frameState.pixelRatio, transform,
frameState.view2DState.rotation, skippedFeaturesIds);
frameState.view2DState.rotation, frameState.skippedFeaturesIds);
if (replayContext != context) {
this.dispatchRenderEvent(replayContext, frameState, transform);
@@ -126,11 +123,8 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
var resolution = frameState.view2DState.resolution;
var rotation = frameState.view2DState.rotation;
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,
rotation, coordinate, skippedFeaturesIds,
rotation, coordinate, frameState.skippedFeaturesIds,
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {Object} data Data.