Make unmanaged vector layers behave more like ol.FeatureOverlay

* Skipped features need to be hit-detected on unmanaged layers.
* updateWhileAnimating and updateWhileInteracting are recommended to
  achieve the same instant visual feedback that ol.FeatureOverlay had.
This commit is contained in:
Andreas Hocevar
2015-06-19 13:06:29 +02:00
parent f74e4c95ff
commit f645a9e1e4
7 changed files with 20 additions and 9 deletions

View File

@@ -20,11 +20,13 @@ you will have to change this to:
var collection = new ol.Collection();
var featureOverlay = new ol.layer.Vector({
map: map,
style: overlayStyle,
source: new ol.source.Vector({
features: collection,
useSpatialIndex: false // optional, might improve performance
});
}),
style: overlayStyle,
updateWhileAnimating: true, // optional, for instant visual feedback
updateWhileInteracting: true // optional, for instant visual feedback
});
featureOverlay.getSource().addFeature(feature);
featureOverlay.getSource().removeFeature(feature);

View File

@@ -122,7 +122,9 @@ ol.interaction.Modify = function(options) {
wrapX: goog.isDef(options.wrapX) ? options.wrapX : false
}),
style: goog.isDef(options.style) ? options.style :
ol.interaction.Modify.getDefaultStyleFunction()
ol.interaction.Modify.getDefaultStyleFunction(),
updateWhileAnimating: true,
updateWhileInteracting: true
});
/**

View File

@@ -178,7 +178,9 @@ ol.interaction.Select = function(opt_options) {
wrapX: options.wrapX
}),
style: goog.isDef(options.style) ? options.style :
ol.interaction.Select.getDefaultStyleFunction()
ol.interaction.Select.getDefaultStyleFunction(),
updateWhileAnimating: true,
updateWhileInteracting: true
});
var features = this.featureOverlay_.getSource().getFeaturesCollection();

View File

@@ -160,10 +160,11 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtCoordinate =
var resolution = frameState.viewState.resolution;
var rotation = frameState.viewState.rotation;
var layer = this.getLayer();
var layerState = frameState.layerStates[goog.getUid(layer)];
/** @type {Object.<string, boolean>} */
var features = {};
return this.replayGroup_.forEachFeatureAtCoordinate(coordinate,
resolution, rotation, frameState.skippedFeatureUids,
return this.replayGroup_.forEachFeatureAtCoordinate(coordinate, resolution,
rotation, layerState.managed ? frameState.skippedFeatureUids : {},
/**
* @param {ol.Feature} feature Feature.
* @return {?} Callback result.

View File

@@ -184,10 +184,11 @@ ol.renderer.dom.VectorLayer.prototype.forEachFeatureAtCoordinate =
var resolution = frameState.viewState.resolution;
var rotation = frameState.viewState.rotation;
var layer = this.getLayer();
var layerState = frameState.layerStates[goog.getUid(layer)];
/** @type {Object.<string, boolean>} */
var features = {};
return this.replayGroup_.forEachFeatureAtCoordinate(coordinate,
resolution, rotation, frameState.skippedFeatureUids,
return this.replayGroup_.forEachFeatureAtCoordinate(coordinate, resolution,
rotation, layerState.managed ? frameState.skippedFeatureUids : {},
/**
* @param {ol.Feature} feature Feature.
* @return {?} Callback result.

View File

@@ -122,7 +122,8 @@ ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtCoordinate =
context, viewState.center, viewState.resolution, viewState.rotation,
frameState.size, frameState.pixelRatio,
layerState.opacity, layerState.brightness, layerState.contrast,
layerState.hue, layerState.saturation, frameState.skippedFeatureUids,
layerState.hue, layerState.saturation,
layerState.managed ? frameState.skippedFeatureUids : {},
/**
* @param {ol.Feature} feature Feature.
* @return {?} Callback result.

View File

@@ -76,12 +76,14 @@ describe('ol.renderer.canvas.VectorLayer', function() {
var spy = sinon.spy();
var coordinate = [0, 0];
var frameState = {
layerStates: {},
skippedFeatureUids: {},
viewState: {
resolution: 1,
rotation: 0
}
};
frameState.layerStates[goog.getUid(layer)] = {};
renderer.forEachFeatureAtCoordinate(
coordinate, frameState, spy, undefined);
expect(spy.callCount).to.be(1);