/
purp-map-gmap.js
36 lines (29 loc) · 958 Bytes
/
purp-map-gmap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
let map;
const MIN_ZOOM_LEVEL = 5;
async function initMap(callback) {
let key = GOOGLE_MAPS_API_KEY;
if (!key) {
alert("Google maps key missing");
return;
}
console.log(`Using api key: ${key}`);
// Fetch the maps API
let maps_url = `https://maps.googleapis.com/maps/api/js?key=${key}&libraries=&v=beta`
await $.getScript(maps_url);
// Handle optional map parameters
let zoom = parseInt($.QueryString.zoom || "12");
let lat = parseFloat($.QueryString.lat || "37.382");
let lng = parseFloat($.QueryString.lng || "-122.064");
// Create a map
let elem = document.getElementById('map');
let mapTypeId = "roadmap";
map = new google.maps.Map(elem, {
center: new google.maps.LatLng(lat, lng),
zoom: zoom,
mapTypeId: mapTypeId,
mapId: "44f4acbc0b00dbf9",
minZoom: MIN_ZOOM_LEVEL,
});
return map;
}
export {map, initMap, MIN_ZOOM_LEVEL}