Merge pull request #1778 from twpayne/render-sync-forces-render

Make renderSync always force a render
This commit is contained in:
Tom Payne
2014-02-28 13:53:33 +01:00
4 changed files with 49 additions and 126 deletions

View File

@@ -110,12 +110,10 @@ ol.interaction.DragRotateAndZoom.prototype.handleDragEnd =
var view2D = view.getView2D(); var view2D = view.getView2D();
var view2DState = view2D.getView2DState(); var view2DState = view2D.getView2DState();
var direction = this.lastScaleDelta_ - 1; var direction = this.lastScaleDelta_ - 1;
map.withFrozenRendering(function() { ol.interaction.Interaction.rotate(map, view2D, view2DState.rotation);
ol.interaction.Interaction.rotate(map, view2D, view2DState.rotation); ol.interaction.Interaction.zoom(map, view2D, view2DState.resolution,
ol.interaction.Interaction.zoom(map, view2D, view2DState.resolution, undefined, ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION,
undefined, ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION, direction);
direction);
});
this.lastScaleDelta_ = 0; this.lastScaleDelta_ = 0;
return true; return true;
}; };

View File

@@ -127,16 +127,12 @@ ol.interaction.Interaction.rotateWithoutConstraints =
})); }));
} }
} }
goog.asserts.assertInstanceof(view, ol.View2D);
if (goog.isDefAndNotNull(opt_anchor)) { if (goog.isDefAndNotNull(opt_anchor)) {
var center = view.calculateCenterRotate(rotation, opt_anchor); var center = view.calculateCenterRotate(rotation, opt_anchor);
map.withFrozenRendering(function() { view.setCenter(center);
goog.asserts.assertInstanceof(view, ol.View2D);
view.setCenter(center);
view.setRotation(rotation);
});
} else {
view.setRotation(rotation);
} }
view.setRotation(rotation);
} }
}; };
@@ -210,15 +206,11 @@ ol.interaction.Interaction.zoomWithoutConstraints =
})); }));
} }
} }
goog.asserts.assertInstanceof(view, ol.View2D);
if (goog.isDefAndNotNull(opt_anchor)) { if (goog.isDefAndNotNull(opt_anchor)) {
var center = view.calculateCenterZoom(resolution, opt_anchor); var center = view.calculateCenterZoom(resolution, opt_anchor);
map.withFrozenRendering(function() { view.setCenter(center);
goog.asserts.assertInstanceof(view, ol.View2D);
view.setCenter(center);
view.setResolution(resolution);
});
} else {
view.setResolution(resolution);
} }
view.setResolution(resolution);
} }
}; };

View File

@@ -97,50 +97,44 @@ ol.interaction.Select.prototype.handleMapBrowserEvent =
var add = this.addCondition_(mapBrowserEvent); var add = this.addCondition_(mapBrowserEvent);
var map = mapBrowserEvent.map; var map = mapBrowserEvent.map;
var features = this.featureOverlay_.getFeatures(); var features = this.featureOverlay_.getFeatures();
map.withFrozenRendering( if (add) {
/** map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
* @this {ol.interaction.Select} /**
*/ * @param {ol.Feature} feature Feature.
function() { * @param {ol.layer.Layer} layer Layer.
if (add) { */
map.forEachFeatureAtPixel(mapBrowserEvent.pixel, function(feature, layer) {
/** if (goog.array.indexOf(features.getArray(), feature) == -1) {
* @param {ol.Feature} feature Feature. features.push(feature);
* @param {ol.layer.Layer} layer Layer.
*/
function(feature, layer) {
if (goog.array.indexOf(features.getArray(), feature) == -1) {
features.push(feature);
}
}, undefined, this.layerFilter_);
} else {
/** @type {ol.Feature|undefined} */
var feature = map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
/**
* @param {ol.Feature} feature Feature.
* @param {ol.layer.Layer} layer Layer.
*/
function(feature, layer) {
return feature;
}, undefined, this.layerFilter_);
if (goog.isDef(feature)) {
if (features.getLength() == 1) {
if (features.getAt(0) !== feature) {
features.setAt(0, feature);
}
} else {
if (features.getLength() != 1) {
features.clear();
}
features.push(feature);
}
} else {
if (features.getLength() !== 0) {
features.clear();
}
} }
}, undefined, this.layerFilter_);
} else {
/** @type {ol.Feature|undefined} */
var feature = map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
/**
* @param {ol.Feature} feature Feature.
* @param {ol.layer.Layer} layer Layer.
*/
function(feature, layer) {
return feature;
}, undefined, this.layerFilter_);
if (goog.isDef(feature)) {
if (features.getLength() == 1) {
if (features.getAt(0) !== feature) {
features.setAt(0, feature);
} }
}, this); } else {
if (features.getLength() != 1) {
features.clear();
}
features.push(feature);
}
} else {
if (features.getLength() !== 0) {
features.clear();
}
}
}
return false; return false;
}; };

