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

added mouseover event handler #6000

Merged
merged 6 commits into from
Jan 19, 2018
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
10 changes: 10 additions & 0 deletions src/ui/bind_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function bindHandlers(map: Map, options: {}) {
el.addEventListener('mousedown', onMouseDown, false);
el.addEventListener('mouseup', onMouseUp, false);
el.addEventListener('mousemove', onMouseMove, false);
el.addEventListener('mouseover', onMouseOver, false);
el.addEventListener('touchstart', onTouchStart, false);
el.addEventListener('touchend', onTouchEnd, false);
el.addEventListener('touchmove', onTouchMove, false);
Expand Down Expand Up @@ -80,6 +81,15 @@ module.exports = function bindHandlers(map: Map, options: {}) {
fireMouseEvent('mousemove', e);
}

function onMouseOver(e: MouseEvent) {

let target: any = e.toElement || e.target;
while (target && target !== el) target = target.parentNode;
if (target !== el) return;

fireMouseEvent('mouseover', e);
}

function onTouchStart(e: TouchEvent) {
map.stop();
fireTouchEvent('touchstart', e);
Expand Down
16 changes: 15 additions & 1 deletion src/ui/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type MapMouseEvent = {
| 'click'
| 'dblclick'
| 'mousemove'
| 'mouseover'
| 'mouseenter'
| 'mouseleave'
| 'mouseover'
Expand Down Expand Up @@ -130,14 +131,27 @@ export type MapEvent =
/**
* Fired when a pointing device (usually a mouse) is moved within the map.
*
* @event mousemove
* @event mouseover
* @memberof Map
* @instance
* @property {MapMouseEvent} data
* @see [Get coordinates of the mouse pointer](https://www.mapbox.com/mapbox-gl-js/example/mouse-position/)
* @see [Highlight features under the mouse pointer](https://www.mapbox.com/mapbox-gl-js/example/hover-styles/)
* @see [Display a popup on hover](https://www.mapbox.com/mapbox-gl-js/example/popup-on-hover/)
*/
| 'mouseover'

/**
* Fired when a pointing device (usually a mouse) is moved within the map.
*
* @event mousemove
* @memberof Map
* @instance
* @property {MapMouseEvent} data
* @see [Get coordinates of the mouse pointer](https://www.mapbox.com/mapbox-gl-js/example/mouse-position/)
* @see [Highlight features under the mouse pointer](https://www.mapbox.com/mapbox-gl-js/example/hover-styles/)
* @see [Display a popup on over](https://www.mapbox.com/mapbox-gl-js/example/popup-on-hover/)
*/
| 'mousemove'

/**
Expand Down