Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIMarker content support scroll when eventsPropagation=false #2221

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions src/ui/InfoWindow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isFunction, isNumber, isObject, isString } from '../core/util';
import { createEl, addDomEvent, removeDomEvent, on, off } from '../core/util/dom';
import { createEl, addDomEvent, removeDomEvent } from '../core/util/dom';
import Coordinate from '../geo/Coordinate';
import Point from '../geo/Point';
import Size from '../geo/Size';
Expand Down Expand Up @@ -442,41 +442,6 @@ class InfoWindow extends UIComponent {
return width;
}

_bindDomEvents(dom, to) {
if (!dom) {
return;
}
const events = this._getDomEvents();
const bindEvent = to === 'on' ? on : off;
for (const eventName in events) {
bindEvent(dom, eventName, events[eventName], this);
}
}

_getDomEvents() {
return {
'mouseover': this._onDomMouseover,
'mouseout': this._onDomMouseout
};
}

// eslint-disable-next-line no-unused-vars
_onDomMouseover(domEvent) {
const map = this.getMap();
if (!map) {
return;
}
map.options['preventWheelScroll'] = false;
}

// eslint-disable-next-line no-unused-vars
_onDomMouseout(domEvent) {
const map = this.getMap();
if (!map) {
return;
}
map.options['preventWheelScroll'] = true;
}
}

InfoWindow.mergeOptions(options);
Expand Down
39 changes: 39 additions & 0 deletions src/ui/UIComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,45 @@ class UIComponent extends Eventable(Class) {
}
return false;
}

_bindDomEvents(dom, to) {
if (!dom) {
return;
}
const events = this._getDomEvents() || {};
const bindEvent = to === 'on' ? on : off;
for (const eventName in events) {
bindEvent(dom, eventName, events[eventName], this);
}
}

_getDomEvents() {
return {
'mouseover': this._onDomMouseover,
'mouseout': this._onDomMouseout
};
}

_configMapPreventWheelScroll(preventWheelScroll) {
const map = this.getMap();
if (!map) {
return;
}
if (this.options.eventsPropagation) {
return;
}
map.options['preventWheelScroll'] = preventWheelScroll;
}

// eslint-disable-next-line no-unused-vars
_onDomMouseover(domEvent) {
this._configMapPreventWheelScroll(false);
}

// eslint-disable-next-line no-unused-vars
_onDomMouseout(domEvent) {
this._configMapPreventWheelScroll(true);
}
}

UIComponent.mergeOptions(options);
Expand Down
3 changes: 3 additions & 0 deletions src/ui/UIMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ class UIMarker extends Handlerable(UIComponent) {
* @return {HTMLElement} UIMarker's HTMLElement
*/
buildOn() {
const oldDom = this.getDOM();
this._bindDomEvents(oldDom, 'off');
let dom;
const content = this.options['content'];
const isStr = isString(content);
Expand All @@ -380,6 +382,7 @@ class UIMarker extends Handlerable(UIComponent) {
dom.className = this.options['containerClass'];
}
this._registerDOMEvents(dom);
this._bindDomEvents(dom, 'on');
return dom;
}

Expand Down