-
Notifications
You must be signed in to change notification settings - Fork 822
/
index.ts
72 lines (61 loc) · 1.87 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* @license
* Copyright 2022 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// [START maps_boundaries_text_search]
let map;
let featureLayer;
let center;
async function initMap() {
const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
center = {lat: 41.059, lng: -124.151}; // Trinidad, CA
map = new Map(document.getElementById('map') as HTMLElement, {
center: center,
zoom: 15,
// In the cloud console, configure this Map ID with a style that enables the
// "Locality" Data Driven Styling type.
mapId: 'a3efe1c035bad51b', // <YOUR_MAP_ID_HERE>,
});
featureLayer = map.getFeatureLayer('LOCALITY');
findBoundary();
}
// [START maps_boundaries_text_search_find_region]
async function findBoundary() {
const request = {
query: 'Trinidad, CA',
fields: ['id', 'location'],
includedType: 'locality',
locationBias: center,
};
const { Place } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary;
//@ts-ignore
const { places } = await Place.searchByText(request);
if (places.length) {
const place = places[0];
styleBoundary(place.id);
map.setCenter(place.location);
} else {
console.log('No results');
}
}
function styleBoundary(placeid) {
// Define a style of transparent purple with opaque stroke.
const styleFill = {
strokeColor: '#810FCB',
strokeOpacity: 1.0,
strokeWeight: 3.0,
fillColor: '#810FCB',
fillOpacity: 0.5
};
// Define the feature style function.
featureLayer.style = (params) => {
if (params.feature.placeId == placeid) {
return styleFill;
}
};
}
// [END maps_boundaries_text_search_find_region]
initMap();
// [END maps_boundaries_text_search]
export { };