Make ol.FeatureOverlay use replay group

This commit is contained in:
Éric Lemoine
2014-06-14 14:22:10 +02:00
parent 49a1215f75
commit 4f23ef66d0
2 changed files with 11 additions and 105 deletions

View File

@@ -10,7 +10,7 @@ goog.require('ol.CollectionEventType');
goog.require('ol.Feature');
goog.require('ol.feature');
goog.require('ol.render.EventType');
goog.require('ol.style.ImageState');
goog.require('ol.renderer.vector');
@@ -101,37 +101,6 @@ ol.FeatureOverlay.prototype.addFeature = function(feature) {
};
/**
* @param {ol.render.IVectorContext|undefined} vectorContext Vector context.
* @param {ol.Feature} feature Feature.
* @param {ol.style.Style} style Style.
* @private
*/
ol.FeatureOverlay.prototype.drawFeature_ = function(vectorContext, feature,
style) {
var imageStyle = style.getImage();
if (!goog.isNull(imageStyle)) {
var imageState = imageStyle.getImageState();
if (imageState == ol.style.ImageState.LOADED ||
imageState == ol.style.ImageState.ERROR) {
imageStyle.unlistenImageChange(this.handleImageChange_, this);
if (imageState == ol.style.ImageState.LOADED) {
vectorContext.drawFeature(feature, style);
}
} else {
if (imageState == ol.style.ImageState.IDLE) {
imageStyle.load();
}
imageState = imageStyle.getImageState();
goog.asserts.assert(imageState == ol.style.ImageState.LOADING);
imageStyle.listenImageChange(this.handleImageChange_, this);
}
} else {
vectorContext.drawFeature(feature, style);
}
};
/**
* @return {ol.Collection} Features collection.
* @todo api
@@ -199,8 +168,14 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) {
if (!goog.isDef(styleFunction)) {
styleFunction = ol.feature.defaultStyleFunction;
}
var resolution = event.frameState.view2DState.resolution;
var vectorContext = event.vectorContext;
var replayGroup = /** @type {ol.render.IReplayGroup} */
(event.replayGroup);
goog.asserts.assert(goog.isDef(replayGroup));
var frameState = event.frameState;
var pixelRatio = frameState.pixelRatio;
var resolution = frameState.view2DState.resolution;
var squaredTolerance =
resolution * resolution / (4 * pixelRatio * pixelRatio);
var i, ii, styles;
this.features_.forEach(function(feature) {
styles = styleFunction(feature, resolution);
@@ -209,7 +184,8 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) {
}
ii = styles.length;
for (i = 0; i < ii; ++i) {
this.drawFeature_(vectorContext, feature, styles[i]);
ol.renderer.vector.renderFeature(replayGroup, feature, styles[i],
squaredTolerance, feature, this.handleImageChange_, this);
}
}, this);
};