google-maps-js-api-react
Version:
Fast, tree-shakable, and light-weight React components and hooks for integrating Google Maps API functionality
1 lines • 5.34 kB
Source Map (JSON)
{"version":3,"sources":["../../src/OverlayView/index.tsx"],"names":["forwardRef","useConst","noop","handleRef_default","GoogleMapsLoader","MAPS","setRef","props","useContext","MapContext_default","useLayoutEffect","createPortal","PanesContext_default"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,IAAI,YAAA;AAEJ,IAAM,WAAc,GAAAA,gBAAA;AAAA,EAClB,CAAC,KAAA,EAAO,QACN,KAAAC,yBAAA,CAAS,MAAM;AACb,IAAA,IAAI,IAAO,GAAAC,qBAAA;AAEX,IAAI,IAAA,GAAA;AAEJ,IAAI,IAAA,GAAA;AAEJ,IAAI,IAAA,GAAA;AAEJ,IAAM,MAAA,EAAE,cAAgB,EAAA,yBAAA,EAA8B,GAAA,KAAA;AAEtD,IAAM,MAAA,GAAA,GAAMC,mCAAuB,CAAA,CAAC,EAAO,KAAA;AACzC,MAAA,IAAI,CAAC,YAAc,EAAA;AACjB,QAAe,YAAA,GAAAC,sCAAA,CAAiB,GAAI,CAAAC,sBAAI,CAAG,CAAA,WAAA;AAAA;AAG7C,MAAA,IAAI,yBAA2B,EAAA;AAC7B,QAAA,YAAA,CAAa,8BAA8B,EAAE,CAAA;AAAA,iBACpC,cAAgB,EAAA;AACzB,QAAA,YAAA,CAAa,mBAAmB,EAAE,CAAA;AAAA;AAGpC,MAAA,MAAM,QAAQ,EAAG,CAAA,KAAA;AAEjB,MAAM,MAAA,WAAA,GAAc,IAAI,YAAa,EAAA;AAErC,MAAA,MAAM,aAAgB,GAAA,WAAA,CAAY,aAAc,CAAA,IAAA,CAAK,WAAW,CAAA;AAEhE,MAAY,WAAA,CAAA,KAAA,GAAQ,YAAY,QAAW,GAAAH,qBAAA;AAE3C,MAAA,KAAA,CAAM,QAAW,GAAA,UAAA;AAEjB,MAAA,IAAA,GAAO,MAAM;AACX,QAAA,MAAM,MAAM,aAAc,EAAA,CAAE,qBAAqB,EAAE,GAAA,EAAK,KAAK,CAAA;AAE7D,QAAA,IAAI,GAAK,EAAA;AACP,UAAM,KAAA,CAAA,IAAA,GAAO,IAAI,CAAI,GAAA,IAAA;AACrB,UAAM,KAAA,CAAA,GAAA,GAAM,IAAI,CAAI,GAAA,IAAA;AAAA;AACtB,OACF;AAEA,MAAA,WAAA,CAAY,IAAO,GAAA,IAAA;AAEnB,MAAA,WAAA,CAAY,OAAO,GAAG,CAAA;AAEtB,MAAAI,uBAAA,CAAO,UAAU,EAAE,CAAA;AAEnB,MAAA,OAAO,MAAM;AACX,QAAA,WAAA,CAAY,OAAO,IAAI,CAAA;AAEvB,QAAAA,uBAAA,CAAO,UAAU,IAAI,CAAA;AAErB,QAAO,IAAA,GAAAJ,qBAAA;AAAA,OACT;AAAA,KACD,CAAA;AAED,IAAA,OAAO,CAACK,MAA4B,KAAA;AAClC,MAAA,GAAA,GAAMC,iBAAWC,oCAAU,CAAA;AAE3B,MAAgBC,qBAAA,CAAA,IAAA,EAAM,CAAE,GAAMH,GAAAA,MAAAA,CAAM,KAAO,GAAMA,GAAAA,MAAAA,CAAM,GAAI,CAAC,CAAA;AAE5D,MAAO,OAAAI,qBAAA;AAAA,QACLJ,MAAAA,CAAM,OAAO,GAAG,CAAA;AAAA,QAChBC,gBAAW,CAAAI,sCAAY,CAAEL,CAAAA,MAAAA,CAAM,gBAAgB,oBAAoB;AAAA,OACrE;AAAA,KACF;AAAA,GACD,EAAE,KAAK;AACZ,CAAA;AAEA,IAAO,mBAAQ,GAAA","file":"chunk-CZMCKSGR.cjs","sourcesContent":["import {\n type RefCallback,\n type ReactElement,\n useContext,\n forwardRef,\n useLayoutEffect,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport noop from 'lodash.noop';\nimport useConst from 'react-helpful-utils/useConst';\nimport PanesContext from '../utils/PanesContext';\nimport { GoogleMapsLoader } from 'google-maps-js-api-loader';\nimport { MAPS } from '../utils/constants';\nimport setRef from 'react-helpful-utils/setRef';\nimport handleRef from '../utils/handleRef';\nimport MapContext from '../utils/MapContext';\n\nexport type OverlayViewProps = {\n /**\n * Specifies which map pane to use for this overlay.\n * @see [link](https://developers.google.com/maps/documentation/javascript/reference/overlay-view#MapPanes)\n * @default 'overlayMouseTarget'\n */\n mapPaneLayer?: keyof google.maps.MapPanes;\n /**\n * stops click, tap, drag, and wheel events on the element from bubbling up to the map. Use this to prevent map dragging and zooming, as well as map `\"click\"` events\n */\n preventMapHitsAndGestures?: boolean;\n /**\n * stops click or tap on the element from bubbling up to the map. Use this to prevent the map from triggering `\"click\"` events\n */\n preventMapHits?: boolean;\n /**\n * [render](https://react.dev/reference/react/cloneElement#passing-data-with-a-render-prop) prop, a function that returns a React element and provides the ability to attach {@link ref} to it\n */\n render(ref: RefCallback<HTMLElement>): ReactElement;\n lat: number;\n lng: number;\n};\n\nlet _OverlayView: typeof google.maps.OverlayView;\n\nconst OverlayView = forwardRef<HTMLElement, OverlayViewProps>(\n (props, outerRef) =>\n useConst(() => {\n let draw = noop;\n\n let lat: number;\n\n let lng: number;\n\n let map: google.maps.Map;\n\n const { preventMapHits, preventMapHitsAndGestures } = props;\n\n const ref = handleRef<HTMLElement>((el) => {\n if (!_OverlayView) {\n _OverlayView = GoogleMapsLoader.get(MAPS)!.OverlayView;\n }\n\n if (preventMapHitsAndGestures) {\n _OverlayView.preventMapHitsAndGesturesFrom(el);\n } else if (preventMapHits) {\n _OverlayView.preventMapHitsFrom(el);\n }\n\n const style = el.style;\n\n const overlayView = new _OverlayView();\n\n const getProjection = overlayView.getProjection.bind(overlayView);\n\n overlayView.onAdd = overlayView.onRemove = noop;\n\n style.position = 'absolute';\n\n draw = () => {\n const pos = getProjection().fromLatLngToDivPixel({ lat, lng });\n\n if (pos) {\n style.left = pos.x + 'px';\n style.top = pos.y + 'px';\n }\n };\n\n overlayView.draw = draw;\n\n overlayView.setMap(map);\n\n setRef(outerRef, el);\n\n return () => {\n overlayView.setMap(null);\n\n setRef(outerRef, null);\n\n draw = noop;\n };\n });\n\n return (props: OverlayViewProps) => {\n map = useContext(MapContext);\n\n useLayoutEffect(draw, [(lat = props.lat), (lng = props.lng)]);\n\n return createPortal(\n props.render(ref),\n useContext(PanesContext)[props.mapPaneLayer || 'overlayMouseTarget']\n );\n };\n })(props)\n);\n\nexport default OverlayView;\n"]}