Skip to content

Commit 582b38c

Browse files
committed
Addressed comments for imports and element placement
1 parent fb04a6a commit 582b38c

File tree

2 files changed

+48
-61
lines changed

2 files changed

+48
-61
lines changed

samples/ui-kit-place-search-nearby/index.html

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,7 @@
2222

2323
<div class="container">
2424
<!-- map-id is required to use advanced markers. See https://developers.google.com/maps/documentation/javascript/map-ids/mapid-over. -->
25-
<gmp-map
26-
center="-37.813,144.963"
27-
zoom="16"
28-
map-id="DEMO_MAP_ID"
29-
disable-default-ui>
30-
<!--
31-
The gmp-place-details-compact element is styled inline because it is
32-
conditionally rendered and moved into the info window, which is
33-
part of the map's shadow DOM.
34-
-->
35-
<gmp-place-details-compact
36-
orientation="horizontal"
37-
truncation-preferred
38-
style="
39-
width: 400px;
40-
padding: 0;
41-
margin: 0;
42-
border: none;
43-
background-color: transparent;
44-
color-scheme: light;
45-
">
46-
<gmp-place-details-place-request></gmp-place-details-place-request>
47-
<gmp-place-content-config>
48-
<gmp-place-media></gmp-place-media>
49-
<gmp-place-rating></gmp-place-rating>
50-
<gmp-place-price></gmp-place-price>
51-
<gmp-place-accessible-entrance-icon></gmp-place-accessible-entrance-icon>
52-
<gmp-place-open-now-status></gmp-place-open-now-status>
53-
<gmp-place-attribution
54-
light-scheme-color="gray"
55-
dark-scheme-color="white"></gmp-place-attribution>
56-
</gmp-place-content-config>
57-
</gmp-place-details-compact>
25+
<gmp-map center="-37.813,144.963" zoom="16" map-id="DEMO_MAP_ID">
5826
</gmp-map>
5927
<div class="ui-panel">
6028
<div class="controls">
@@ -79,6 +47,35 @@
7947
</div>
8048
</div>
8149

50+
<!--
51+
The gmp-place-details-compact element is styled inline because it is
52+
conditionally rendered and moved into the info window, which is
53+
part of the map's shadow DOM.
54+
-->
55+
<gmp-place-details-compact
56+
orientation="horizontal"
57+
truncation-preferred
58+
style="
59+
width: 400px;
60+
padding: 0;
61+
margin: 0;
62+
border: none;
63+
background-color: transparent;
64+
color-scheme: light;
65+
">
66+
<gmp-place-details-place-request></gmp-place-details-place-request>
67+
<gmp-place-content-config>
68+
<gmp-place-media></gmp-place-media>
69+
<gmp-place-rating></gmp-place-rating>
70+
<gmp-place-price></gmp-place-price>
71+
<gmp-place-accessible-entrance-icon></gmp-place-accessible-entrance-icon>
72+
<gmp-place-open-now-status></gmp-place-open-now-status>
73+
<gmp-place-attribution
74+
light-scheme-color="gray"
75+
dark-scheme-color="white"></gmp-place-attribution>
76+
</gmp-place-content-config>
77+
</gmp-place-details-compact>
78+
8279
<!--[END maps_ui_kit_place_search_nearby_map] -->
8380
</body>
8481
</html>

