Primo committ Notevole
This commit is contained in:
25
src/googlemap/index.ts
Normal file
25
src/googlemap/index.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
let promise = null
|
||||
const id = 'google-cdn'
|
||||
const url = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyB228FQfRMabWfIczMamI1NSYMJg2FqLts'
|
||||
export default () => {
|
||||
if (!promise) {
|
||||
promise = new Promise((resolve, reject) => {
|
||||
if (document.getElementById(id)) {
|
||||
console.error(`Error loading ${url} async: ${id} is not unique`)
|
||||
return
|
||||
}
|
||||
const script = document.createElement('script')
|
||||
script.src = url
|
||||
script.async = true
|
||||
script.id = id
|
||||
script.onload = () => {
|
||||
resolve()
|
||||
}
|
||||
script.onerror = (err) => {
|
||||
reject(err)
|
||||
}
|
||||
document.body.appendChild(script)
|
||||
})
|
||||
}
|
||||
return promise
|
||||
}
|
||||
Reference in New Issue
Block a user