@@ -12,22 +12,24 @@ const placeDetails = document.querySelector("gmp-place-details") as any;
1212let marker = document . querySelector ( 'gmp-advanced-marker' ) as any ;
1313/* [END maps_ui_kit_place_search_query_selectors] */
1414let markers = { } ;
15- let infowindow ;
15+ let infoWindow ;
1616let mapCenter ;
1717
1818async function initMap ( ) : Promise < void > {
1919 await google . maps . importLibrary ( "places" ) ;
2020 const { InfoWindow } = await google . maps . importLibrary ( "maps" ) as google . maps . MapsLibrary ;
2121 const { spherical } = await google . maps . importLibrary ( "geometry" ) as google . maps . GeometryLibrary ;
2222
23- infowindow = new google . maps . InfoWindow ;
23+ infoWindow = new google . maps . InfoWindow ;
2424
2525 function getContainingCircle ( bounds ) {
2626 const diameter = spherical . computeDistanceBetween (
2727 bounds . getNorthEast ( ) ,
2828 bounds . getSouthWest ( )
2929 ) ;
30- return { center : bounds . getCenter ( ) , radius : diameter / 2 } ;
30+ const calculatedRadius = diameter / 2 ;
31+ const cappedRadius = Math . min ( calculatedRadius , 50000 ) ; // Cap the radius to avoid an error.
32+ return { center : bounds . getCenter ( ) , radius : cappedRadius } ;
3133 }
3234
3335 findCurrentLocation ( ) ;
@@ -41,7 +43,6 @@ async function initMap(): Promise<void> {
4143 typeSelect . addEventListener ( "change" , ( event ) => {
4244 // First remove all existing markers.
4345 for ( marker in markers ) {
44- console . log ( marker ) ;
4546 markers [ marker ] . map = null ;
4647 }
4748 markers = { } ;
@@ -53,7 +54,7 @@ async function initMap(): Promise<void> {
5354 ) ,
5455 includedPrimaryTypes : [ typeSelect . value ] ,
5556 } ) . then ( addMarkers ) ;
56-
57+ // Handle user selection in Place Details.
5758 placeList . addEventListener ( "gmp-placeselect" , ( { place } ) => {
5859 markers [ place . id ] . click ( ) ;
5960 } ) ;
@@ -79,20 +80,20 @@ async function addMarkers(){
7980 bounds . extend ( place . location ) ;
8081
8182 marker . addListener ( 'gmp-click' , ( event ) => {
82- if ( infowindow . isOpen ) {
83- infowindow . close ( ) ;
83+ if ( infoWindow . isOpen ) {
84+ infoWindow . close ( ) ;
8485 }
8586 placeDetails . configureFromPlace ( place ) ;
8687 placeDetails . style . width = "350px" ;
87- infowindow . setOptions ( {
88+ infoWindow . setOptions ( {
8889 content : placeDetails
8990 } ) ;
90- infowindow . open ( {
91+ infoWindow . open ( {
9192 anchor : marker ,
9293 map : map . innerMap
9394 } ) ;
9495 placeDetails . addEventListener ( 'gmp-load' , ( ) => {
95- map . innerMap . fitBounds ( place . viewport , { top : placeDetails . offsetHeight || 206 , left : 200 } ) ;
96+ map . innerMap . fitBounds ( place . viewport , { top : 400 , left : 200 } ) ;
9697 } ) ;
9798
9899 } ) ;
0 commit comments