Skip to content

Commit

Permalink
Merge pull request #1 from Sasha95/develop
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
Sasha95 authored Dec 27, 2023
2 parents 3275c5d + a2a1915 commit 213e0bb
Show file tree
Hide file tree
Showing 5 changed files with 1,345 additions and 2,142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ function DrawingManagerFunctional({
}, [instance, options])

useEffect(() => {
if (drawingMode && instance !== null) {
instance.setDrawingMode(drawingMode)
if (instance !== null) {
instance.setDrawingMode(drawingMode ?? null)
}
}, [instance, drawingMode])

Expand Down
10 changes: 5 additions & 5 deletions packages/react-google-maps-api/src/useJsApiLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function useJsApiLoader({
const loader = useMemo(() => {
return new Loader({
id,
apiKey: googleMapsApiKey,
apiKey: googleMapsApiKey || "",
version,
libraries,
language: language || 'en',
Expand All @@ -62,13 +62,13 @@ export function useJsApiLoader({
return
} else {
loader.load().then(() => {
if (isMounted.current) {setLoaded(true)}
if (isMounted.current) { setLoaded(true) }

return
})
.catch((error) => {
setLoadError(error)
})
.catch((error) => {
setLoadError(error)
})
}
}, [])

Expand Down
8 changes: 5 additions & 3 deletions packages/react-google-maps-api/src/useLoadScript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { defaultLoadScriptProps } from './LoadScript'
export interface UseLoadScriptOptions extends LoadScriptUrlOptions {
id?: string | undefined
nonce?: string | undefined
preventGoogleFontsLoading?: boolean | undefined
preventGoogleFontsLoading?: boolean | undefined;
}

let previouslyLoadedUrl: string
Expand All @@ -30,6 +30,7 @@ export function useLoadScript({
channel,
mapIds,
authReferrerPolicy,
apiUrl = "https://maps.googleapis.com"
}: UseLoadScriptOptions): {
isLoaded: boolean
loadError: Error | undefined
Expand Down Expand Up @@ -76,7 +77,8 @@ export function useLoadScript({
libraries,
channel,
mapIds,
authReferrerPolicy
authReferrerPolicy,
apiUrl
})

useEffect(
Expand Down Expand Up @@ -105,7 +107,7 @@ export function useLoadScript({
}
console.warn(`
There has been an Error with loading Google Maps API script, please check that you provided correct google API key (${googleMapsApiKey ||
'-'}) or Client ID (${googleMapsClientId || '-'})
'-'}) or Client ID (${googleMapsClientId || '-'})
Otherwise it is a Network issue.
`)
console.error(err)
Expand Down
14 changes: 5 additions & 9 deletions packages/react-google-maps-api/src/utils/make-load-script-url.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { Library } from '@googlemaps/js-api-loader'
import invariant from 'invariant'

export type Libraries = Library[]

export interface LoadScriptUrlOptions {
googleMapsApiKey: string | ""
googleMapsApiKey: string | undefined
googleMapsClientId?: string | undefined
version?: string | undefined
language?: string | undefined
Expand All @@ -13,26 +12,23 @@ export interface LoadScriptUrlOptions {
channel?: string | undefined
mapIds?: string[] | undefined
authReferrerPolicy?: 'origin' | undefined
apiUrl: string
}

export function makeLoadScriptUrl({
googleMapsApiKey,
googleMapsClientId,
version = 'weekly',
apiUrl,
language,
region,
libraries,
channel,
mapIds,
authReferrerPolicy
authReferrerPolicy,
}: LoadScriptUrlOptions): string {
const params = []

invariant(
(googleMapsApiKey && googleMapsClientId) || !(googleMapsApiKey && googleMapsClientId),
'You need to specify either googleMapsApiKey or googleMapsClientId for @react-google-maps/api load script to work. You cannot use both at the same time.'
)

if (googleMapsApiKey) {
params.push(`key=${googleMapsApiKey}`)
} else if (googleMapsClientId) {
Expand Down Expand Up @@ -69,5 +65,5 @@ export function makeLoadScriptUrl({

params.push('callback=initMap')

return `https://maps.googleapis.com/maps/api/js?${params.join('&')}`
return `${apiUrl}/maps/api/js?${params.join('&')}`
}
Loading

0 comments on commit 213e0bb

Please sign in to comment.