UMass Amherst: Science Building Tour
Sample code for Google Maps Platform JavaScript API author(s): Justin Poehnelt
by aatallah
HTML
<!doctype html>
<!--
@license
Copyright 2019 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<html>
<head>
<title>UMass Amherst: Science Building Tour</title>
<link href='https://fonts.googleapis.com/css?family=Open Sans' rel='stylesheet'>
<!-- jsFiddle will insert css and js -->
</head>
<body>
<h4>UMass Amherst's Centers of Science: A Tour</h4>
<p>
The best place for parking, <b>Lot 25</b>, is highlighted in <span style= "color:#881c1c">red</span>. Then, follow the <span style= "color:#881c1c">red</span> line up <b>Holdsworth Way</b> to begin your journey!
</p>
<div id="map"></div>
<!-- prettier-ignore -->
<script>(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})
({key: "AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg", v: "beta"});</script>
</body>
</html>
CSS
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Always set the map height explicitly to define the size of the div element
* that contains the map.
*/
#map {
height: 100%;
}
/*
* Optional: Makes the sample page fill the window.
*/
html,
body {
height: 100%;
margin: 2px;
padding: 0;
font-family: 'Open Sans';
}
h4 {
background-color: #881c1c;
color: white;
text-align: center;
font-family: 'Open Sans';
}
p {
font-size: 12px;
text-align: center;
font-family: 'Open Sans';
}
JavaScript
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// Initial map generation
async function initMap() {
const center = { lat: 42.392550, lng: -72.525031 };
// Request needed libraries.
const { Map, InfoWindow } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary(
"marker",
);
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 15,
center: center,
mapId: "4504f8b37365c3d0",
mapTypeId: "satellite",
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
mapTypeIds: ["roadmap", "satellite", "hybrid", "terrain"],
}
});
// Set LatLng and title text for the markers. The first marker receives the initial focus when tab is pressed. Use arrow keys to move between markers; press tab again to cycle through the map controls.
const tourStops = [
{
position: { lat: 42.3928651, lng: -72.5310157 },
title: "Holdsworth Hall",
},
{
position: { lat: 42.392345, lng: -72.530353 },
title: "Hatch Laboratory",
},
{
position: {lat: 42.39322388850513, lng: -72.52903110731859},
title: "Knowles Engineering Building",
},
{
position: { lat: 42.393152, lng: -72.5279834 },
title: "Goessmann Laboratory",
},
{
position: {lat: 42.394121, lng: -72.5276503 },
title: "Lederle Graduate Research Center",
},
{
position: {lat: 42.39378675772498, lng: -72.52638997969242},
title: "Physical Sciences Building",
},
{
position: { lat: 42.392550, lng: -72.525031 },
title: "Integrated Science Building",
},
{
position: {lat: 42.39211102116256, lng: -72.5238536016437},
title: "Life Sciences Building",
},
{
position: {lat: 42.39157781679017, lng: -72.52577048978628},
title: "Hasbrouck...