Skip to content

Commit

Permalink
Add capturePointerMove to NavigationControl (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Williams authored and Pessimistress committed Nov 5, 2020
1 parent 7a7fa44 commit c86bfc7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions docs/advanced/custom-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Stop propagation of click event to the map component. Can be used to stop map fr
##### `captureDoubleClick` {Boolean} - default: `true`
Stop propagation of dblclick event to the map component. Can be used to stop map from zooming when this component is double clicked.

##### `capturePointerMove` {Boolean} - default: `false`
Stop propagation of pointermove event to the map component. Can be used to stop map from calling the `onMouseMove` or `onTouchMove` callback when this component is hovered.

## Private Members

##### `_containerRef`
Expand Down
17 changes: 14 additions & 3 deletions src/components/base-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,25 @@ const propTypes = {
// Stop map click
captureClick: PropTypes.bool,
// Stop map double click
captureDoubleClick: PropTypes.bool
captureDoubleClick: PropTypes.bool,
// Stop map pointer move
capturePointerMove: PropTypes.bool
};

const defaultProps = {
captureScroll: false,
captureDrag: true,
captureClick: true,
captureDoubleClick: true
captureDoubleClick: true,
capturePointerMove: false
};

export type BaseControlProps = {
captureScroll: boolean,
captureDrag: boolean,
captureClick: boolean,
captureDoubleClick: boolean,
capturePointerMove: boolean,
children?: any
};

Expand Down Expand Up @@ -81,7 +85,8 @@ export default class BaseControl<
panstart: this._onDragStart,
anyclick: this._onClick,
click: this._onClick,
dblclick: this._onDblClick
dblclick: this._onDblClick,
pointermove: this._onPointerMove
};
eventManager.watch(this._events, ref);
}
Expand Down Expand Up @@ -122,6 +127,12 @@ export default class BaseControl<
}
};

_onPointerMove = (evt: MjolnirEvent) => {
if (this.props.capturePointerMove) {
evt.stopPropagation();
}
};

_render() {
throw new Error('_render() not implemented');
}
Expand Down
3 changes: 2 additions & 1 deletion src/overlays/canvas-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const defaultProps = {
captureScroll: false,
captureDrag: false,
captureClick: false,
captureDoubleClick: false
captureDoubleClick: false,
capturePointerMove: false
};

export type CanvasOverlayProps = BaseControlProps & {
Expand Down
3 changes: 2 additions & 1 deletion src/overlays/html-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const defaultProps = {
captureScroll: false,
captureDrag: false,
captureClick: false,
captureDoubleClick: false
captureDoubleClick: false,
capturePointerMove: false
};

export type HTMLOverlayProps = BaseControlProps & {
Expand Down
3 changes: 2 additions & 1 deletion src/overlays/svg-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const defaultProps = {
captureScroll: false,
captureDrag: false,
captureClick: false,
captureDoubleClick: false
captureDoubleClick: false,
capturePointerMove: false
};

export type SVGOverlayProps = BaseControlProps & {
Expand Down

0 comments on commit c86bfc7

Please sign in to comment.