Skip to content

Commit b9f9c12

Browse files
authored
feat: Quality and Standards improvements for test-example. (#813)
Change-Id: I80933b91bef6640333657da6588aae03b9bf280e
1 parent 6c00368 commit b9f9c12

File tree

3 files changed

+53
-35
lines changed

3 files changed

+53
-35
lines changed

samples/test-example/index.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@
1111

1212
<link rel="stylesheet" type="text/css" href="./style.css" />
1313
<script type="module" src="./index.js"></script>
14+
15+
<!-- Add the inline bootstrap loader to the document head. -->
16+
<!-- prettier-ignore -->
17+
<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))})
18+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
1419
</head>
1520
<body>
1621
<!--[START maps_test_example_heading]-->
1722
<h3>Maps Test Example</h3>
1823
<!--[END maps_test_example_heading]-->
1924
<!--[START maps_test_example_body]-->
20-
<div id="map"></div>
25+
<!-- Add a gmp-map element to display the map. -->
26+
<gmp-map center="-25.344, 131.031" zoom="4" map-id="DEMO_MAP_ID">
27+
<!-- Nest markers and UI controls inside the gmp-map element. -->
28+
<gmp-advanced-marker></gmp-advanced-marker>
29+
</gmp-map>
2130
<!--[END maps_test_example_body]-->
22-
<!-- prettier-ignore -->
23-
<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))})
24-
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
2531
</body>
2632
</html>
2733
<!--[END maps_test_example]-->

samples/test-example/index.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,46 @@
33
* Copyright 2025 Google LLC. All Rights Reserved.
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6+
/*
7+
* This is a special sample! Having a dedicated test sample makes it easier to
8+
* test changes in a world where sometimes changes must be merged in order to
9+
* test them. This way we can avoid making changes to published content.
10+
*/
11+
612
// TEST COMMENT 007
713
// [START maps_test_example]
8-
// Initialize and add the map.
9-
let map;
14+
// Declare the gmp-map element.
15+
const mapElement = document.querySelector("gmp-map") as google.maps.MapElement;
16+
let innerMap;
17+
const advancedMarkerElement = document.querySelector(
18+
"gmp-advanced-marker"
19+
) as google.maps.marker.AdvancedMarkerElement;
20+
let center;
21+
1022
async function initMap(): Promise<void> {
1123
// [START maps_test_example_instantiate_map]
12-
// The location of Uluru.
13-
const position = {lat: -25.344, lng: 131.031};
14-
1524
// Request the needed libraries.
16-
const {Map} =
17-
await google.maps.importLibrary('maps') as google.maps.MapsLibrary;
18-
const {AdvancedMarkerElement} =
19-
await google.maps.importLibrary('marker') as google.maps.MarkerLibrary;
25+
const { Map } = (await google.maps.importLibrary(
26+
"maps"
27+
)) as google.maps.MapsLibrary;
28+
const { AdvancedMarkerElement } = (await google.maps.importLibrary(
29+
"marker"
30+
)) as google.maps.MarkerLibrary;
2031

21-
// The map, centered at Uluru.
22-
map = new Map(document.getElementById('map') as HTMLElement, {
23-
zoom: 4,
24-
center: position,
25-
mapId: 'DEMO_MAP_ID',
32+
// Get the inner map from the gmp-map element.
33+
innerMap = mapElement.innerMap;
34+
innerMap.setOptions({
35+
mapTypeControl: false,
2636
});
2737
// [END maps_test_example_instantiate_map]
2838

39+
// Get the lat/lng from the inner map.
40+
center = innerMap.getCenter();
41+
2942
// [START maps_test_example_instantiate_marker]
30-
// The marker, positioned at Uluru.
31-
const marker = new AdvancedMarkerElement({map, position, title: 'Uluru'});
32-
// [END maps_test_example_instantiate_marker]
43+
// Add a marker, positioned at Uluru.
44+
const marker = new AdvancedMarkerElement({ map: innerMap, position: center, title: "Uluru" });
45+
// [END maps_test_example_instantiate_marker]
3346
}
3447
initMap();
3548
// [END maps_test_example]

samples/test-example/style.css

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
/* [START maps_test_example] */
7-
/*
7+
/*
88
* Always set the map height explicitly to define the size of the div element
99
* that contains the map.
1010
*/
11-
#map {
12-
height: 100%;
13-
}
14-
15-
/*
11+
gmp-map {
12+
height: 100%;
13+
}
14+
15+
/*
1616
* Optional: Makes the sample page fill the window.
1717
*/
18-
html,
19-
body {
20-
height: 100%;
21-
margin: 0;
22-
padding: 0;
23-
}
24-
/* [END maps_test_example] */
25-
18+
html,
19+
body {
20+
height: 100%;
21+
margin: 0;
22+
padding: 0;
23+
}
24+
/* [END maps_test_example] */

0 commit comments

Comments
 (0)