Render on view changes
This commit is contained in:
+13
-1
@@ -216,6 +216,12 @@ ol.Map = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.viewPropertyListenerKey_ = null;
|
this.viewPropertyListenerKey_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {?ol.EventsKey}
|
||||||
|
*/
|
||||||
|
this.viewChangeListenerKey_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Array.<ol.EventsKey>}
|
* @type {Array.<ol.EventsKey>}
|
||||||
@@ -1102,11 +1108,18 @@ ol.Map.prototype.handleViewChanged_ = function() {
|
|||||||
ol.events.unlistenByKey(this.viewPropertyListenerKey_);
|
ol.events.unlistenByKey(this.viewPropertyListenerKey_);
|
||||||
this.viewPropertyListenerKey_ = null;
|
this.viewPropertyListenerKey_ = null;
|
||||||
}
|
}
|
||||||
|
if (this.viewChangeListenerKey_) {
|
||||||
|
ol.events.unlistenByKey(this.viewChangeListenerKey_);
|
||||||
|
this.viewChangeListenerKey_ = null;
|
||||||
|
}
|
||||||
var view = this.getView();
|
var view = this.getView();
|
||||||
if (view) {
|
if (view) {
|
||||||
this.viewPropertyListenerKey_ = ol.events.listen(
|
this.viewPropertyListenerKey_ = ol.events.listen(
|
||||||
view, ol.ObjectEventType.PROPERTYCHANGE,
|
view, ol.ObjectEventType.PROPERTYCHANGE,
|
||||||
this.handleViewPropertyChanged_, this);
|
this.handleViewPropertyChanged_, this);
|
||||||
|
this.viewChangeListenerKey_ = ol.events.listen(
|
||||||
|
view, ol.events.EventType.CHANGE,
|
||||||
|
this.handleViewPropertyChanged_, this);
|
||||||
}
|
}
|
||||||
this.render();
|
this.render();
|
||||||
};
|
};
|
||||||
@@ -1221,7 +1234,6 @@ ol.Map.prototype.removeOverlay = function(overlay) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.renderFrame_ = function(time) {
|
ol.Map.prototype.renderFrame_ = function(time) {
|
||||||
|
|
||||||
var i, ii, viewState;
|
var i, ii, viewState;
|
||||||
|
|
||||||
var size = this.getSize();
|
var size = this.getSize();
|
||||||
|
|||||||
@@ -160,6 +160,23 @@ describe('ol.Map', function() {
|
|||||||
document.body.removeChild(target);
|
document.body.removeChild(target);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('is called when the view.changed() is called', function() {
|
||||||
|
var view = map.getView();
|
||||||
|
|
||||||
|
var spy = sinon.spy(map, 'render');
|
||||||
|
view.changed();
|
||||||
|
expect(spy.callCount).to.be(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is not called on view changes after the view has been removed', function() {
|
||||||
|
var view = map.getView();
|
||||||
|
map.setView(null);
|
||||||
|
|
||||||
|
var spy = sinon.spy(map, 'render');
|
||||||
|
view.changed();
|
||||||
|
expect(spy.callCount).to.be(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('calls renderFrame_ and results in an postrender event', function(done) {
|
it('calls renderFrame_ and results in an postrender event', function(done) {
|
||||||
|
|
||||||
var spy = sinon.spy(map, 'renderFrame_');
|
var spy = sinon.spy(map, 'renderFrame_');
|
||||||
|
|||||||
Reference in New Issue
Block a user