Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1

Merged
merged 3 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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