Add new container which don't stop event propagation
and allow overlays to optionnally stop event propagation
This commit is contained in:
+22
-4
@@ -225,13 +225,21 @@ ol.Map = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.overlayContainer_ = goog.dom.createDom(goog.dom.TagName.DIV,
|
this.overlayContainer_ = goog.dom.createDom(goog.dom.TagName.DIV,
|
||||||
'ol-overlaycontainer');
|
'ol-overlaycontainer');
|
||||||
goog.events.listen(this.overlayContainer_, [
|
goog.dom.appendChild(this.viewport_, this.overlayContainer_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Element}
|
||||||
|
*/
|
||||||
|
this.overlayContainerStopEvent_ = goog.dom.createDom(goog.dom.TagName.DIV,
|
||||||
|
'ol-overlaycontainer-stopevent');
|
||||||
|
goog.events.listen(this.overlayContainerStopEvent_, [
|
||||||
goog.events.EventType.CLICK,
|
goog.events.EventType.CLICK,
|
||||||
goog.events.EventType.DBLCLICK,
|
goog.events.EventType.DBLCLICK,
|
||||||
ol.BrowserFeature.HAS_TOUCH ?
|
ol.BrowserFeature.HAS_TOUCH ?
|
||||||
goog.events.EventType.TOUCHSTART : goog.events.EventType.MOUSEDOWN
|
goog.events.EventType.TOUCHSTART : goog.events.EventType.MOUSEDOWN
|
||||||
], goog.events.Event.stopPropagation);
|
], goog.events.Event.stopPropagation);
|
||||||
goog.dom.appendChild(this.viewport_, this.overlayContainer_);
|
goog.dom.appendChild(this.viewport_, this.overlayContainerStopEvent_);
|
||||||
|
|
||||||
var mapBrowserEventHandler = new ol.MapBrowserEventHandler(this);
|
var mapBrowserEventHandler = new ol.MapBrowserEventHandler(this);
|
||||||
goog.events.listen(mapBrowserEventHandler,
|
goog.events.listen(mapBrowserEventHandler,
|
||||||
@@ -591,14 +599,24 @@ ol.Map.prototype.getViewport = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {Element} The map's overlay container. Elements added to this
|
* @return {Element} The map's overlay container. Elements added to this
|
||||||
* container won't let mousedown and touchstart events through to the map, so
|
* container will let mousedown and touchstart events through to the map, so
|
||||||
* clicks and gestures on an overlay don't trigger any MapBrowserEvent.
|
* clicks and gestures on an overlay will trigger MapBrowserEvent events.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.getOverlayContainer = function() {
|
ol.Map.prototype.getOverlayContainer = function() {
|
||||||
return this.overlayContainer_;
|
return this.overlayContainer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Element} The map's overlay container. Elements added to this
|
||||||
|
* container won't let mousedown and touchstart events through to the map, so
|
||||||
|
* clicks and gestures on an overlay don't trigger any MapBrowserEvent.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.getOverlayContainerStopEvent = function() {
|
||||||
|
return this.overlayContainerStopEvent_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Tile} tile Tile.
|
* @param {ol.Tile} tile Tile.
|
||||||
* @param {string} tileSourceKey Tile source key.
|
* @param {string} tileSourceKey Tile source key.
|
||||||
|
|||||||
+10
-2
@@ -60,6 +60,12 @@ ol.Overlay = function(options) {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.stopEvent_ = goog.isDef(options.stopEvent) ? options.stopEvent : false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Element}
|
* @type {Element}
|
||||||
@@ -202,8 +208,10 @@ ol.Overlay.prototype.handleMapChanged = function() {
|
|||||||
this.mapPostrenderListenerKey_ = goog.events.listen(map,
|
this.mapPostrenderListenerKey_ = goog.events.listen(map,
|
||||||
ol.MapEventType.POSTRENDER, this.handleMapPostrender, false, this);
|
ol.MapEventType.POSTRENDER, this.handleMapPostrender, false, this);
|
||||||
this.updatePixelPosition_();
|
this.updatePixelPosition_();
|
||||||
goog.dom.append(
|
goog.dom.append(/** @type {!Node} */ (
|
||||||
/** @type {!Node} */ (map.getOverlayContainer()), this.element_);
|
this.stopEvent_ ? map.getOverlayContainerStopEvent() :
|
||||||
|
map.getOverlayContainer()),
|
||||||
|
this.element_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user