Improve ol.Overlay extensibility
- make autoPan_ protected; - split updatePixelPosition_() and make it protected; - use a protected setVisible() function.
This commit is contained in:
+38
-21
@@ -97,10 +97,10 @@ ol.Overlay = function(options) {
|
|||||||
this.element_.style.position = 'absolute';
|
this.element_.style.position = 'absolute';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @protected
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
this.autoPan_ = goog.isDef(options.autoPan) ? options.autoPan : false;
|
this.autoPan = goog.isDef(options.autoPan) ? options.autoPan : false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -263,7 +263,7 @@ ol.Overlay.prototype.handleMapChanged = function() {
|
|||||||
if (goog.isDefAndNotNull(map)) {
|
if (goog.isDefAndNotNull(map)) {
|
||||||
this.mapPostrenderListenerKey_ = goog.events.listen(map,
|
this.mapPostrenderListenerKey_ = goog.events.listen(map,
|
||||||
ol.MapEventType.POSTRENDER, this.render, false, this);
|
ol.MapEventType.POSTRENDER, this.render, false, this);
|
||||||
this.updatePixelPosition_();
|
this.updatePixelPosition();
|
||||||
var container = this.stopEvent_ ?
|
var container = this.stopEvent_ ?
|
||||||
map.getOverlayContainerStopEvent() : map.getOverlayContainer();
|
map.getOverlayContainerStopEvent() : map.getOverlayContainer();
|
||||||
if (this.insertFirst_) {
|
if (this.insertFirst_) {
|
||||||
@@ -280,7 +280,7 @@ ol.Overlay.prototype.handleMapChanged = function() {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
ol.Overlay.prototype.render = function() {
|
ol.Overlay.prototype.render = function() {
|
||||||
this.updatePixelPosition_();
|
this.updatePixelPosition();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ ol.Overlay.prototype.render = function() {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
ol.Overlay.prototype.handleOffsetChanged = function() {
|
ol.Overlay.prototype.handleOffsetChanged = function() {
|
||||||
this.updatePixelPosition_();
|
this.updatePixelPosition();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -296,8 +296,8 @@ ol.Overlay.prototype.handleOffsetChanged = function() {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
ol.Overlay.prototype.handlePositionChanged = function() {
|
ol.Overlay.prototype.handlePositionChanged = function() {
|
||||||
this.updatePixelPosition_();
|
this.updatePixelPosition();
|
||||||
if (goog.isDef(this.get(ol.OverlayProperty.POSITION)) && this.autoPan_) {
|
if (goog.isDef(this.get(ol.OverlayProperty.POSITION)) && this.autoPan) {
|
||||||
this.panIntoView_();
|
this.panIntoView_();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -307,7 +307,7 @@ ol.Overlay.prototype.handlePositionChanged = function() {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
ol.Overlay.prototype.handlePositioningChanged = function() {
|
ol.Overlay.prototype.handlePositioningChanged = function() {
|
||||||
this.updatePixelPosition_();
|
this.updatePixelPosition();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -363,7 +363,7 @@ ol.Overlay.prototype.setPosition = function(position) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.Overlay.prototype.panIntoView_ = function() {
|
ol.Overlay.prototype.panIntoView_ = function() {
|
||||||
goog.asserts.assert(this.autoPan_, 'this.autoPan_ should be true');
|
goog.asserts.assert(this.autoPan, 'this.autoPan should be true');
|
||||||
var map = this.getMap();
|
var map = this.getMap();
|
||||||
|
|
||||||
if (!goog.isDef(map) || goog.isNull(map.getTargetElement())) {
|
if (!goog.isDef(map) || goog.isNull(map.getTargetElement())) {
|
||||||
@@ -455,27 +455,48 @@ ol.Overlay.prototype.setPositioning = function(positioning) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* Modify the visibility of the element.
|
||||||
|
* @param {boolean} visible
|
||||||
|
* @protected
|
||||||
*/
|
*/
|
||||||
ol.Overlay.prototype.updatePixelPosition_ = function() {
|
ol.Overlay.prototype.setVisible = function(visible) {
|
||||||
|
if (this.rendered_.visible !== visible) {
|
||||||
|
goog.style.setElementShown(this.element_, visible);
|
||||||
|
this.rendered_.visible = visible;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update pixel position.
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.Overlay.prototype.updatePixelPosition = function() {
|
||||||
var map = this.getMap();
|
var map = this.getMap();
|
||||||
var position = this.getPosition();
|
var position = this.getPosition();
|
||||||
if (!goog.isDef(map) || !map.isRendered() || !goog.isDef(position)) {
|
if (!goog.isDef(map) || !map.isRendered() || !goog.isDef(position)) {
|
||||||
if (this.rendered_.visible) {
|
this.setVisible(false);
|
||||||
goog.style.setElementShown(this.element_, false);
|
|
||||||
this.rendered_.visible = false;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pixel = map.getPixelFromCoordinate(position);
|
var pixel = map.getPixelFromCoordinate(position);
|
||||||
goog.asserts.assert(!goog.isNull(pixel), 'pixel should not be null');
|
|
||||||
var mapSize = map.getSize();
|
var mapSize = map.getSize();
|
||||||
|
this.updateRenderedPosition(pixel, mapSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Pixel} pixel
|
||||||
|
* @param {ol.Size|undefined} mapSize
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.Overlay.prototype.updateRenderedPosition = function(pixel, mapSize) {
|
||||||
|
goog.asserts.assert(!goog.isNull(pixel), 'pixel should not be null');
|
||||||
goog.asserts.assert(goog.isDef(mapSize), 'mapSize should be defined');
|
goog.asserts.assert(goog.isDef(mapSize), 'mapSize should be defined');
|
||||||
var style = this.element_.style;
|
var style = this.element_.style;
|
||||||
var offset = this.getOffset();
|
var offset = this.getOffset();
|
||||||
goog.asserts.assert(goog.isArray(offset), 'offset should be an array');
|
goog.asserts.assert(goog.isArray(offset), 'offset should be an array');
|
||||||
|
|
||||||
var positioning = this.getPositioning();
|
var positioning = this.getPositioning();
|
||||||
goog.asserts.assert(goog.isDef(positioning),
|
goog.asserts.assert(goog.isDef(positioning),
|
||||||
'positioning should be defined');
|
'positioning should be defined');
|
||||||
@@ -531,9 +552,5 @@ ol.Overlay.prototype.updatePixelPosition_ = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.rendered_.visible) {
|
this.setVisible(true);
|
||||||
goog.style.setElementShown(this.element_, true);
|
|
||||||
this.rendered_.visible = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user