Skip to content

Commit f86ce65

Browse files
authored
fix: Fixes an edge case and formatting. (#1450)
* fix: Clamps tilt value to prevent error. * Reformat Google Maps API script loading tag * Fix label formatting for tilt control * Simplify tilt change event listener Removing since it's impossible to get a negative value here. * Refactor tilt calculation in updateUI function * Fix label formatting in 3D camera position UI * Refactor property assignment for map3DElement
1 parent 41f5d2c commit f86ce65

2 files changed

Lines changed: 28 additions & 21 deletions

File tree

samples/3d-camera-position/index.html

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
<title>Google Maps 3D - Camera Position Controller</title>
1111
<link rel="stylesheet" type="text/css" href="./style.css" />
1212
<script type="module" src="./index.js"></script>
13-
<!-- prettier-ignore -->
14-
<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)) })
15-
({ key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8"});</script>
13+
<script>
14+
// prettier-ignore
15+
(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"
17+
});
18+
</script>
1619
</head>
1720

1821
<body>
@@ -25,9 +28,9 @@
2528
<div id="ui-container">
2629
<div class="panel">
2730
<div class="control-group">
28-
<label for="heading"
29-
>Heading: <span id="heading-val">0</span>&deg;</label
30-
>
31+
<label for="heading">
32+
Heading: <span id="heading-val">0</span>&deg;
33+
</label>
3134
<input
3235
type="range"
3336
id="heading"
@@ -39,9 +42,9 @@
3942
</div>
4043

4144
<div class="control-group">
42-
<label for="tilt"
43-
>Tilt: <span id="tilt-val">45</span>&deg;</label
44-
>
45+
<label for="tilt">
46+
Tilt: <span id="tilt-val">45</span>&deg;
47+
</label>
4548
<input
4649
type="range"
4750
id="tilt"
@@ -53,9 +56,9 @@
5356
</div>
5457

5558
<div class="control-group">
56-
<label for="range"
57-
>Range: <span id="range-val">1000</span>m</label
58-
>
59+
<label for="range">
60+
Range: <span id="range-val">1000</span>m
61+
</label>
5962
<input
6063
type="range"
6164
id="range"
@@ -92,9 +95,9 @@
9295
</div>
9396

9497
<div class="control-group">
95-
<label for="altitude"
96-
>Altitude: <span id="altitude-val">30</span>m</label
97-
>
98+
<label for="altitude">
99+
Altitude: <span id="altitude-val">30</span>m
100+
</label>
98101
<input
99102
type="range"
100103
id="altitude"
@@ -106,9 +109,9 @@
106109
</div>
107110

108111
<div class="control-group">
109-
<label for="fov"
110-
>FOV: <span id="fov-val">35</span>&deg;</label
111-
>
112+
<label for="fov">
113+
FOV: <span id="fov-val">35</span>&deg;
114+
</label>
112115
<input
113116
type="range"
114117
id="fov"
@@ -120,9 +123,9 @@
120123
</div>
121124

122125
<div class="control-group">
123-
<label for="roll"
124-
>Roll: <span id="roll-val">0</span>&deg;</label
125-
>
126+
<label for="roll">
127+
Roll: <span id="roll-val">0</span>&deg;
128+
</label>
126129
<input
127130
type="range"
128131
id="roll"

samples/3d-camera-position/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ async function initMap(): Promise<void> {
120120
altitude: val,
121121
};
122122
}
123+
} else if (prop === 'tilt') {
124+
map3DElement.tilt = Math.max(0, val);
125+
} else if (prop === 'fov') {
126+
map3DElement.fov = Math.min(80, Math.max(5, val));
123127
} else {
124128
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125129
(map3DElement as any)[prop] = val;

0 commit comments

Comments
 (0)