Merge pull request #1778 from twpayne/render-sync-forces-render
Make renderSync always force a render
This commit is contained in:
@@ -110,12 +110,10 @@ ol.interaction.DragRotateAndZoom.prototype.handleDragEnd =
|
||||
var view2D = view.getView2D();
|
||||
var view2DState = view2D.getView2DState();
|
||||
var direction = this.lastScaleDelta_ - 1;
|
||||
map.withFrozenRendering(function() {
|
||||
ol.interaction.Interaction.rotate(map, view2D, view2DState.rotation);
|
||||
ol.interaction.Interaction.zoom(map, view2D, view2DState.resolution,
|
||||
undefined, ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION,
|
||||
direction);
|
||||
});
|
||||
ol.interaction.Interaction.rotate(map, view2D, view2DState.rotation);
|
||||
ol.interaction.Interaction.zoom(map, view2D, view2DState.resolution,
|
||||
undefined, ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION,
|
||||
direction);
|
||||
this.lastScaleDelta_ = 0;
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -127,16 +127,12 @@ ol.interaction.Interaction.rotateWithoutConstraints =
|
||||
}));
|
||||
}
|
||||
}
|
||||
goog.asserts.assertInstanceof(view, ol.View2D);
|
||||
if (goog.isDefAndNotNull(opt_anchor)) {
|
||||
var center = view.calculateCenterRotate(rotation, opt_anchor);
|
||||
map.withFrozenRendering(function() {
|
||||
goog.asserts.assertInstanceof(view, ol.View2D);
|
||||
view.setCenter(center);
|
||||
view.setRotation(rotation);
|
||||
});
|
||||
} else {
|
||||
view.setRotation(rotation);
|
||||
view.setCenter(center);
|
||||
}
|
||||
view.setRotation(rotation);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -210,15 +206,11 @@ ol.interaction.Interaction.zoomWithoutConstraints =
|
||||
}));
|
||||
}
|
||||
}
|
||||
goog.asserts.assertInstanceof(view, ol.View2D);
|
||||
if (goog.isDefAndNotNull(opt_anchor)) {
|
||||
var center = view.calculateCenterZoom(resolution, opt_anchor);
|
||||
map.withFrozenRendering(function() {
|
||||
goog.asserts.assertInstanceof(view, ol.View2D);
|
||||
view.setCenter(center);
|
||||
view.setResolution(resolution);
|
||||
});
|
||||
} else {
|
||||
view.setResolution(resolution);
|
||||
view.setCenter(center);
|
||||
}
|
||||
view.setResolution(resolution);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -97,50 +97,44 @@ ol.interaction.Select.prototype.handleMapBrowserEvent =
|
||||
var add = this.addCondition_(mapBrowserEvent);
|
||||
var map = mapBrowserEvent.map;
|
||||
var features = this.featureOverlay_.getFeatures();
|
||||
map.withFrozenRendering(
|
||||
/**
|
||||
* @this {ol.interaction.Select}
|
||||
*/
|
||||
function() {
|
||||
if (add) {
|
||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||
/**
|
||||
* @param {ol.Feature} feature 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();
|
||||
}
|
||||
if (add) {
|
||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||
/**
|
||||
* @param {ol.Feature} feature 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);
|
||||
}
|
||||
}, this);
|
||||
} else {
|
||||
if (features.getLength() != 1) {
|
||||
features.clear();
|
||||
}
|
||||
features.push(feature);
|
||||
}
|
||||
} else {
|
||||
if (features.getLength() !== 0) {
|
||||
features.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
@@ -215,18 +215,6 @@ ol.Map = function(options) {
|
||||
*/
|
||||
this.frameState_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.freezeRenderingCount_ = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.dirty_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @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.
|
||||
* @param {Event} event Event.
|
||||
@@ -1022,13 +1002,7 @@ ol.Map.prototype.isRendered = function() {
|
||||
* Render.
|
||||
*/
|
||||
ol.Map.prototype.renderSync = function() {
|
||||
if (this.animationDelay_.isActive()) {
|
||||
// pass
|
||||
} else if (this.freezeRenderingCount_ === 0) {
|
||||
this.animationDelay_.fire();
|
||||
} else {
|
||||
this.dirty_ = true;
|
||||
}
|
||||
this.animationDelay_.fire();
|
||||
};
|
||||
|
||||
|
||||
@@ -1036,12 +1010,8 @@ ol.Map.prototype.renderSync = function() {
|
||||
* Request that renderFrame_ be called some time in the future.
|
||||
*/
|
||||
ol.Map.prototype.render = function() {
|
||||
if (this.freezeRenderingCount_ === 0) {
|
||||
if (!this.animationDelay_.isActive()) {
|
||||
this.animationDelay_.start();
|
||||
}
|
||||
} else {
|
||||
this.dirty_ = true;
|
||||
if (!this.animationDelay_.isActive()) {
|
||||
this.animationDelay_.start();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1122,10 +1092,6 @@ ol.Map.prototype.renderFrame_ = function(time) {
|
||||
|
||||
var i, ii, view2DState;
|
||||
|
||||
if (this.freezeRenderingCount_ !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -1202,7 +1168,6 @@ ol.Map.prototype.renderFrame_ = function(time) {
|
||||
|
||||
this.frameState_ = frameState;
|
||||
this.renderer_.renderFrame(frameState);
|
||||
this.dirty_ = false;
|
||||
|
||||
if (!goog.isNull(frameState)) {
|
||||
if (frameState.animate) {
|
||||
@@ -1285,17 +1250,6 @@ goog.exportProperty(
|
||||
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
|
||||
* 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,
|
||||
* deviceOptions: olx.DeviceOptions,
|
||||
|
||||
Reference in New Issue
Block a user