Skip to content

Commit 8c7621d

Browse files
committed
enforce maps js async
1 parent 3cfdecc commit 8c7621d

15 files changed

Lines changed: 58 additions & 35 deletions

File tree

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
index.html
1+
/index.html
22
package.json
33
package-lock.json
44
dist

samples/3d-map-roadmap/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<script type="module" src="./index.js"></script>
1414
<!-- prettier-ignore -->
1515
<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)) })
16-
({ key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "alpha" });</script>
16+
({ key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "alpha" });
17+
</script>
1718
</head>
1819

1920
<body></body>

samples/3d-marker-html/index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<head>
1010
<title>3D Marker HTML</title>
1111
<link rel="stylesheet" type="text/css" href="./style.css" />
12+
<script
13+
async
14+
src="https://maps.googleapis.com/maps/api/js?loading=async&key=AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8&libraries=maps3d&internal_usage_attribution_ids=gmp_git_jsapisamples_v1_3d-markers"></script>
1215
</head>
1316
<body>
1417
<gmp-map-3d
@@ -23,10 +26,6 @@
2326
</div>
2427
</gmp-marker>
2528
</gmp-map-3d>
26-
27-
<script
28-
async
29-
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8&libraries=maps3d&internal_usage_attribution_ids=gmp_git_jsapisamples_v1_3d-markers"></script>
3029
</body>
3130
</html>
3231
<!-- [END maps_3d_marker_html] -->

samples/3d-simple-map-declarative/index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
<head>
1010
<title>Map</title>
1111
<link rel="stylesheet" type="text/css" href="./style.css" />
12+
<script
13+
async
14+
src="https://maps.googleapis.com/maps/api/js?loading=async&key=AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8&libraries=maps3d&internal_usage_attribution_ids=gmp_git_jsapisamples_v1_3d-rendering"></script>
1215
</head>
1316
<body>
1417
<gmp-map-3d
1518
center="37.7704,-122.3985,500"
1619
tilt="67.5"
1720
mode="hybrid"></gmp-map-3d>
18-
19-
<script
20-
async
21-
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8&libraries=maps3d&internal_usage_attribution_ids=gmp_git_jsapisamples_v1_3d-rendering"></script>
2221
</body>
2322
</html>
2423
<!-- [END maps_3d_simple_map_declarative] -->

samples/build-single.sh

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,57 @@ NAME=$(basename $PWD)
88
npx prettier --check --ignore-path ../../.prettierignore .
99
npx eslint
1010

11+
set +e
12+
grep weekly -r --include=*.{html,js,ts,css,jsx,tsx} --exclude-dir=dist
13+
if [[ $? -eq 0 ]]; then
14+
# sure, it could be other things, but so far it's not, so we'll keep it simple for now
15+
echo "Found 'weekly'. Please remove (it's the default channel)."
16+
exit 1
17+
fi
18+
grep callback -r --include=*.{html,js,ts,css,jsx,tsx} --exclude-dir=dist --no-filename | grep -v -E "^\s*//" | grep -v importLibrary # callback & importLibrary both show up the in the inline loader
19+
if [[ $? -eq 0 ]]; then
20+
# sure, it could be other things, but so far it's not, so we'll keep it simple for now
21+
echo "Found 'callback'. Please replace with a more modern pattern for loading Maps JS."
22+
exit 1
23+
fi
24+
grep 'src="https://maps' -r --include=*.html
25+
if [[ $? -eq 0 ]]; then
26+
grep 'src="https://maps' -r --include=*.html | grep "loading=async"
27+
if [[ $? -ne 0 ]]; then
28+
echo "Missing loading=async in direct script loader."
29+
exit 1
30+
fi
31+
grep -B 1 'src="https://maps' -r --include=*.html | grep " async"
32+
if [[ $? -ne 0 ]]; then
33+
echo "Missing async attribute on direct script loader (expected on line before)."
34+
exit 1
35+
fi
36+
grep -B 2 -A 2 'src="https://maps' -r --include=*.html | grep " defer"
37+
if [[ $? -eq 0 ]]; then
38+
echo "Found defer attribute on direct script loader (use async instead)."
39+
exit 1
40+
fi
41+
fi
42+
set -e
43+
1144
# clean comments for empty lines, and then clean up, to preserve newlines
1245
sed -i.sed-back 's#^$#// TMP EMPTY LINE#g' *.ts && rm *.sed-back
1346
set +e
1447
npx tsc
1548
status=$?
49+
set -e
1650
sed -i.sed-back 's#// TMP EMPTY LINE##g' *.ts *.js && rm *.sed-back
1751
if [[ $status -ne 0 ]]; then
1852
echo "TS build failure!"
1953
exit $status
2054
fi
2155

22-
npx prettier -w index.js --ignore-path /dev/null
56+
if [[ -f index.js ]]; then # DNE for react builds
57+
npx prettier -w index.js --ignore-path /dev/null
58+
fi
2359

2460
set +e
25-
grep "google\.maps\." index.js | grep -v "google.maps.importLibrary" | grep -v -E "^\s+//"
61+
grep "google\.maps\." index.js | grep -v "google.maps.importLibrary" | grep -v -E "^\s*//"
2662
if [[ $? -eq 0 ]]; then
2763
echo "Using google.maps namespace for something other than google.maps.importLibrary()!"
2864
exit 1

samples/js-api-loader-map/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ async function initMap(): Promise<void> {
1717
// Set loader options.
1818
setOptions({
1919
key: API_KEY,
20-
v: 'weekly',
2120
});
2221
// [END maps_js_api_loader_map_options]
2322

samples/layer-data-quakes-red/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ async function initMap() {
4141
}
4242

4343
// Defines the callback function referenced in the jsonp file.
44-
function eqfeed_callback(data: any) {
44+
function earthquakeDataLoad(data: any) {
4545
innerMap.data.addGeoJson(data);
4646
}
4747

48-
window.eqfeed_callback = eqfeed_callback;
48+
window.earthquakeDataLoad = earthquakeDataLoad;
4949
initMap();
5050
// [END maps_layer_data_quakes_red]

samples/layer-data-quakes-red/public/quakes.geo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
eqfeed_callback({
1+
earthquakeDataLoad({
22
type: 'FeatureCollection',
33
metadata: {
44
generated: 1395197681000,

samples/layer-data-quakes-simple/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ async function initMap() {
2626
}
2727

2828
// Defines the callback function referenced in the jsonp file.
29-
function eqfeed_callback(data: any) {
29+
function earthquakeDataLoad(data: any) {
3030
innerMap.data.addGeoJson(data);
3131
}
3232

33-
window.eqfeed_callback = eqfeed_callback;
33+
window.earthquakeDataLoad = earthquakeDataLoad;
3434
initMap();
3535
// [END maps_layer_data_quakes_simple]

samples/layer-data-quakes-simple/public/quakes.geo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
eqfeed_callback({
1+
earthquakeDataLoad({
22
type: 'FeatureCollection',
33
metadata: {
44
generated: 1395197681000,

0 commit comments

Comments
 (0)