From 40fa0a5ddbf5b6d42a277f3506697d5b648b4b3c Mon Sep 17 00:00:00 2001 From: Shylpx Date: Tue, 25 Jul 2023 13:12:39 +0100 Subject: [PATCH] Add click event to GoogleMap component (#747) --- CHANGELOG.md | 2 ++ packages/react-basemaps/src/basemaps/GoogleMap.js | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c98c93ad..ddeef7d2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Not released +- Add onClick event handler to GoogleMap component [#747](https://github.com/CartoDB/carto-react/pull/747) + ## 2.2 ### 2.2.1 (2023-07-21) diff --git a/packages/react-basemaps/src/basemaps/GoogleMap.js b/packages/react-basemaps/src/basemaps/GoogleMap.js index be1edcecf..9373ca88c 100644 --- a/packages/react-basemaps/src/basemaps/GoogleMap.js +++ b/packages/react-basemaps/src/basemaps/GoogleMap.js @@ -11,6 +11,7 @@ import { debounce } from '@carto/react-core'; * @param { Object } props.viewState - Viewstate, as defined by deck.gl. Just center and zoom level are supported * @param { Layer[] } props.layers - deck.gl layers array * @param { function } props.getTooltip - (Optional) Tooltip handler + * @param { function } props.onClick - (Optional) onClick handler * @param { function } props.onResize - (Optional) onResize handler * @param { function } props.onViewStateChange - (Optional) onViewStateChange handler * @param { string } props.apiKey - Google Maps API Key @@ -24,6 +25,7 @@ export function GoogleMap(props) { viewState, layers, getTooltip, + onClick, onResize, onViewStateChange, apiKey, @@ -90,6 +92,9 @@ export function GoogleMap(props) { const handleViewportChangeDebounced = debounce(handleViewportChange, 200); map.addListener('bounds_changed', handleViewportChangeDebounced); + if (onClick) { + map.addListener('click', onClick); + } map.addListener('resize', () => { onResize && onResize({