Skip to content

Commit 02fcce3

Browse files
committed
feat: Migrates Place AC samples.
1 parent 5ce9af9 commit 02fcce3

File tree

17 files changed

+532
-4
lines changed

17 files changed

+532
-4
lines changed

samples/new1.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
# To run this script:
99
# 1. Fill in the NAME, REGION_TAG, TITLE, and API_LOADER below.
1010
# Get these values from the <sample-name>.json for the sample being migrated.
11-
# 2. cd to the root js-api–samples folder on your local computer.
11+
# 2. cd to the js-api–samples/samples folder on your local computer.
1212
# 3. ./new1.sh
1313

1414
# AUTHOR: Update these values!
15-
NAME="add-map" # The name of the folder to create.
16-
REGION_TAG="maps_add_map" # The region tag to use for the JSHTML.
17-
TITLE="Add a Map" # The title of the example.
15+
NAME="map-simple" # The name of the folder to create (for example "map-simple").
16+
REGION_TAG="maps_map_simple" # The region tag to use for the JSHTML (for example "maps_map_simple").
17+
TITLE="Simple map" # The title of the example.
1818
API_LOADER="api_loader_dynamic" # The type of loader to use (api_loader_dynamic or api_loader_default).
1919

2020
# Path to the source folder for the repo archive; substitute with your own path.
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+
28+
`npm run build-all`
29+
30+
## Feedback
31+
32+
For feedback related to this sample, please open a new issue on
33+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright 2019 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_place_autocomplete_element] -->
8+
<html>
9+
<head>
10+
<title>Place Autocomplete element</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+
<p style="font-family: roboto, sans-serif">Search for a place here:</p>
17+
18+
<!-- prettier-ignore -->
19+
<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))})
20+
({key: "AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg", v: "beta"});</script>
21+
</body>
22+
</html>
23+
<!-- [END maps_place_autocomplete_element] -->
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
// [START maps_place_autocomplete_element]
7+
async function initMap() {
8+
// [START maps_place_autocomplete_element_add]
9+
// Request needed libraries.
10+
//@ts-ignore
11+
await google.maps.importLibrary("places");
12+
// Create the input HTML element, and append it.
13+
//@ts-ignore
14+
const placeAutocomplete = new google.maps.places.PlaceAutocompleteElement();
15+
//@ts-ignore
16+
document.body.appendChild(placeAutocomplete);
17+
// [END maps_place_autocomplete_element_add]
18+
// Inject HTML UI.
19+
const selectedPlaceTitle = document.createElement('p');
20+
selectedPlaceTitle.textContent = '';
21+
document.body.appendChild(selectedPlaceTitle);
22+
const selectedPlaceInfo = document.createElement('pre');
23+
selectedPlaceInfo.textContent = '';
24+
document.body.appendChild(selectedPlaceInfo);
25+
// [START maps_place_autocomplete_element_listener]
26+
// Add the gmp-placeselect listener, and display the results.
27+
//@ts-ignore
28+
placeAutocomplete.addEventListener('gmp-placeselect', async ({ place }) => {
29+
await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location'] });
30+
selectedPlaceTitle.textContent = 'Selected Place:';
31+
selectedPlaceInfo.textContent = JSON.stringify(place.toJSON(), /* replacer */ null, /* space */ 2);
32+
});
33+
// [END maps_place_autocomplete_element_listener]
34+
}
35+
initMap();
36+
export {};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_place_autocomplete_element]
8+
async function initMap(): Promise<void> {
9+
// [START maps_place_autocomplete_element_add]
10+
// Request needed libraries.
11+
//@ts-ignore
12+
await google.maps.importLibrary("places") as google.maps.PlacesLibrary;
13+
// Create the input HTML element, and append it.
14+
//@ts-ignore
15+
const placeAutocomplete = new google.maps.places.PlaceAutocompleteElement();
16+
//@ts-ignore
17+
document.body.appendChild(placeAutocomplete);
18+
// [END maps_place_autocomplete_element_add]
19+
20+
// Inject HTML UI.
21+
const selectedPlaceTitle = document.createElement('p');
22+
selectedPlaceTitle.textContent = '';
23+
document.body.appendChild(selectedPlaceTitle);
24+
25+
const selectedPlaceInfo = document.createElement('pre');
26+
selectedPlaceInfo.textContent = '';
27+
document.body.appendChild(selectedPlaceInfo);
28+
29+
// [START maps_place_autocomplete_element_listener]
30+
// Add the gmp-placeselect listener, and display the results.
31+
//@ts-ignore
32+
placeAutocomplete.addEventListener('gmp-placeselect', async ({ place }) => {
33+
await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location'] });
34+
35+
selectedPlaceTitle.textContent = 'Selected Place:';
36+
selectedPlaceInfo.textContent = JSON.stringify(
37+
place.toJSON(), /* replacer */ null, /* space */ 2);
38+
});
39+
// [END maps_place_autocomplete_element_listener]
40+
}
41+
42+
initMap();
43+
// [END maps_place_autocomplete_element]
44+
export { };
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@js-api-samples/place-autocomplete-element",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh place-autocomplete-element && bash ../app.sh place-autocomplete-element && bash ../docs.sh place-autocomplete-element && npm run build:vite --workspace=.",
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+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
{% spaceless %}{% include "maps/documentation/javascript/examples/full/_apikey.html" %}{% endspaceless %}<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
6+
<meta charset="utf-8">
7+
<title>Place Autocomplete element</title>
8+
<style>
9+
{% includecode content_path="maps/documentation/javascript/examples/samples/place-autocomplete-element/style.css" region_tag="maps_place_autocomplete_element" html_escape="False" %}
10+
</style>
11+
</head>
12+
<body>
13+
{% includecode content_path="maps/documentation/javascript/examples/samples/place-autocomplete-element/index.html" region_tag="maps_place_autocomplete_element_body" html_escape="False" %}
14+
{{ api_loader_dynamic }}
15+
<script>
16+
{% includecode content_path="maps/documentation/javascript/examples/samples/place-autocomplete-element/index.js" region_tag="maps_place_autocomplete_element" html_escape="False" %}
17+
</script>
18+
</body>
19+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_place_autocomplete_element] */
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+
25+
p {
26+
font-family: Roboto, sans-serif;
27+
font-weight: bold;
28+
}
29+
30+
/* [END maps_place_autocomplete_element] */
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+
}
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+
28+
`npm run build-all`
29+
30+
## Feedback
31+
32+
For feedback related to this sample, please open a new issue on
33+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).

0 commit comments

Comments
 (0)