Merge pull request #855 from elemoine/zoom-slider-fix
Zoomslider cannot be added to a map with no target
This commit is contained in:
@@ -62,6 +62,13 @@ ol.control.ZoomSlider = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
this.direction_ = ol.control.ZoomSlider.direction.VERTICAL;
|
this.direction_ = ol.control.ZoomSlider.direction.VERTICAL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the slider is initialized.
|
||||||
|
* @type {boolean}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.sliderInitialized_ = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Array.<?number>}
|
* @type {Array.<?number>}
|
||||||
@@ -107,11 +114,8 @@ ol.control.ZoomSlider.direction = {
|
|||||||
*/
|
*/
|
||||||
ol.control.ZoomSlider.prototype.setMap = function(map) {
|
ol.control.ZoomSlider.prototype.setMap = function(map) {
|
||||||
goog.base(this, 'setMap', map);
|
goog.base(this, 'setMap', map);
|
||||||
this.initSlider_();
|
if (!goog.isNull(map)) {
|
||||||
var resolution = map.getView().getView2D().getResolution();
|
map.render();
|
||||||
if (goog.isDef(resolution)) {
|
|
||||||
this.currentResolution_ = resolution;
|
|
||||||
this.positionThumbForResolution_(resolution);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -147,6 +151,7 @@ ol.control.ZoomSlider.prototype.initSlider_ = function() {
|
|||||||
limits = new goog.math.Rect(0, 0, 0, h);
|
limits = new goog.math.Rect(0, 0, 0, h);
|
||||||
}
|
}
|
||||||
this.dragger_.setLimits(limits);
|
this.dragger_.setLimits(limits);
|
||||||
|
this.sliderInitialized_ = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -154,6 +159,14 @@ ol.control.ZoomSlider.prototype.initSlider_ = function() {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.control.ZoomSlider.prototype.handleMapPostrender = function(mapEvent) {
|
ol.control.ZoomSlider.prototype.handleMapPostrender = function(mapEvent) {
|
||||||
|
if (goog.isNull(mapEvent.frameState)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
goog.asserts.assert(
|
||||||
|
goog.isDefAndNotNull(mapEvent.frameState.view2DState));
|
||||||
|
if (!this.sliderInitialized_) {
|
||||||
|
this.initSlider_();
|
||||||
|
}
|
||||||
var res = mapEvent.frameState.view2DState.resolution;
|
var res = mapEvent.frameState.view2DState.resolution;
|
||||||
if (res !== this.currentResolution_) {
|
if (res !== this.currentResolution_) {
|
||||||
this.currentResolution_ = res;
|
this.currentResolution_ = res;
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ describe('ol.control.ZoomSlider', function() {
|
|||||||
control.element.style.width = '1000px';
|
control.element.style.width = '1000px';
|
||||||
control.element.style.height = '10px';
|
control.element.style.height = '10px';
|
||||||
control.setMap(map);
|
control.setMap(map);
|
||||||
|
control.initSlider_();
|
||||||
|
|
||||||
var horizontal = ol.control.ZoomSlider.direction.HORIZONTAL;
|
var horizontal = ol.control.ZoomSlider.direction.HORIZONTAL;
|
||||||
expect(control.direction_).to.be(horizontal);
|
expect(control.direction_).to.be(horizontal);
|
||||||
|
|||||||
Reference in New Issue
Block a user