samples/ui-kit-place-search-nearby/index.ts

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,15 @@ let infoWindow: google.maps.InfoWindow;
2727
// The init function is called when the page loads.
2828
async function init(): Promise<void> {
2929
// Import the necessary libraries from the Google Maps API.
30-
const [{ InfoWindow }, { Place }, markerLib, coreLib] = await Promise.all([
30+
const [{ InfoWindow }, { Place }] = await Promise.all([
3131
google.maps.importLibrary('maps') as Promise<google.maps.MapsLibrary>,
3232
google.maps.importLibrary(
3333
'places'
3434
) as Promise<google.maps.PlacesLibrary>,
35-
google.maps.importLibrary(
36-
'marker'
37-
) as Promise<google.maps.MarkerLibrary>,
38-
google.maps.importLibrary('core') as Promise<google.maps.CoreLibrary>,
3935
]);
4036

41-
const AdvancedMarkerElement = markerLib.AdvancedMarkerElement;
42-
43-
const LatLngBounds = coreLib.LatLngBounds;
44-
4537
// Create a new info window and set its content to the place details element.
38+
placeDetails.remove(); // Hide the place details element because it is not needed until the info window opens
4639
infoWindow = new InfoWindow({
4740
content: placeDetails,
4841
ariaLabel: 'Place Details',
@@ -55,33 +48,26 @@ async function init(): Promise<void> {
5548
streetViewControl: false,
5649
});
5750

58-
// Add a click listener to the map to hide the info window when the map is clicked.
59-
map.innerMap.addListener('click', () => infoWindow.close());
6051
/* [START maps_ui_kit_place_search_nearby_event] */
6152
// Add event listeners to the type select and place search elements.
62-
typeSelect.addEventListener('change', () =>
63-
searchPlaces(AdvancedMarkerElement, LatLngBounds)
64-
);
53+
typeSelect.addEventListener('change', () => searchPlaces());
6554

6655
placeSearch.addEventListener('gmp-select', (event: Event) => {
6756
const { place } = event as any;
6857
markers.get(place.id)?.click();
6958
if (place.location) {
70-
map.innerMap.setCenter(place.location);
59+
map.center = place.location;
7160
}
7261
});
7362
placeSearch.addEventListener('gmp-load', () => {
74-
addMarkers(AdvancedMarkerElement, LatLngBounds);
63+
addMarkers();
7564
});
7665

77-
searchPlaces(AdvancedMarkerElement, LatLngBounds);
66+
searchPlaces();
7867
}
7968
/* [END maps_ui_kit_place_search_nearby_event] */
8069
// The searchPlaces function is called when the user changes the type select or when the page loads.
81-
function searchPlaces(
82-
AdvancedMarkerElement: typeof google.maps.marker.AdvancedMarkerElement,
83-
LatLngBounds: typeof google.maps.LatLngBounds
84-
) {
70+
async function searchPlaces() {
8571
// Close the info window and clear the markers.
8672
infoWindow.close();
8773
for (const marker of markers.values()) {
@@ -91,23 +77,27 @@ function searchPlaces(
9177

9278
// Set the place search query and add an event listener to the place search element.
9379
if (typeSelect.value) {
94-
const center = map.innerMap.getCenter()!;
80+
const center = map.center!;
9581
placeSearchQuery.locationRestriction = {
96-
center: { lat: center.lat(), lng: center.lng() },
82+
center,
9783
radius: 50000, // 50km radius
9884
};
9985
placeSearchQuery.locationBias = {
100-
center: { lat: center.lat(), lng: center.lng() },
86+
center,
10187
};
10288
placeSearchQuery.includedTypes = [typeSelect.value];
10389
}
10490
}
10591

10692
// The addMarkers function is called when the place search element loads.
107-
async function addMarkers(
108-
AdvancedMarkerElement: typeof google.maps.marker.AdvancedMarkerElement,
109-
LatLngBounds: typeof google.maps.LatLngBounds
110-
) {
93+
async function addMarkers() {
94+
// Import the necessary libraries from the Google Maps API.
95+
const [{ AdvancedMarkerElement }, { LatLngBounds }] = await Promise.all([
96+
google.maps.importLibrary(
97+
'marker'
98+
) as Promise<google.maps.MarkerLibrary>,
99+
google.maps.importLibrary('core') as Promise<google.maps.CoreLibrary>,
100+
]);
111101
const bounds = new LatLngBounds();
112102

113103
if (placeSearch.places.length === 0) {

0 commit comments

Comments
 (0)