@@ -88,6 +88,30 @@ var LitGoogleMap = (function (exports) {
8888 this . mapId = "DEMO_MAP_ID" ;
8989 this . map = null ;
9090 }
91+ attributeChangedCallback ( name , oldValue , newValue ) {
92+ super . attributeChangedCallback ( name , oldValue , newValue ) ;
93+ if ( this . map && oldValue !== newValue && newValue !== null ) {
94+ if ( name === "center-latitude" || name === "center-longitude" ) {
95+ this . map . setCenter ( {
96+ lat : this . centerLatitude ,
97+ lng : this . centerLongitude ,
98+ } ) ;
99+ }
100+ else if ( name === "zoom" ) {
101+ this . map . setZoom ( this . zoom ) ;
102+ }
103+ }
104+ }
105+ dispatchViewChanged ( ) {
106+ this . dispatchEvent ( new CustomEvent ( "view_changed" , {
107+ detail : {
108+ center : this . map . getCenter ( ) . toJSON ( ) ,
109+ zoom : this . map . getZoom ( ) ,
110+ } ,
111+ bubbles : true ,
112+ composed : true ,
113+ } ) ) ;
114+ }
91115 initGMap ( ) {
92116 if ( this . map != null ) {
93117 return ;
@@ -111,6 +135,22 @@ var LitGoogleMap = (function (exports) {
111135 composed : true ,
112136 } ) ) ;
113137 } ) ;
138+ this . map . addListener ( "center_changed" , ( ) => {
139+ this . dispatchEvent ( new CustomEvent ( "center_changed" , {
140+ detail : this . map . getCenter ( ) . toJSON ( ) ,
141+ bubbles : true ,
142+ composed : true ,
143+ } ) ) ;
144+ this . dispatchViewChanged ( ) ;
145+ } ) ;
146+ this . map . addListener ( "zoom_changed" , ( ) => {
147+ this . dispatchEvent ( new CustomEvent ( "zoom_changed" , {
148+ detail : { zoom : this . map . getZoom ( ) } ,
149+ bubbles : true ,
150+ composed : true ,
151+ } ) ) ;
152+ this . dispatchViewChanged ( ) ;
153+ } ) ;
114154 this . map . addListener ( "click" , ( event ) => {
115155 if ( "placeId" in event ) {
116156 event . stop ( ) ;
@@ -140,6 +180,27 @@ var LitGoogleMap = (function (exports) {
140180 super . connectedCallback ( ) ;
141181 this . initGMap ( ) ;
142182 }
183+ updated ( changedProperties ) {
184+ super . updated ( changedProperties ) ;
185+ if ( this . map ) {
186+ if ( changedProperties . has ( "centerLatitude" ) ||
187+ changedProperties . has ( "centerLongitude" ) ) {
188+ changedProperties . get ( "centerLatitude" ) ;
189+ changedProperties . get ( "centerLongitude" ) ;
190+ this . map . setCenter ( {
191+ lat : this . centerLatitude ,
192+ lng : this . centerLongitude ,
193+ } ) ;
194+ }
195+ if ( changedProperties . has ( "zoom" ) ) {
196+ changedProperties . get ( "zoom" ) ;
197+ this . map . setZoom ( this . zoom ) ;
198+ }
199+ }
200+ else {
201+ console . log ( "Map not initialized yet, skipping update" ) ;
202+ }
203+ }
143204 attachChildrenToMap ( children ) {
144205 if ( this . map ) {
145206 for ( const child of children ) {
@@ -197,10 +258,9 @@ var LitGoogleMap = (function (exports) {
197258 }
198259 }
199260 fitToMarkersChanged ( retryAttempt = 0 ) {
200- const markers = this . markers . filter ( ( m ) => ! m . omitFromFit ) ;
201- if ( this . map && this . fitToMarkers && markers . length > 0 ) {
261+ if ( this . map && this . fitToMarkers && this . markers . length > 0 ) {
202262 const latLngBounds = new google . maps . LatLngBounds ( ) ;
203- for ( const marker of markers ) {
263+ for ( const marker of this . markers ) {
204264 latLngBounds . extend ( new google . maps . LatLng ( marker . latitude , marker . longitude ) ) ;
205265 }
206266 const domDimensions = this . getBoundingClientRect ( ) ;
@@ -212,20 +272,18 @@ var LitGoogleMap = (function (exports) {
212272 } , timeout ) ;
213273 return ;
214274 }
215- if ( markers . length > 1 ) {
275+ if ( this . markers . length > 1 ) {
216276 this . map . fitBounds ( latLngBounds , 0 ) ;
217277 }
218278 this . map . setCenter ( latLngBounds . getCenter ( ) ) ;
219279 }
220280 }
221281 checkBoundsChanged ( oldMarkers , newMarkers ) {
222282 const addedInBounds = newMarkers . filter ( ( m ) => {
223- return ( ! m . omitFromFit &&
224- ( ! oldMarkers || ! oldMarkers . includes ( m ) ) ) ;
283+ return ! oldMarkers || ! oldMarkers . includes ( m ) ;
225284 } ) ;
226285 const removedInBounds = oldMarkers === null || oldMarkers === void 0 ? void 0 : oldMarkers . filter ( ( m ) => {
227- return ( ! m . omitFromFit &&
228- ( ! newMarkers || ! newMarkers . includes ( m ) ) ) ;
286+ return ! newMarkers || ! newMarkers . includes ( m ) ;
229287 } ) ;
230288 return addedInBounds . length > 0 || removedInBounds . length > 0 ;
231289 }
@@ -426,7 +484,6 @@ var LitGoogleMap = (function (exports) {
426484 this . background = null ;
427485 this . borderColor = null ;
428486 this . scale = null ;
429- this . omitFromFit = false ;
430487 this . map = null ;
431488 this . marker = null ;
432489 this . pin = null ;
@@ -625,10 +682,6 @@ var LitGoogleMap = (function (exports) {
625682 n ( { type : Number , reflect : true } ) ,
626683 __metadata ( "design:type" , Number )
627684 ] , exports . LitGoogleMapMarker . prototype , "scale" , void 0 ) ;
628- __decorate ( [
629- n ( { type : Boolean , attribute : "omit-from-fit" } ) ,
630- __metadata ( "design:type" , Object )
631- ] , exports . LitGoogleMapMarker . prototype , "omitFromFit" , void 0 ) ;
632685 exports . LitGoogleMapMarker = __decorate ( [
633686 t ( "lit-google-map-marker" )
634687 ] , exports . LitGoogleMapMarker ) ;
0 commit comments