Skip to content

Commit 56a2374

Browse files
authored
feat: Adds special project just for testing. (#534)
1 parent 900a1ff commit 56a2374

File tree

7 files changed

+169
-0
lines changed

7 files changed

+169
-0
lines changed

samples/test-example/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Google Maps JavaScript Sample
2+
3+
This sample is generated from @googlemaps/js-samples located at
4+
https://github.com/googlemaps-samples/js-api-samples.
5+
6+
## Setup
7+
8+
### Before starting run:
9+
10+
`$npm i`
11+
12+
### Run an example on a local web server
13+
14+
First `cd` to the folder for the sample to run, then:
15+
16+
`$npm start`
17+
18+
### Build an individual example
19+
20+
From `samples/`:
21+
22+
`$npm run build --workspace=sample-name/`
23+
24+
### Build all of the examples.
25+
26+
From `samples/`:
27+
`$npm run build-all`
28+
29+
## Feedback
30+
31+
For feedback related to this sample, please open a new issue on
32+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
33+

samples/test-example/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright 2025 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!--[START maps_test_example]-->
8+
<html>
9+
<head>
10+
<title>Add a Map</title>
11+
12+
<link rel="stylesheet" type="text/css" href="./style.css" />
13+
<script type="module" src="./index.js"></script>
14+
</head>
15+
<body>
16+
<!--[START maps_test_example_heading]-->
17+
<h3>Maps Test Example</h3>
18+
<!--[END maps_test_example_heading]-->
19+
<!--[START maps_test_example_body]-->
20+
<div id="map"></div>
21+
<!--[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>
25+
</body>
26+
</html>
27+
<!--[END maps_test_example]-->

samples/test-example/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_test_example]
8+
// Initialize and add the map.
9+
let map;
10+
async function initMap(): Promise<void> {
11+
// [START maps_test_example_instantiate_map]
12+
// The location of Uluru.
13+
const position = {lat: -25.344, lng: 131.031};
14+
15+
// 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;
20+
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',
26+
});
27+
// [END maps_test_example_instantiate_map]
28+
29+
// [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]
33+
}
34+
initMap();
35+
// [END maps_test_example]

samples/test-example/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@js-api-samples/test-example",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh test-example && bash ../app.sh test-example && bash ../docs.sh test-example && npm run build:vite --workspace=. && bash ../dist.sh test-example",
6+
"test": "tsc && npm run build:vite --workspace=.",
7+
"start": "tsc && vite build --base './' && vite",
8+
"build:vite": "vite build --base './'",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
13+
}
14+
}

samples/test-example/style.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_test_example] */
7+
/*
8+
* Always set the map height explicitly to define the size of the div element
9+
* that contains the map.
10+
*/
11+
#map {
12+
height: 100%;
13+
}
14+
15+
/*
16+
* Optional: Makes the sample page fill the window.
17+
*/
18+
html,
19+
body {
20+
height: 100%;
21+
margin: 0;
22+
padding: 0;
23+
}
24+
/* [END maps_test_example] */
25+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% spaceless %}{% include "maps/documentation/javascript/examples/full/_apikey.html" %}{% endspaceless %}<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
5+
<meta charset="utf-8">
6+
<title>Test Example</title>
7+
<style>
8+
{% includecode content_path="maps/documentation/javascript/examples/collection/test-example/style.css" region_tag="maps_test_example" html_escape="False" %}
9+
</style>
10+
</head>
11+
<body>
12+
{% includecode content_path="maps/documentation/javascript/examples/collection/test-example/index.html" region_tag="maps_test_example_body" html_escape="False" %}
13+
{{ api_loader_dynamic }}
14+
<script>
15+
{% includecode content_path="maps/documentation/javascript/examples/collection/test-example/index.js" region_tag="maps_test_example" html_escape="False" %}
16+
</script>
17+
</body>
18+
</html>

samples/test-example/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"target": "esnext",
5+
"strict": true,
6+
"noImplicitAny": false,
7+
"lib": [
8+
"es2015",
9+
"esnext",
10+
"es6",
11+
"dom",
12+
"dom.iterable"
13+
],
14+
"moduleResolution": "Node",
15+
"jsx": "preserve"
16+
}
17+
}

0 commit comments

Comments
 (0)