Skip to content

Commit 266d2f0

Browse files
Update dist folder [skip ci] (#672)
1 parent a584239 commit 266d2f0

File tree

16 files changed

+346
-81
lines changed

16 files changed

+346
-81
lines changed

‎dist/samples/place-text-search/app/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<script type="module" src="./index.js"></script>
1414
</head>
1515
<body>
16+
<div id="text-input-card">
17+
<input type="text" id="text-input" placeholder="Search for a place"></input>
18+
<input type="button" id="text-input-button" value="Search"></input>
19+
</div>
1620
<div id="map"></div>
1721

1822
<!-- prettier-ignore -->

‎dist/samples/place-text-search/app/index.ts

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,85 @@
66

77
// [START maps_place_text_search]
88
let map;
9-
let center;
9+
let markers = {};
10+
let infoWindow;
1011

1112
async function initMap() {
12-
const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
13+
const { Map, InfoWindow } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
1314

14-
center = { lat: 37.4161493, lng: -122.0812166 };
15+
const center = { lat: 37.4161493, lng: -122.0812166 };
1516
map = new Map(document.getElementById('map') as HTMLElement, {
1617
center: center,
1718
zoom: 11,
19+
mapTypeControl: false,
1820
mapId: 'DEMO_MAP_ID',
1921
});
2022

21-
findPlaces();
23+
const textInput = document.getElementById('text-input') as HTMLInputElement;
24+
const textInputButton = document.getElementById('text-input-button') as HTMLButtonElement;
25+
const card = document.getElementById('text-input-card') as HTMLElement;
26+
map.controls[google.maps.ControlPosition.TOP_LEFT].push(card);
27+
28+
textInputButton.addEventListener('click', () => {
29+
findPlaces(textInput.value);
30+
});
31+
32+
textInput.addEventListener('keydown', (event) => {
33+
if (event.key === 'Enter') {
34+
findPlaces(textInput.value);
35+
}
36+
});
37+
38+
infoWindow = new google.maps.InfoWindow();
2239
}
2340

24-
async function findPlaces() {
41+
async function findPlaces(query) {
2542
const { Place } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary;
2643
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
2744
// [START maps_place_text_search_request]
2845
const request = {
29-
textQuery: 'Tacos in Mountain View',
46+
textQuery: query,
3047
fields: ['displayName', 'location', 'businessStatus'],
31-
includedType: 'restaurant',
32-
locationBias: { lat: 37.4161493, lng: -122.0812166 },
48+
includedType: '', // Restrict query to a specific type (leave blank for any).
49+
useStrictTypeFiltering: true,
50+
locationBias: map.center,
3351
isOpenNow: true,
3452
language: 'en-US',
3553
maxResultCount: 8,
36-
minRating: 3.2,
54+
minRating: 1, // Specify a minimum rating.
3755
region: 'us',
38-
useStrictTypeFiltering: false,
3956
};
4057

41-
//@ts-ignore
4258
const { places } = await Place.searchByText(request);
4359
// [END maps_place_text_search_request]
4460

4561
if (places.length) {
46-
console.log(places);
47-
4862
const { LatLngBounds } = await google.maps.importLibrary("core") as google.maps.CoreLibrary;
4963
const bounds = new LatLngBounds();
64+
65+
// First remove all existing markers.
66+
for (const id in markers) {
67+
markers[id].map = null;
68+
};
69+
markers = {};
5070

5171
// Loop through and get all the results.
52-
places.forEach((place) => {
53-
const markerView = new AdvancedMarkerElement({
72+
places.forEach(place => {
73+
const marker = new AdvancedMarkerElement({
5474
map,
5575
position: place.location,
5676
title: place.displayName,
5777
});
78+
markers[place.id] = marker;
79+
80+
marker.addListener('gmp-click', () => {
81+
map.panTo(place.location);
82+
updateInfoWindow(place.displayName, place.id, marker);
83+
});
5884

59-
bounds.extend(place.location as google.maps.LatLng);
60-
console.log(place);
85+
if (place.location != null) {
86+
bounds.extend(place.location);
87+
}
6188
});
6289

6390
map.fitBounds(bounds);
@@ -67,5 +94,16 @@ async function findPlaces() {
6794
}
6895
}
6996

97+
// Helper function to create an info window.
98+
async function updateInfoWindow(title, content, anchor) {
99+
infoWindow.setContent(content);
100+
infoWindow.setHeaderContent(title);
101+
infoWindow.open({
102+
map,
103+
anchor,
104+
shouldFocus: false,
105+
});
106+
}
107+
70108
initMap();
71109
// [END maps_place_text_search]

‎dist/samples/place-text-search/app/style.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,39 @@ body {
2222
padding: 0;
2323
}
2424

25+
#text-input-card {
26+
width: 25%;
27+
background-color: #fff;
28+
border-radius: 5px;
29+
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
30+
margin: 10px;
31+
padding: 5px;
32+
font-family: Roboto, sans-serif;
33+
font-size: large;
34+
font-weight: bold;
35+
}
36+
37+
#text-input {
38+
width: 100%;
39+
padding: 10px;
40+
margin: 0;
41+
box-sizing: border-box;
42+
}
43+
44+
#text-input-button {
45+
display: inline-block;
46+
margin-top: .5rem;
47+
width: auto;
48+
padding: .6rem .75rem;
49+
font-size: .875rem;
50+
font-weight: 500;
51+
color: #fff;
52+
background-color: #2563eb;
53+
border: none;
54+
border-radius: .375rem;
55+
cursor: pointer;
56+
transition: background-color .15s ease-in-out;
57+
text-align: center
58+
}
59+
2560
/* [END maps_place_text_search] */

‎dist/samples/place-text-search/dist/assets/index-B0L17ZdS.css

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/samples/place-text-search/dist/assets/index-CgrE9OxR.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎dist/samples/place-text-search/dist/assets/index-D3DoV7sY.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/samples/place-text-search/dist/assets/index-kz-ac4rW.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎dist/samples/place-text-search/dist/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
<head>
1010
<title>Text Search</title>
1111

12-
<script type="module" crossorigin src="./assets/index-CgrE9OxR.js"></script>
13-
<link rel="stylesheet" crossorigin href="./assets/index-kz-ac4rW.css">
12+
<script type="module" crossorigin src="./assets/index-D3DoV7sY.js"></script>
13+
<link rel="stylesheet" crossorigin href="./assets/index-B0L17ZdS.css">
1414
</head>
1515
<body>
16+
<div id="text-input-card">
17+
<input type="text" id="text-input" placeholder="Search for a place"></input>
18+
<input type="button" id="text-input-button" value="Search"></input>
19+
</div>
1620
<div id="map"></div>
1721

1822
<!-- prettier-ignore -->

‎dist/samples/place-text-search/docs/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<script type="module" src="./index.js"></script>
1414
</head>
1515
<body>
16+
<div id="text-input-card">
17+
<input type="text" id="text-input" placeholder="Search for a place"></input>
18+
<input type="button" id="text-input-button" value="Search"></input>
19+
</div>
1620
<div id="map"></div>
1721

1822
<!-- prettier-ignore -->

‎dist/samples/place-text-search/docs/index.js

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,89 @@
66
*/
77
// [START maps_place_text_search]
88
let map;
9-
let center;
9+
let markers = {};
10+
let infoWindow;
1011
async function initMap() {
11-
const { Map } = await google.maps.importLibrary("maps");
12-
center = { lat: 37.4161493, lng: -122.0812166 };
12+
const { Map, InfoWindow } = await google.maps.importLibrary("maps");
13+
const center = { lat: 37.4161493, lng: -122.0812166 };
1314
map = new Map(document.getElementById('map'), {
1415
center: center,
1516
zoom: 11,
17+
mapTypeControl: false,
1618
mapId: 'DEMO_MAP_ID',
1719
});
18-
findPlaces();
20+
const textInput = document.getElementById('text-input');
21+
const textInputButton = document.getElementById('text-input-button');
22+
const card = document.getElementById('text-input-card');
23+
map.controls[google.maps.ControlPosition.TOP_LEFT].push(card);
24+
textInputButton.addEventListener('click', () => {
25+
findPlaces(textInput.value);
26+
});
27+
textInput.addEventListener('keydown', (event) => {
28+
if (event.key === 'Enter') {
29+
findPlaces(textInput.value);
30+
}
31+
});
32+
infoWindow = new google.maps.InfoWindow();
1933
}
20-
async function findPlaces() {
34+
async function findPlaces(query) {
2135
const { Place } = await google.maps.importLibrary("places");
2236
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
2337
// [START maps_place_text_search_request]
2438
const request = {
25-
textQuery: 'Tacos in Mountain View',
39+
textQuery: query,
2640
fields: ['displayName', 'location', 'businessStatus'],
27-
includedType: 'restaurant',
28-
locationBias: { lat: 37.4161493, lng: -122.0812166 },
41+
includedType: '', // Restrict query to a specific type (leave blank for any).
42+
useStrictTypeFiltering: true,
43+
locationBias: map.center,
2944
isOpenNow: true,
3045
language: 'en-US',
3146
maxResultCount: 8,
32-
minRating: 3.2,
47+
minRating: 1, // Specify a minimum rating.
3348
region: 'us',
34-
useStrictTypeFiltering: false,
3549
};
36-
//@ts-ignore
3750
const { places } = await Place.searchByText(request);
3851
// [END maps_place_text_search_request]
3952
if (places.length) {
40-
console.log(places);
4153
const { LatLngBounds } = await google.maps.importLibrary("core");
4254
const bounds = new LatLngBounds();
55+
// First remove all existing markers.
56+
for (const id in markers) {
57+
markers[id].map = null;
58+
}
59+
;
60+
markers = {};
4361
// Loop through and get all the results.
44-
places.forEach((place) => {
45-
const markerView = new AdvancedMarkerElement({
62+
places.forEach(place => {
63+
const marker = new AdvancedMarkerElement({
4664
map,
4765
position: place.location,
4866
title: place.displayName,
4967
});
50-
bounds.extend(place.location);
51-
console.log(place);
68+
markers[place.id] = marker;
69+
marker.addListener('gmp-click', () => {
70+
map.panTo(place.location);
71+
updateInfoWindow(place.displayName, place.id, marker);
72+
});
73+
if (place.location != null) {
74+
bounds.extend(place.location);
75+
}
5276
});
5377
map.fitBounds(bounds);
5478
}
5579
else {
5680
console.log('No results');
5781
}
5882
}
83+
// Helper function to create an info window.
84+
async function updateInfoWindow(title, content, anchor) {
85+
infoWindow.setContent(content);
86+
infoWindow.setHeaderContent(title);
87+
infoWindow.open({
88+
map,
89+
anchor,
90+
shouldFocus: false,
91+
});
92+
}
5993
initMap();
6094
// [END maps_place_text_search]

0 commit comments

Comments
 (0)