Skip to content

Commit 3bf1454

Browse files
committed
allow mouse event pass through
1 parent e7acc9f commit 3bf1454

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

examples/components/withCustomOverlay.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const WithCustomOverlay = (props) => {
2020
position={{ lat: 37.782551, lng: -122.425368 }}
2121
visible={showOverlay}
2222
className={styles.overlayContainer}
23+
passThroughMouseEvents={true}
2324
>
2425
<div>Hi there. I'm a custom overlay.</div>
2526
</CustomOverlay>

src/components/CustomOverlay.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import React, { useRef, useEffect } from 'react';
22
import PropTypes from 'prop-types';
33

44
function createPopupClass() {
5-
function Popup({ position, content, map }) {
5+
function Popup({ position, content, map, passThroughMouseEvents }) {
66
this.position = position;
77
this.containerDiv = content;
88
this.setMap(map);
9-
google.maps.OverlayView.preventMapHitsAndGesturesFrom(this.containerDiv);
9+
if (!passThroughMouseEvents) {
10+
google.maps.OverlayView.preventMapHitsAndGesturesFrom(this.containerDiv);
11+
}
1012
}
1113

1214
Popup.prototype = Object.create(google.maps.OverlayView.prototype);
@@ -40,7 +42,15 @@ function createPopupClass() {
4042
return Popup;
4143
}
4244

43-
const CustomPopup = ({ map, position, children, visible, google, className }) => {
45+
const CustomPopup = ({
46+
map,
47+
position,
48+
children,
49+
visible,
50+
google,
51+
className,
52+
passThroughMouseEvents
53+
}) => {
4454
const containerEl = useRef(null);
4555
useEffect(() => {
4656
if (map) {
@@ -49,7 +59,8 @@ const CustomPopup = ({ map, position, children, visible, google, className }) =>
4959
new Popup({
5060
position: pos,
5161
content: containerEl.current,
52-
map
62+
map,
63+
passThroughMouseEvents
5364
});
5465
}
5566
}, [map]);
@@ -70,7 +81,8 @@ CustomPopup.propTypes = {
7081
children: PropTypes.element.isRequired,
7182
map: PropTypes.object,
7283
position: PropTypes.object,
73-
visible: PropTypes.bool
84+
visible: PropTypes.bool,
85+
passThroughMouseEvents: PropTypes.bool
7486
};
7587

7688
CustomPopup.defaultProps = {

0 commit comments

Comments
 (0)