Skip to content

Commit

Permalink
Allow to use custom version explicitly in GoogleMap (eg. 'beta'). Non…
Browse files Browse the repository at this point in the history
…e by default
  • Loading branch information
VictorVelarde committed Dec 13, 2022
1 parent 15fb8a0 commit bdec577
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/react-basemaps/src/basemaps/GoogleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { debounce } from '@carto/react-core';
* @param { Object } props.basemap.options - *MapOptions* as defined by https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions
* @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.getTooltip - (Optional) Tooltip handler
* @param { function } props.onResize - (Optional) onResize handler
* @param { function } props.onViewStateChange - (Optional) onViewStateChange handler
* @param { string } props.apiKey - Google Maps API Key
* @param { string } props.mapId - Google Maps custom mapId
* @param { string } props.customVersion - (Optional) Google Maps custom version, that will be specified at url level. Eg: if customVersion === 'beta' it will use internally like https://maps.google.com/maps/api/js?v=beta
* @returns { JSX.Element } - Data returned from the SQL query execution
*/
export function GoogleMap(props) {
Expand All @@ -26,7 +27,8 @@ export function GoogleMap(props) {
onResize,
onViewStateChange,
apiKey,
mapId
mapId,
customVersion = null
} = props;
// based on https://publiuslogic.com/blog/google-maps+react-hooks/
const containerRef = useRef();
Expand Down Expand Up @@ -137,7 +139,10 @@ export function GoogleMap(props) {
script.id = 'gmaps';
script.async = true;
script.type = `text/javascript`;
script.src = `https://maps.google.com/maps/api/js?v=beta&key=` + apiKey;

let url = `https://maps.google.com/maps/api/js?key=${apiKey}`;
if (customVersion) url = url + `&v=${customVersion}`;
script.src = url;
const headScript = document.getElementsByTagName(`script`)[0];
headScript.parentNode.insertBefore(script, headScript);
script.addEventListener(`load`, onLoad);
Expand Down

0 comments on commit bdec577

Please sign in to comment.