View File

@@ -215,18 +215,6 @@ ol.Map = function(options) {
*/ */
this.frameState_ = null; this.frameState_ = null;
/**
* @private
* @type {number}
*/
this.freezeRenderingCount_ = 0;
/**
* @private
* @type {boolean}
*/
this.dirty_ = false;
/** /**
* @private * @private
* @type {goog.events.Key} * @type {goog.events.Key}
@@ -526,14 +514,6 @@ ol.Map.prototype.forEachFeatureAtPixel =
}; };
/**
* Freeze rendering.
*/
ol.Map.prototype.freezeRendering = function() {
++this.freezeRenderingCount_;
};
/** /**
* Returns the geographical coordinate for a browser event. * Returns the geographical coordinate for a browser event.
* @param {Event} event Event. * @param {Event} event Event.
@@ -1022,13 +1002,7 @@ ol.Map.prototype.isRendered = function() {
* Render. * Render.
*/ */
ol.Map.prototype.renderSync = function() { ol.Map.prototype.renderSync = function() {
if (this.animationDelay_.isActive()) { this.animationDelay_.fire();
// pass
} else if (this.freezeRenderingCount_ === 0) {
this.animationDelay_.fire();
} else {
this.dirty_ = true;
}
}; };
@@ -1036,12 +1010,8 @@ ol.Map.prototype.renderSync = function() {
* Request that renderFrame_ be called some time in the future. * Request that renderFrame_ be called some time in the future.
*/ */
ol.Map.prototype.render = function() { ol.Map.prototype.render = function() {
if (this.freezeRenderingCount_ === 0) { if (!this.animationDelay_.isActive()) {
if (!this.animationDelay_.isActive()) { this.animationDelay_.start();
this.animationDelay_.start();
}
} else {
this.dirty_ = true;
} }
}; };
@@ -1122,10 +1092,6 @@ ol.Map.prototype.renderFrame_ = function(time) {
var i, ii, view2DState; var i, ii, view2DState;
if (this.freezeRenderingCount_ !== 0) {
return;
}
/** /**
* Check whether a size has non-zero width and height. Note that this * Check whether a size has non-zero width and height. Note that this
* function is here because the compiler doesn't recognize that size is * function is here because the compiler doesn't recognize that size is
@@ -1202,7 +1168,6 @@ ol.Map.prototype.renderFrame_ = function(time) {
this.frameState_ = frameState; this.frameState_ = frameState;
this.renderer_.renderFrame(frameState); this.renderer_.renderFrame(frameState);
this.dirty_ = false;
if (!goog.isNull(frameState)) { if (!goog.isNull(frameState)) {
if (frameState.animate) { if (frameState.animate) {
@@ -1285,17 +1250,6 @@ goog.exportProperty(
ol.Map.prototype.setView); ol.Map.prototype.setView);
/**
* Unfreeze rendering.
*/
ol.Map.prototype.unfreezeRendering = function() {
goog.asserts.assert(this.freezeRenderingCount_ > 0);
if (--this.freezeRenderingCount_ === 0 && this.dirty_) {
this.animationDelay_.fire();
}
};
/** /**
* Force a recalculation of the map viewport size. This should be called when * Force a recalculation of the map viewport size. This should be called when
* third-party code changes the size of the map viewport. * third-party code changes the size of the map viewport.
@@ -1319,21 +1273,6 @@ ol.Map.prototype.updateSize = function() {
}; };
/**
* @param {function(this: T)} f Function.
* @param {T=} opt_this The object to use as `this` in `f`.
* @template T
*/
ol.Map.prototype.withFrozenRendering = function(f, opt_this) {
this.freezeRendering();
try {
f.call(opt_this);
} finally {
this.unfreezeRendering();
}
};
/** /**
* @typedef {{controls: ol.Collection, * @typedef {{controls: ol.Collection,
* deviceOptions: olx.DeviceOptions, * deviceOptions: olx.DeviceOptions,