diff --git a/README.md b/README.md
index 84634a2..5da2f6d 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ This project is a fork of [lit-google-map](https://github.com/arkadiuszwojcik/li
- add marker `mouseover` and `mouseout` events
- fix marker `icon` attribute not being updateable live
- update dependencies and keep current with Dependabot
-- add `omit-from-fit` to markers. This lets you add more markers to display on the map that won't affect the sizing of the bounds box
+- add `zoom_changed`, `center_changed`, and `view_changed` events
- move to [AdvancedMarkerElement](https://developers.google.com/maps/documentation/javascript/advanced-markers/migration)
## Table of contents
@@ -109,6 +109,9 @@ Example:
- '_bounds_changed_' - Custom Event with `detail` attribute containing `north`, `south`, `east`, and `west` attributes
- '_tilesloaded_' - Custom Event containing the same data as `bounds_changed`
+- '_center_changed_' - Custom Event with `detail` attribute containing `lat` and `lng` attributes
+- '_zoom_changed_' - Custom Event with `detail` attribute containing `zoom` attribute
+- '_view_changed_' - Custom Event with `detail` attribute containing `center` (with `lat` and `lng`) and `zoom` attributes. Fires whenever either center or zoom changes
- '_place_click_' - Custom Event containing `detail` attribute containing `placeId` attribute
## Marker events
@@ -121,7 +124,6 @@ Example:
- '_latitude_' - Marker latitude position
- '_longitude_' - Marker longitude position
-- '_omit-from-fit_' - Don't include marker when fitting map bounds to markers
- '_z-index_' - Marker z index
- '_id_' - Use with Marker events to identify the source
- '_glyph_' - Glyph in center of pin
diff --git a/dist/lit-google-map.bundle.js b/dist/lit-google-map.bundle.js
index 3e35dff..e671e52 100644
--- a/dist/lit-google-map.bundle.js
+++ b/dist/lit-google-map.bundle.js
@@ -88,6 +88,30 @@ var LitGoogleMap = (function (exports) {
this.mapId = "DEMO_MAP_ID";
this.map = null;
}
+ attributeChangedCallback(name, oldValue, newValue) {
+ super.attributeChangedCallback(name, oldValue, newValue);
+ if (this.map && oldValue !== newValue && newValue !== null) {
+ if (name === "center-latitude" || name === "center-longitude") {
+ this.map.setCenter({
+ lat: this.centerLatitude,
+ lng: this.centerLongitude,
+ });
+ }
+ else if (name === "zoom") {
+ this.map.setZoom(this.zoom);
+ }
+ }
+ }
+ dispatchViewChanged() {
+ this.dispatchEvent(new CustomEvent("view_changed", {
+ detail: {
+ center: this.map.getCenter().toJSON(),
+ zoom: this.map.getZoom(),
+ },
+ bubbles: true,
+ composed: true,
+ }));
+ }
initGMap() {
if (this.map != null) {
return;
@@ -111,6 +135,22 @@ var LitGoogleMap = (function (exports) {
composed: true,
}));
});
+ this.map.addListener("center_changed", () => {
+ this.dispatchEvent(new CustomEvent("center_changed", {
+ detail: this.map.getCenter().toJSON(),
+ bubbles: true,
+ composed: true,
+ }));
+ this.dispatchViewChanged();
+ });
+ this.map.addListener("zoom_changed", () => {
+ this.dispatchEvent(new CustomEvent("zoom_changed", {
+ detail: { zoom: this.map.getZoom() },
+ bubbles: true,
+ composed: true,
+ }));
+ this.dispatchViewChanged();
+ });
this.map.addListener("click", (event) => {
if ("placeId" in event) {
event.stop();
@@ -140,6 +180,27 @@ var LitGoogleMap = (function (exports) {
super.connectedCallback();
this.initGMap();
}
+ updated(changedProperties) {
+ super.updated(changedProperties);
+ if (this.map) {
+ if (changedProperties.has("centerLatitude") ||
+ changedProperties.has("centerLongitude")) {
+ changedProperties.get("centerLatitude");
+ changedProperties.get("centerLongitude");
+ this.map.setCenter({
+ lat: this.centerLatitude,
+ lng: this.centerLongitude,
+ });
+ }
+ if (changedProperties.has("zoom")) {
+ changedProperties.get("zoom");
+ this.map.setZoom(this.zoom);
+ }
+ }
+ else {
+ console.log("Map not initialized yet, skipping update");
+ }
+ }
attachChildrenToMap(children) {
if (this.map) {
for (const child of children) {
@@ -197,10 +258,9 @@ var LitGoogleMap = (function (exports) {
}
}
fitToMarkersChanged(retryAttempt = 0) {
- const markers = this.markers.filter((m) => !m.omitFromFit);
- if (this.map && this.fitToMarkers && markers.length > 0) {
+ if (this.map && this.fitToMarkers && this.markers.length > 0) {
const latLngBounds = new google.maps.LatLngBounds();
- for (const marker of markers) {
+ for (const marker of this.markers) {
latLngBounds.extend(new google.maps.LatLng(marker.latitude, marker.longitude));
}
const domDimensions = this.getBoundingClientRect();
@@ -212,7 +272,7 @@ var LitGoogleMap = (function (exports) {
}, timeout);
return;
}
- if (markers.length > 1) {
+ if (this.markers.length > 1) {
this.map.fitBounds(latLngBounds, 0);
}
this.map.setCenter(latLngBounds.getCenter());
@@ -220,12 +280,10 @@ var LitGoogleMap = (function (exports) {
}
checkBoundsChanged(oldMarkers, newMarkers) {
const addedInBounds = newMarkers.filter((m) => {
- return (!m.omitFromFit &&
- (!oldMarkers || !oldMarkers.includes(m)));
+ return !oldMarkers || !oldMarkers.includes(m);
});
const removedInBounds = oldMarkers === null || oldMarkers === void 0 ? void 0 : oldMarkers.filter((m) => {
- return (!m.omitFromFit &&
- (!newMarkers || !newMarkers.includes(m)));
+ return !newMarkers || !newMarkers.includes(m);
});
return addedInBounds.length > 0 || removedInBounds.length > 0;
}
@@ -426,7 +484,6 @@ var LitGoogleMap = (function (exports) {
this.background = null;
this.borderColor = null;
this.scale = null;
- this.omitFromFit = false;
this.map = null;
this.marker = null;
this.pin = null;
@@ -625,10 +682,6 @@ var LitGoogleMap = (function (exports) {
n({ type: Number, reflect: true }),
__metadata("design:type", Number)
], exports.LitGoogleMapMarker.prototype, "scale", void 0);
- __decorate([
- n({ type: Boolean, attribute: "omit-from-fit" }),
- __metadata("design:type", Object)
- ], exports.LitGoogleMapMarker.prototype, "omitFromFit", void 0);
exports.LitGoogleMapMarker = __decorate([
t("lit-google-map-marker")
], exports.LitGoogleMapMarker);
diff --git a/dist/lit-google-map.bundle.min.js b/dist/lit-google-map.bundle.min.js
index fa9df5b..d86a060 100644
--- a/dist/lit-google-map.bundle.min.js
+++ b/dist/lit-google-map.bundle.min.js
@@ -15,12 +15,12 @@ const s=globalThis,o=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
-const A=globalThis,M=A.trustedTypes,S=M?M.createPolicy("lit-html",{createHTML:t=>t}):void 0,E="$lit$",L=`lit$${Math.random().toFixed(9).slice(2)}$`,O="?"+L,w=`<${O}>`,P=document,x=()=>P.createComment(""),N=t=>null===t||"object"!=typeof t&&"function"!=typeof t,I=Array.isArray,G="[ \t\n\f\r]",j=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,T=/-->/g,U=/>/g,R=RegExp(`>|${G}(?:([^\\s"'>=/]+)(${G}*=${G}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),H=/'/g,z=/"/g,B=/^(?:script|style|textarea|title)$/i,F=(t=>(e,...i)=>({_$litType$:t,strings:e,values:i}))(1),D=Symbol.for("lit-noChange"),W=Symbol.for("lit-nothing"),q=new WeakMap,K=P.createTreeWalker(P,129);function V(t,e){if(!I(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==S?S.createHTML(e):e}const J=(t,e)=>{const i=t.length-1,s=[];let o,r=2===e?"":3===e?"":"")),s]};class Z{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let o=0,r=0;const n=t.length-1,a=this.parts,[l,h]=J(t,e);if(this.el=Z.createElement(l,i),K.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(s=K.nextNode())&&a.length0){s.textContent=M?M.emptyScript:"";for(let i=0;iI(t)||"function"==typeof t?.[Symbol.iterator])(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==W&&N(this._$AH)?this._$AA.nextSibling.data=t:this.T(P.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:i}=t,s="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=Z.createElement(V(i.h,i.h[0]),this.options)),i);if(this._$AH?._$AD===s)this._$AH.p(e);else{const t=new X(s,this),i=t.u(this.options);t.p(e),this.T(i),this._$AH=t}}_$AC(t){let e=q.get(t.strings);return void 0===e&&q.set(t.strings,e=new Z(t)),e}k(t){I(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const o of t)s===e.length?e.push(i=new Y(this.O(x()),this.O(x()),this,this.options)):i=e[s],i._$AI(o),s++;s2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=W}_$AI(t,e=this,i,s){const o=this.strings;let r=!1;if(void 0===o)t=Q(this,t,e,0),r=!N(t)||t!==this._$AH&&t!==D,r&&(this._$AH=t);else{const s=t;let n,a;for(t=o[0],n=0;nt}):void 0,L="$lit$",S=`lit$${Math.random().toFixed(9).slice(2)}$`,O="?"+S,w=`<${O}>`,P=document,x=()=>P.createComment(""),N=t=>null===t||"object"!=typeof t&&"function"!=typeof t,I=Array.isArray,G="[ \t\n\f\r]",j=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,T=/-->/g,U=/>/g,R=RegExp(`>|${G}(?:([^\\s"'>=/]+)(${G}*=${G}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),H=/'/g,z=/"/g,B=/^(?:script|style|textarea|title)$/i,D=(t=>(e,...i)=>({_$litType$:t,strings:e,values:i}))(1),W=Symbol.for("lit-noChange"),q=Symbol.for("lit-nothing"),F=new WeakMap,V=P.createTreeWalker(P,129);function K(t,e){if(!I(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==E?E.createHTML(e):e}const J=(t,e)=>{const i=t.length-1,s=[];let o,r=2===e?"":3===e?"":"")),s]};class Z{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let o=0,r=0;const n=t.length-1,a=this.parts,[l,h]=J(t,e);if(this.el=Z.createElement(l,i),V.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(s=V.nextNode())&&a.length0){s.textContent=M?M.emptyScript:"";for(let i=0;iI(t)||"function"==typeof t?.[Symbol.iterator])(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==q&&N(this._$AH)?this._$AA.nextSibling.data=t:this.T(P.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:i}=t,s="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=Z.createElement(K(i.h,i.h[0]),this.options)),i);if(this._$AH?._$AD===s)this._$AH.p(e);else{const t=new X(s,this),i=t.u(this.options);t.p(e),this.T(i),this._$AH=t}}_$AC(t){let e=F.get(t.strings);return void 0===e&&F.set(t.strings,e=new Z(t)),e}k(t){I(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const o of t)s===e.length?e.push(i=new Y(this.O(x()),this.O(x()),this,this.options)):i=e[s],i._$AI(o),s++;s2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=q}_$AI(t,e=this,i,s){const o=this.strings;let r=!1;if(void 0===o)t=Q(this,t,e,0),r=!N(t)||t!==this._$AH&&t!==W,r&&(this._$AH=t);else{const s=t;let n,a;for(t=o[0],n=0;n{const s=i?.renderBefore??e;let o=s._$litPart$;if(void 0===o){const t=i?.renderBefore??null;s._$litPart$=o=new Y(e.insertBefore(x(),t),t,void 0,i??{})}return o._$AI(t),o})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return D}}at._$litElement$=!0,at.finalized=!0,nt.litElementHydrateSupport?.({LitElement:at});const lt=nt.litElementPolyfillSupport;lt?.({LitElement:at}),(nt.litElementVersions??=[]).push("4.2.0");
+ */class at extends C{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=((t,e,i)=>{const s=i?.renderBefore??e;let o=s._$litPart$;if(void 0===o){const t=i?.renderBefore??null;s._$litPart$=o=new Y(e.insertBefore(x(),t),t,void 0,i??{})}return o._$AI(t),o})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return W}}at._$litElement$=!0,at.finalized=!0,nt.litElementHydrateSupport?.({LitElement:at});const lt=nt.litElementPolyfillSupport;lt?.({LitElement:at}),(nt.litElementVersions??=[]).push("4.2.0");
/**
* @license
* Copyright 2017 Google LLC
@@ -31,7 +31,7 @@ const ht=t=>(e,i)=>{void 0!==i?i.addInitializer((()=>{customElements.define(t,e)
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
- */,pt={attribute:!0,type:String,converter:$,reflect:!1,hasChanged:_},ct=(t=pt,e,i)=>{const{kind:s,metadata:o}=i;let r=globalThis.litPropertyMetadata.get(o);if(void 0===r&&globalThis.litPropertyMetadata.set(o,r=new Map),"setter"===s&&((t=Object.create(t)).wrapped=!0),r.set(i.name,t),"accessor"===s){const{name:s}=i;return{set(i){const o=e.get.call(this);e.set.call(this,i),this.requestUpdate(s,o,t)},init(e){return void 0!==e&&this.C(s,void 0,t,e),e}}}if("setter"===s){const{name:s}=i;return function(i){const o=this[s];e.call(this,i),this.requestUpdate(s,o,t)}}throw Error("Unsupported decorator location: "+s)};function dt(t){return(e,i)=>"object"==typeof i?ct(t,e,i):((t,e,i)=>{const s=e.hasOwnProperty(i);return e.constructor.createProperty(i,t),s?Object.getOwnPropertyDescriptor(e,i):void 0})(t,e,i)}t.LitGoogleMap=class extends at{constructor(){super(...arguments),this.apiKey="",this.version="3.48",this.styles={},this.zoom=8,this.fitToMarkers=!1,this.mapType="roadmap",this.centerLatitude=-34.397,this.centerLongitude=150.644,this.language="",this.mapId="DEMO_MAP_ID",this.map=null}initGMap(){if(null!=this.map)return;const t=this.shadowRoot.getElementById("api");null!=t&&!0===t.libraryLoaded&&(this.map=new google.maps.Map(this.shadowRoot.getElementById("map"),this.getMapOptions()),this.map.addListener("bounds_changed",(()=>{this.dispatchEvent(new CustomEvent("bounds_changed",{detail:this.map.getBounds().toJSON(),bubbles:!0,composed:!0}))})),this.map.addListener("tilesloaded",(()=>{this.dispatchEvent(new CustomEvent("tilesloaded",{detail:this.map.getBounds().toJSON(),bubbles:!0,composed:!0}))})),this.map.addListener("click",(t=>{"placeId"in t&&(t.stop(),this.dispatchEvent(new CustomEvent("place_click",{detail:{placeId:t.placeId},bubbles:!0,composed:!0})))})),this.updateMarkers(),this.updateShapes())}getMapOptions(){return{zoom:this.zoom,center:{lat:this.centerLatitude,lng:this.centerLongitude},mapTypeId:this.mapType,styles:this.styles,mapId:this.mapId}}mapApiLoaded(){this.initGMap()}connectedCallback(){super.connectedCallback(),this.initGMap()}attachChildrenToMap(t){if(this.map)for(const e of t)e.changeMap(this.map)}detachChildrenFromMap(t){if(this.map)for(const e of t)e.changeMap(null)}observeMarkers(){this.markerObserverSet||(this.addEventListener("selector-items-changed",(()=>{this.updateMarkers()})),this.markerObserverSet=!0)}updateMarkers(){var t;this.observeMarkers();const e=this.shadowRoot.getElementById("markers-selector");if(!e)return;const i=e.items;if(this.markers&&i.length===this.markers.length){const t=i.filter((t=>this.markers&&-1===this.markers.indexOf(t)));if(0===t.length)return}const s=this.checkBoundsChanged(this.markers,i),o=(null===(t=this.markers)||void 0===t?void 0:t.filter((t=>-1===i.indexOf(t))))||[];this.detachChildrenFromMap(o),this.markers=i,this.attachChildrenToMap(this.markers),this.fitToMarkers&&s&&this.fitToMarkersChanged()}updateShapes(){const t=this.shadowRoot.getElementById("shapes-selector");if(t){this.shapes=t.items;for(const t of this.shapes)t.attachToMap(this.map)}}fitToMarkersChanged(t=0){const e=this.markers.filter((t=>!t.omitFromFit));if(this.map&&this.fitToMarkers&&e.length>0){const i=new google.maps.LatLngBounds;for(const t of e)i.extend(new google.maps.LatLng(t.latitude,t.longitude));const s=this.getBoundingClientRect();if(0===s.width||0===s.height){console.log("Invalid DOM width or height for lit-google-map");return void setTimeout((()=>{this.fitToMarkersChanged(t+1)}),2**t*100)}e.length>1&&this.map.fitBounds(i,0),this.map.setCenter(i.getCenter())}}checkBoundsChanged(t,e){const i=e.filter((e=>!(e.omitFromFit||t&&t.includes(e)))),s=null==t?void 0:t.filter((t=>!(t.omitFromFit||e&&e.includes(t))));return i.length>0||s.length>0}deselectMarker(t){}deselectShape(t){}render(){return F`
+ */,pt={attribute:!0,type:String,converter:$,reflect:!1,hasChanged:_},ct=(t=pt,e,i)=>{const{kind:s,metadata:o}=i;let r=globalThis.litPropertyMetadata.get(o);if(void 0===r&&globalThis.litPropertyMetadata.set(o,r=new Map),"setter"===s&&((t=Object.create(t)).wrapped=!0),r.set(i.name,t),"accessor"===s){const{name:s}=i;return{set(i){const o=e.get.call(this);e.set.call(this,i),this.requestUpdate(s,o,t)},init(e){return void 0!==e&&this.C(s,void 0,t,e),e}}}if("setter"===s){const{name:s}=i;return function(i){const o=this[s];e.call(this,i),this.requestUpdate(s,o,t)}}throw Error("Unsupported decorator location: "+s)};function dt(t){return(e,i)=>"object"==typeof i?ct(t,e,i):((t,e,i)=>{const s=e.hasOwnProperty(i);return e.constructor.createProperty(i,t),s?Object.getOwnPropertyDescriptor(e,i):void 0})(t,e,i)}t.LitGoogleMap=class extends at{constructor(){super(...arguments),this.apiKey="",this.version="3.48",this.styles={},this.zoom=8,this.fitToMarkers=!1,this.mapType="roadmap",this.centerLatitude=-34.397,this.centerLongitude=150.644,this.language="",this.mapId="DEMO_MAP_ID",this.map=null}attributeChangedCallback(t,e,i){super.attributeChangedCallback(t,e,i),this.map&&e!==i&&null!==i&&("center-latitude"===t||"center-longitude"===t?this.map.setCenter({lat:this.centerLatitude,lng:this.centerLongitude}):"zoom"===t&&this.map.setZoom(this.zoom))}dispatchViewChanged(){this.dispatchEvent(new CustomEvent("view_changed",{detail:{center:this.map.getCenter().toJSON(),zoom:this.map.getZoom()},bubbles:!0,composed:!0}))}initGMap(){if(null!=this.map)return;const t=this.shadowRoot.getElementById("api");null!=t&&!0===t.libraryLoaded&&(this.map=new google.maps.Map(this.shadowRoot.getElementById("map"),this.getMapOptions()),this.map.addListener("bounds_changed",(()=>{this.dispatchEvent(new CustomEvent("bounds_changed",{detail:this.map.getBounds().toJSON(),bubbles:!0,composed:!0}))})),this.map.addListener("tilesloaded",(()=>{this.dispatchEvent(new CustomEvent("tilesloaded",{detail:this.map.getBounds().toJSON(),bubbles:!0,composed:!0}))})),this.map.addListener("center_changed",(()=>{this.dispatchEvent(new CustomEvent("center_changed",{detail:this.map.getCenter().toJSON(),bubbles:!0,composed:!0})),this.dispatchViewChanged()})),this.map.addListener("zoom_changed",(()=>{this.dispatchEvent(new CustomEvent("zoom_changed",{detail:{zoom:this.map.getZoom()},bubbles:!0,composed:!0})),this.dispatchViewChanged()})),this.map.addListener("click",(t=>{"placeId"in t&&(t.stop(),this.dispatchEvent(new CustomEvent("place_click",{detail:{placeId:t.placeId},bubbles:!0,composed:!0})))})),this.updateMarkers(),this.updateShapes())}getMapOptions(){return{zoom:this.zoom,center:{lat:this.centerLatitude,lng:this.centerLongitude},mapTypeId:this.mapType,styles:this.styles,mapId:this.mapId}}mapApiLoaded(){this.initGMap()}connectedCallback(){super.connectedCallback(),this.initGMap()}updated(t){super.updated(t),this.map?((t.has("centerLatitude")||t.has("centerLongitude"))&&(t.get("centerLatitude"),t.get("centerLongitude"),this.map.setCenter({lat:this.centerLatitude,lng:this.centerLongitude})),t.has("zoom")&&(t.get("zoom"),this.map.setZoom(this.zoom))):console.log("Map not initialized yet, skipping update")}attachChildrenToMap(t){if(this.map)for(const e of t)e.changeMap(this.map)}detachChildrenFromMap(t){if(this.map)for(const e of t)e.changeMap(null)}observeMarkers(){this.markerObserverSet||(this.addEventListener("selector-items-changed",(()=>{this.updateMarkers()})),this.markerObserverSet=!0)}updateMarkers(){var t;this.observeMarkers();const e=this.shadowRoot.getElementById("markers-selector");if(!e)return;const i=e.items;if(this.markers&&i.length===this.markers.length){const t=i.filter((t=>this.markers&&-1===this.markers.indexOf(t)));if(0===t.length)return}const s=this.checkBoundsChanged(this.markers,i),o=(null===(t=this.markers)||void 0===t?void 0:t.filter((t=>-1===i.indexOf(t))))||[];this.detachChildrenFromMap(o),this.markers=i,this.attachChildrenToMap(this.markers),this.fitToMarkers&&s&&this.fitToMarkersChanged()}updateShapes(){const t=this.shadowRoot.getElementById("shapes-selector");if(t){this.shapes=t.items;for(const t of this.shapes)t.attachToMap(this.map)}}fitToMarkersChanged(t=0){if(this.map&&this.fitToMarkers&&this.markers.length>0){const e=new google.maps.LatLngBounds;for(const t of this.markers)e.extend(new google.maps.LatLng(t.latitude,t.longitude));const i=this.getBoundingClientRect();if(0===i.width||0===i.height){console.log("Invalid DOM width or height for lit-google-map");return void setTimeout((()=>{this.fitToMarkersChanged(t+1)}),2**t*100)}this.markers.length>1&&this.map.fitBounds(e,0),this.map.setCenter(e.getCenter())}}checkBoundsChanged(t,e){const i=e.filter((e=>!t||!t.includes(e))),s=null==t?void 0:t.filter((t=>!e||!e.includes(t)));return i.length>0||s.length>0}deselectMarker(t){}deselectShape(t){}render(){return D`
(e,i)=>{void 0!==i?i.addInitializer((()=>{customElements.define(t,e)
width: 100%;
height: 100%;
}
- `,e([dt({type:String,attribute:"api-key"}),i("design:type",Object)],t.LitGoogleMap.prototype,"apiKey",void 0),e([dt({type:String}),i("design:type",Object)],t.LitGoogleMap.prototype,"version",void 0),e([dt({type:Object}),i("design:type",Object)],t.LitGoogleMap.prototype,"styles",void 0),e([dt({type:Number}),i("design:type",Object)],t.LitGoogleMap.prototype,"zoom",void 0),e([dt({type:Boolean,attribute:"fit-to-markers"}),i("design:type",Object)],t.LitGoogleMap.prototype,"fitToMarkers",void 0),e([dt({type:String,attribute:"map-type"}),i("design:type",Object)],t.LitGoogleMap.prototype,"mapType",void 0),e([dt({type:Number,attribute:"center-latitude"}),i("design:type",Object)],t.LitGoogleMap.prototype,"centerLatitude",void 0),e([dt({type:Number,attribute:"center-longitude"}),i("design:type",Object)],t.LitGoogleMap.prototype,"centerLongitude",void 0),e([dt({type:String}),i("design:type",Object)],t.LitGoogleMap.prototype,"language",void 0),e([dt({type:String,attribute:"map-id"}),i("design:type",Object)],t.LitGoogleMap.prototype,"mapId",void 0),t.LitGoogleMap=e([ht("lit-google-map")],t.LitGoogleMap),t.LitGoogleMapCircle=class extends at{constructor(){super(...arguments),this.centerLatitude=-34.397,this.centerLongitude=150.644,this.radius=1e5,this.fillColor="#FF0000",this.fillOpacity=.35,this.strokeColor="#FF0000",this.strokeOpacity=.8,this.strokeWeight=2,this.map=null,this.circle=null}attributeChangedCallback(t,e,i){var s;switch(super.attributeChangedCallback(t,e,i),t){case"center-latitude":case"center-longitude":this.updateCenter();break;case"radius":null===(s=this.circle)||void 0===s||s.setRadius(this.radius)}}updateCenter(){var t;null===(t=this.circle)||void 0===t||t.setCenter(new google.maps.LatLng(this.centerLatitude,this.centerLongitude))}attachToMap(t){this.map=t,this.mapChanged()}mapChanged(){this.circle&&(this.circle.setMap(null),google.maps.event.clearInstanceListeners(this.circle)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.circle=new google.maps.Circle({map:this.map,strokeColor:this.strokeColor,strokeOpacity:this.strokeOpacity,strokeWeight:this.strokeWeight,fillColor:this.fillColor,fillOpacity:this.fillOpacity,center:{lat:this.centerLatitude,lng:this.centerLongitude},radius:this.radius})}},e([dt({type:Number,attribute:"center-latitude"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"centerLatitude",void 0),e([dt({type:Number,attribute:"center-longitude"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"centerLongitude",void 0),e([dt({type:Number}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"radius",void 0),e([dt({type:String,attribute:"fill-color"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"fillColor",void 0),e([dt({type:Number,attribute:"fill-opacity"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"fillOpacity",void 0),e([dt({type:String,attribute:"stroke-color"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"strokeColor",void 0),e([dt({type:Number,attribute:"stroke-opacity"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"strokeOpacity",void 0),e([dt({type:Number,attribute:"stroke-weight"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"strokeWeight",void 0),t.LitGoogleMapCircle=e([ht("lit-google-map-circle")],t.LitGoogleMapCircle),t.LitGoogleMapMarker=class extends at{constructor(){super(...arguments),this.latitude=0,this.longitude=0,this.zIndex=0,this.open=!1,this.id=null,this.glyph=null,this.glyphColor=null,this.background=null,this.borderColor=null,this.scale=null,this.omitFromFit=!1,this.map=null,this.marker=null,this.pin=null}attributeChangedCallback(t,e,i){switch(super.attributeChangedCallback(t,e,i),t){case"open":this.openChanged();break;case"latitude":case"longitude":this.updatePosition();break;case"glyph":this.pin&&(this.pin.glyph=this.glyph);break;case"glyphColor":this.pin&&(this.pin.glyphColor=this.glyphColor);break;case"background":this.pin&&(this.pin.background=this.background);break;case"borderColor":this.pin&&(this.pin.borderColor=this.borderColor);break;case"scale":this.pin&&(this.pin.scale=this.scale);break;case"z-index":this.marker&&(this.marker.zIndex=this.zIndex)}}openChanged(){this.info&&(this.open?(this.info.open(this.map,this.marker),this.dispatchEvent(new CustomEvent("google-map-marker-open",{bubbles:!0}))):(this.info.close(),this.dispatchEvent(new CustomEvent("google-map-marker-close",{bubbles:!0}))))}updatePosition(){this.marker&&(this.marker.position=new google.maps.LatLng(this.latitude,this.longitude))}changeMap(t){this.map=t,this.mapChanged()}mapChanged(){this.marker&&(this.marker.map=null,google.maps.event.clearInstanceListeners(this.marker)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.pin=new google.maps.marker.PinElement({glyph:this.glyph,glyphColor:this.glyphColor,background:this.background,borderColor:this.borderColor,scale:this.scale}),this.marker=new google.maps.marker.AdvancedMarkerElement({map:this.map,position:{lat:this.latitude,lng:this.longitude},content:this.pin.element,zIndex:this.zIndex,gmpClickable:!0}),this.marker.element.addEventListener("mouseover",(()=>{this.dispatchEvent(new CustomEvent("mouseover",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.marker.element.addEventListener("mouseout",(()=>{this.dispatchEvent(new CustomEvent("mouseout",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.marker.addListener("click",(()=>{this.dispatchEvent(new CustomEvent("click",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.contentChanged()}contentChanged(){this.contentObserver&&this.contentObserver.disconnect(),this.contentObserver=new MutationObserver(this.contentChanged.bind(this)),this.contentObserver.observe(this,{childList:!0,subtree:!0});const t=this.innerHTML.trim();t?(this.info||(this.info=new google.maps.InfoWindow,this.openInfoHandler=google.maps.event.addListener(this.marker,"click",function(){this.open=!0}.bind(this)),this.closeInfoHandler=google.maps.event.addListener(this.info,"closeclick",function(){this.open=!1}.bind(this))),this.info.setContent(t)):this.info&&(google.maps.event.removeListener(this.openInfoHandler),google.maps.event.removeListener(this.closeInfoHandler),this.info=null)}},e([dt({type:Number,reflect:!0}),i("design:type",Object)],t.LitGoogleMapMarker.prototype,"latitude",void 0),e([dt({type:Number,reflect:!0}),i("design:type",Object)],t.LitGoogleMapMarker.prototype,"longitude",void 0),e([dt({type:Number,reflect:!0,attribute:"z-index"}),i("design:type",Object)],t.LitGoogleMapMarker.prototype,"zIndex",void 0),e([dt({type:Boolean,reflect:!0}),i("design:type",Object)],t.LitGoogleMapMarker.prototype,"open",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"id",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"glyph",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"glyphColor",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"background",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"borderColor",void 0),e([dt({type:Number,reflect:!0}),i("design:type",Number)],t.LitGoogleMapMarker.prototype,"scale",void 0),e([dt({type:Boolean,attribute:"omit-from-fit"}),i("design:type",Object)],t.LitGoogleMapMarker.prototype,"omitFromFit",void 0),t.LitGoogleMapMarker=e([ht("lit-google-map-marker")],t.LitGoogleMapMarker),t.LitGoogleMapPolygon=class extends at{constructor(){super(...arguments),this.paths=[],this.fillColor="#FF0000",this.fillOpacity=.35,this.strokeColor="#FF0000",this.strokeOpacity=.8,this.strokeWeight=2,this.map=null,this.polygon=null}attachToMap(t){this.map=t,this.mapChanged()}mapChanged(){this.polygon&&(this.polygon.setMap(null),google.maps.event.clearInstanceListeners(this.polygon)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.polygon=new google.maps.Polygon({map:this.map,strokeColor:this.strokeColor,strokeOpacity:this.strokeOpacity,strokeWeight:this.strokeWeight,fillColor:this.fillColor,fillOpacity:this.fillOpacity,paths:this.paths})}},e([dt({type:Array}),i("design:type",Array)],t.LitGoogleMapPolygon.prototype,"paths",void 0),e([dt({type:String,attribute:"fill-color"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"fillColor",void 0),e([dt({type:Number,attribute:"fill-opacity"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"fillOpacity",void 0),e([dt({type:String,attribute:"stroke-color"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"strokeColor",void 0),e([dt({type:Number,attribute:"stroke-opacity"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"strokeOpacity",void 0),e([dt({type:Number,attribute:"stroke-weight"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"strokeWeight",void 0),t.LitGoogleMapPolygon=e([ht("lit-google-map-polygon")],t.LitGoogleMapPolygon);class ut{constructor(){this.apiMap={}}require(t,e,i){const s=this.nameFromUrl(t);this.apiMap[s]||(this.apiMap[s]=new gt(s,t,i)),this.apiMap[s].requestNotify(e)}static getInstance(){return ut.instance||(ut.instance=new ut),ut.instance}nameFromUrl(t){return`${t.replace(/[:/%?&.=\-,]/g,"_")}_api`}}class gt{constructor(t,e,i){this.callbackMacro="%%callback%%",this.loaded=!1,this.script=null,this.notifiers=[];let s=e,o=i;if(!o){if(!(s.indexOf(this.callbackMacro)>=0))return void console.error("ScriptLoader class: a %%callback%% parameter is required in libraryUrl");o=`${t}_loaded`,s=s.replace(this.callbackMacro,o)}this.callbackName=o,window[this.callbackName]=this.success.bind(this),this.addScript(s)}addScript(t){const e=document.createElement("script");e.src=t,e.onerror=this.handleError.bind(this);const i=document.querySelector("script")||document.body;i.parentNode.insertBefore(e,i),this.script=e}removeScript(){this.script.parentNode&&this.script.parentNode.removeChild(this.script),this.script=null}handleError(t){this.error=new Error("Library failed to load"),this.notifyAll(),this.cleanup()}success(...t){this.loaded=!0,this.result=t,this.notifyAll(),this.cleanup()}cleanup(){delete window[this.callbackName]}notifyAll(){this.notifiers.forEach(function(t){t(this.error,this.result)}.bind(this)),this.notifiers=[]}requestNotify(t){this.loaded||this.error?t(this.error,this.result):this.notifiers.push(t)}}class mt extends at{constructor(){super(...arguments),this.libraryLoaded=!1,this.libraryErrorMessage=null,this.isReady=!1}get callbackName(){return null}libraryUrlChanged(){this.isReady&&null!=this.libraryUrl&&this.loadLibrary()}libraryLoadCallback(t,e){t?(console.warn("Library load failed:",t.message),this.libraryErrorMessage=t.message):(this.libraryErrorMessage=null,this.libraryLoaded=!0,null!=this.notifyEvent&&this.dispatchEvent(new CustomEvent(this.notifyEvent,{detail:e,composed:!0})))}loadLibrary(){ut.getInstance().require(this.libraryUrl,this.libraryLoadCallback.bind(this),this.callbackName)}connectedCallback(){super.connectedCallback(),this.isReady=!0,null!=this.libraryUrl&&this.loadLibrary()}}t.LitGoogleMapsApi=class extends mt{constructor(){super(...arguments),this.apiKey="",this.clientId="",this.mapsUrl="https://maps.googleapis.com/maps/api/js?callback=%%callback%%",this.version="3.39",this.language="",this.mapId=""}get libraryUrl(){return this.computeUrl(this.mapsUrl,this.version,this.apiKey,this.clientId,this.language,this.mapId)}get notifyEvent(){return"api-load"}computeUrl(t,e,i,s,o,r){let n=`${t}&v=${e}`;if(n+="&libraries=drawing,geometry,places,visualization,marker",i&&!s&&(n+=`&key=${i}`),s&&(n+=`&client=${s}`),!i&&!s){const t="No Google Maps API Key or Client ID specified. See https://developers.google.com/maps/documentation/javascript/get-api-key for instructions to get started with a key or client id.";console.warn(t)}return o&&(n+=`&language=${o}`),r&&(n+=`&map_ids=${r}`),n}},e([dt({type:String,attribute:"api-key"}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"apiKey",void 0),e([dt({type:String,attribute:"client-id"}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"clientId",void 0),e([dt({type:String,attribute:"maps-url"}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"mapsUrl",void 0),e([dt({type:String}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"version",void 0),e([dt({type:String}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"language",void 0),e([dt({type:String,attribute:"map-id"}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"mapId",void 0),t.LitGoogleMapsApi=e([ht("lit-google-maps-api")],t.LitGoogleMapsApi);class yt{constructor(t){this.multi=!1,this.selection=[],this.selectCallback=t}get(){return this.multi?this.selection.slice():this.selection[0]}clear(t){for(const e of this.selection.slice())(!t||t.indexOf(e)<0)&&this.setItemSelected(e,!1)}isSelected(t){return this.selection.indexOf(t)>=0}setItemSelected(t,e){if(null!=t&&e!==this.isSelected(t)){if(e)this.selection.push(t);else{const e=this.selection.indexOf(t);e>=0&&this.selection.splice(e,1)}this.selectCallback&&this.selectCallback(t,e)}}select(t){this.multi?this.toggle(t):this.get()!==t&&(this.setItemSelected(this.get(),!1),this.setItemSelected(t,!0))}toggle(t){this.setItemSelected(t,!this.isSelected(t))}}return t.LitSelector=class extends at{constructor(){super(...arguments),this.activateEvent="tap",this.selectedAttribute=null,this.selected=null,this._selection=new yt(((t,e)=>this.applySelection(t,e))),this._items=[]}get items(){return this._items}connectedCallback(){super.connectedCallback(),this.addEventListener("slotchange",(t=>{t.stopPropagation(),this.updateItems(),this.dispatchEvent(new CustomEvent("selector-items-changed",{detail:{},composed:!0}))})),this.addListener(this.activateEvent)}disconnectedCallback(){super.disconnectedCallback(),this.removeListener(this.activateEvent)}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback(t,e,i),"selected"===t)this.updateSelected()}applySelection(t,e){this.selectedAttribute&&t instanceof Element&&e!==t.hasAttribute(this.selectedAttribute)&&t.toggleAttribute(this.selectedAttribute)}updateItems(){var t;const e=this.querySelector("slot");this._items=null!==(t=null==e?void 0:e.assignedNodes())&&void 0!==t?t:[]}addListener(t){this.addEventListener(t,(t=>this.activateHandler(t)))}removeListener(t){this.removeEventListener(t,(t=>this.activateHandler(t)))}activateHandler(t){let e=t.target;const i=this.items;for(;e&&e!==this;){const t=i.indexOf(e);if(t>=0){const i=this.indexToValue(t);return void this.itemActivate(i,e)}e=e.parentNode}}itemActivate(t,e){this.dispatchEvent(new CustomEvent("selector-item-activate",{detail:{selected:t,item:e},composed:!0,cancelable:!0}))&&this.select(t)}select(t){this.selected=t}updateSelected(){this.selectSelected(this.selected)}selectSelected(t){if(!this._items)return;const e=this.valueToItem(this.selected);e?this._selection.select(e):this._selection.clear()}valueToItem(t){return null==t?null:this._items[this.valueToIndex(t)]}valueToIndex(t){return Number(t)}indexToValue(t){return t}indexOf(t){return this._items?this._items.indexOf(t):-1}},e([dt({type:String,attribute:"activate-event"}),i("design:type",Object)],t.LitSelector.prototype,"activateEvent",void 0),e([dt({type:String,attribute:"selected-attribute"}),i("design:type",String)],t.LitSelector.prototype,"selectedAttribute",void 0),e([dt({type:Number,reflect:!0}),i("design:type",Object)],t.LitSelector.prototype,"selected",void 0),t.LitSelector=e([ht("lit-selector")],t.LitSelector),t}({});
+ `,e([dt({type:String,attribute:"api-key"}),i("design:type",Object)],t.LitGoogleMap.prototype,"apiKey",void 0),e([dt({type:String}),i("design:type",Object)],t.LitGoogleMap.prototype,"version",void 0),e([dt({type:Object}),i("design:type",Object)],t.LitGoogleMap.prototype,"styles",void 0),e([dt({type:Number}),i("design:type",Object)],t.LitGoogleMap.prototype,"zoom",void 0),e([dt({type:Boolean,attribute:"fit-to-markers"}),i("design:type",Object)],t.LitGoogleMap.prototype,"fitToMarkers",void 0),e([dt({type:String,attribute:"map-type"}),i("design:type",Object)],t.LitGoogleMap.prototype,"mapType",void 0),e([dt({type:Number,attribute:"center-latitude"}),i("design:type",Object)],t.LitGoogleMap.prototype,"centerLatitude",void 0),e([dt({type:Number,attribute:"center-longitude"}),i("design:type",Object)],t.LitGoogleMap.prototype,"centerLongitude",void 0),e([dt({type:String}),i("design:type",Object)],t.LitGoogleMap.prototype,"language",void 0),e([dt({type:String,attribute:"map-id"}),i("design:type",Object)],t.LitGoogleMap.prototype,"mapId",void 0),t.LitGoogleMap=e([ht("lit-google-map")],t.LitGoogleMap),t.LitGoogleMapCircle=class extends at{constructor(){super(...arguments),this.centerLatitude=-34.397,this.centerLongitude=150.644,this.radius=1e5,this.fillColor="#FF0000",this.fillOpacity=.35,this.strokeColor="#FF0000",this.strokeOpacity=.8,this.strokeWeight=2,this.map=null,this.circle=null}attributeChangedCallback(t,e,i){var s;switch(super.attributeChangedCallback(t,e,i),t){case"center-latitude":case"center-longitude":this.updateCenter();break;case"radius":null===(s=this.circle)||void 0===s||s.setRadius(this.radius)}}updateCenter(){var t;null===(t=this.circle)||void 0===t||t.setCenter(new google.maps.LatLng(this.centerLatitude,this.centerLongitude))}attachToMap(t){this.map=t,this.mapChanged()}mapChanged(){this.circle&&(this.circle.setMap(null),google.maps.event.clearInstanceListeners(this.circle)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.circle=new google.maps.Circle({map:this.map,strokeColor:this.strokeColor,strokeOpacity:this.strokeOpacity,strokeWeight:this.strokeWeight,fillColor:this.fillColor,fillOpacity:this.fillOpacity,center:{lat:this.centerLatitude,lng:this.centerLongitude},radius:this.radius})}},e([dt({type:Number,attribute:"center-latitude"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"centerLatitude",void 0),e([dt({type:Number,attribute:"center-longitude"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"centerLongitude",void 0),e([dt({type:Number}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"radius",void 0),e([dt({type:String,attribute:"fill-color"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"fillColor",void 0),e([dt({type:Number,attribute:"fill-opacity"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"fillOpacity",void 0),e([dt({type:String,attribute:"stroke-color"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"strokeColor",void 0),e([dt({type:Number,attribute:"stroke-opacity"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"strokeOpacity",void 0),e([dt({type:Number,attribute:"stroke-weight"}),i("design:type",Object)],t.LitGoogleMapCircle.prototype,"strokeWeight",void 0),t.LitGoogleMapCircle=e([ht("lit-google-map-circle")],t.LitGoogleMapCircle),t.LitGoogleMapMarker=class extends at{constructor(){super(...arguments),this.latitude=0,this.longitude=0,this.zIndex=0,this.open=!1,this.id=null,this.glyph=null,this.glyphColor=null,this.background=null,this.borderColor=null,this.scale=null,this.map=null,this.marker=null,this.pin=null}attributeChangedCallback(t,e,i){switch(super.attributeChangedCallback(t,e,i),t){case"open":this.openChanged();break;case"latitude":case"longitude":this.updatePosition();break;case"glyph":this.pin&&(this.pin.glyph=this.glyph);break;case"glyphColor":this.pin&&(this.pin.glyphColor=this.glyphColor);break;case"background":this.pin&&(this.pin.background=this.background);break;case"borderColor":this.pin&&(this.pin.borderColor=this.borderColor);break;case"scale":this.pin&&(this.pin.scale=this.scale);break;case"z-index":this.marker&&(this.marker.zIndex=this.zIndex)}}openChanged(){this.info&&(this.open?(this.info.open(this.map,this.marker),this.dispatchEvent(new CustomEvent("google-map-marker-open",{bubbles:!0}))):(this.info.close(),this.dispatchEvent(new CustomEvent("google-map-marker-close",{bubbles:!0}))))}updatePosition(){this.marker&&(this.marker.position=new google.maps.LatLng(this.latitude,this.longitude))}changeMap(t){this.map=t,this.mapChanged()}mapChanged(){this.marker&&(this.marker.map=null,google.maps.event.clearInstanceListeners(this.marker)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.pin=new google.maps.marker.PinElement({glyph:this.glyph,glyphColor:this.glyphColor,background:this.background,borderColor:this.borderColor,scale:this.scale}),this.marker=new google.maps.marker.AdvancedMarkerElement({map:this.map,position:{lat:this.latitude,lng:this.longitude},content:this.pin.element,zIndex:this.zIndex,gmpClickable:!0}),this.marker.element.addEventListener("mouseover",(()=>{this.dispatchEvent(new CustomEvent("mouseover",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.marker.element.addEventListener("mouseout",(()=>{this.dispatchEvent(new CustomEvent("mouseout",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.marker.addListener("click",(()=>{this.dispatchEvent(new CustomEvent("click",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.contentChanged()}contentChanged(){this.contentObserver&&this.contentObserver.disconnect(),this.contentObserver=new MutationObserver(this.contentChanged.bind(this)),this.contentObserver.observe(this,{childList:!0,subtree:!0});const t=this.innerHTML.trim();t?(this.info||(this.info=new google.maps.InfoWindow,this.openInfoHandler=google.maps.event.addListener(this.marker,"click",function(){this.open=!0}.bind(this)),this.closeInfoHandler=google.maps.event.addListener(this.info,"closeclick",function(){this.open=!1}.bind(this))),this.info.setContent(t)):this.info&&(google.maps.event.removeListener(this.openInfoHandler),google.maps.event.removeListener(this.closeInfoHandler),this.info=null)}},e([dt({type:Number,reflect:!0}),i("design:type",Object)],t.LitGoogleMapMarker.prototype,"latitude",void 0),e([dt({type:Number,reflect:!0}),i("design:type",Object)],t.LitGoogleMapMarker.prototype,"longitude",void 0),e([dt({type:Number,reflect:!0,attribute:"z-index"}),i("design:type",Object)],t.LitGoogleMapMarker.prototype,"zIndex",void 0),e([dt({type:Boolean,reflect:!0}),i("design:type",Object)],t.LitGoogleMapMarker.prototype,"open",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"id",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"glyph",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"glyphColor",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"background",void 0),e([dt({type:String,reflect:!0}),i("design:type",String)],t.LitGoogleMapMarker.prototype,"borderColor",void 0),e([dt({type:Number,reflect:!0}),i("design:type",Number)],t.LitGoogleMapMarker.prototype,"scale",void 0),t.LitGoogleMapMarker=e([ht("lit-google-map-marker")],t.LitGoogleMapMarker),t.LitGoogleMapPolygon=class extends at{constructor(){super(...arguments),this.paths=[],this.fillColor="#FF0000",this.fillOpacity=.35,this.strokeColor="#FF0000",this.strokeOpacity=.8,this.strokeWeight=2,this.map=null,this.polygon=null}attachToMap(t){this.map=t,this.mapChanged()}mapChanged(){this.polygon&&(this.polygon.setMap(null),google.maps.event.clearInstanceListeners(this.polygon)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.polygon=new google.maps.Polygon({map:this.map,strokeColor:this.strokeColor,strokeOpacity:this.strokeOpacity,strokeWeight:this.strokeWeight,fillColor:this.fillColor,fillOpacity:this.fillOpacity,paths:this.paths})}},e([dt({type:Array}),i("design:type",Array)],t.LitGoogleMapPolygon.prototype,"paths",void 0),e([dt({type:String,attribute:"fill-color"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"fillColor",void 0),e([dt({type:Number,attribute:"fill-opacity"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"fillOpacity",void 0),e([dt({type:String,attribute:"stroke-color"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"strokeColor",void 0),e([dt({type:Number,attribute:"stroke-opacity"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"strokeOpacity",void 0),e([dt({type:Number,attribute:"stroke-weight"}),i("design:type",Object)],t.LitGoogleMapPolygon.prototype,"strokeWeight",void 0),t.LitGoogleMapPolygon=e([ht("lit-google-map-polygon")],t.LitGoogleMapPolygon);class ut{constructor(){this.apiMap={}}require(t,e,i){const s=this.nameFromUrl(t);this.apiMap[s]||(this.apiMap[s]=new gt(s,t,i)),this.apiMap[s].requestNotify(e)}static getInstance(){return ut.instance||(ut.instance=new ut),ut.instance}nameFromUrl(t){return`${t.replace(/[:/%?&.=\-,]/g,"_")}_api`}}class gt{constructor(t,e,i){this.callbackMacro="%%callback%%",this.loaded=!1,this.script=null,this.notifiers=[];let s=e,o=i;if(!o){if(!(s.indexOf(this.callbackMacro)>=0))return void console.error("ScriptLoader class: a %%callback%% parameter is required in libraryUrl");o=`${t}_loaded`,s=s.replace(this.callbackMacro,o)}this.callbackName=o,window[this.callbackName]=this.success.bind(this),this.addScript(s)}addScript(t){const e=document.createElement("script");e.src=t,e.onerror=this.handleError.bind(this);const i=document.querySelector("script")||document.body;i.parentNode.insertBefore(e,i),this.script=e}removeScript(){this.script.parentNode&&this.script.parentNode.removeChild(this.script),this.script=null}handleError(t){this.error=new Error("Library failed to load"),this.notifyAll(),this.cleanup()}success(...t){this.loaded=!0,this.result=t,this.notifyAll(),this.cleanup()}cleanup(){delete window[this.callbackName]}notifyAll(){this.notifiers.forEach(function(t){t(this.error,this.result)}.bind(this)),this.notifiers=[]}requestNotify(t){this.loaded||this.error?t(this.error,this.result):this.notifiers.push(t)}}class mt extends at{constructor(){super(...arguments),this.libraryLoaded=!1,this.libraryErrorMessage=null,this.isReady=!1}get callbackName(){return null}libraryUrlChanged(){this.isReady&&null!=this.libraryUrl&&this.loadLibrary()}libraryLoadCallback(t,e){t?(console.warn("Library load failed:",t.message),this.libraryErrorMessage=t.message):(this.libraryErrorMessage=null,this.libraryLoaded=!0,null!=this.notifyEvent&&this.dispatchEvent(new CustomEvent(this.notifyEvent,{detail:e,composed:!0})))}loadLibrary(){ut.getInstance().require(this.libraryUrl,this.libraryLoadCallback.bind(this),this.callbackName)}connectedCallback(){super.connectedCallback(),this.isReady=!0,null!=this.libraryUrl&&this.loadLibrary()}}t.LitGoogleMapsApi=class extends mt{constructor(){super(...arguments),this.apiKey="",this.clientId="",this.mapsUrl="https://maps.googleapis.com/maps/api/js?callback=%%callback%%",this.version="3.39",this.language="",this.mapId=""}get libraryUrl(){return this.computeUrl(this.mapsUrl,this.version,this.apiKey,this.clientId,this.language,this.mapId)}get notifyEvent(){return"api-load"}computeUrl(t,e,i,s,o,r){let n=`${t}&v=${e}`;if(n+="&libraries=drawing,geometry,places,visualization,marker",i&&!s&&(n+=`&key=${i}`),s&&(n+=`&client=${s}`),!i&&!s){const t="No Google Maps API Key or Client ID specified. See https://developers.google.com/maps/documentation/javascript/get-api-key for instructions to get started with a key or client id.";console.warn(t)}return o&&(n+=`&language=${o}`),r&&(n+=`&map_ids=${r}`),n}},e([dt({type:String,attribute:"api-key"}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"apiKey",void 0),e([dt({type:String,attribute:"client-id"}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"clientId",void 0),e([dt({type:String,attribute:"maps-url"}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"mapsUrl",void 0),e([dt({type:String}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"version",void 0),e([dt({type:String}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"language",void 0),e([dt({type:String,attribute:"map-id"}),i("design:type",Object)],t.LitGoogleMapsApi.prototype,"mapId",void 0),t.LitGoogleMapsApi=e([ht("lit-google-maps-api")],t.LitGoogleMapsApi);class yt{constructor(t){this.multi=!1,this.selection=[],this.selectCallback=t}get(){return this.multi?this.selection.slice():this.selection[0]}clear(t){for(const e of this.selection.slice())(!t||t.indexOf(e)<0)&&this.setItemSelected(e,!1)}isSelected(t){return this.selection.indexOf(t)>=0}setItemSelected(t,e){if(null!=t&&e!==this.isSelected(t)){if(e)this.selection.push(t);else{const e=this.selection.indexOf(t);e>=0&&this.selection.splice(e,1)}this.selectCallback&&this.selectCallback(t,e)}}select(t){this.multi?this.toggle(t):this.get()!==t&&(this.setItemSelected(this.get(),!1),this.setItemSelected(t,!0))}toggle(t){this.setItemSelected(t,!this.isSelected(t))}}return t.LitSelector=class extends at{constructor(){super(...arguments),this.activateEvent="tap",this.selectedAttribute=null,this.selected=null,this._selection=new yt(((t,e)=>this.applySelection(t,e))),this._items=[]}get items(){return this._items}connectedCallback(){super.connectedCallback(),this.addEventListener("slotchange",(t=>{t.stopPropagation(),this.updateItems(),this.dispatchEvent(new CustomEvent("selector-items-changed",{detail:{},composed:!0}))})),this.addListener(this.activateEvent)}disconnectedCallback(){super.disconnectedCallback(),this.removeListener(this.activateEvent)}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback(t,e,i),"selected"===t)this.updateSelected()}applySelection(t,e){this.selectedAttribute&&t instanceof Element&&e!==t.hasAttribute(this.selectedAttribute)&&t.toggleAttribute(this.selectedAttribute)}updateItems(){var t;const e=this.querySelector("slot");this._items=null!==(t=null==e?void 0:e.assignedNodes())&&void 0!==t?t:[]}addListener(t){this.addEventListener(t,(t=>this.activateHandler(t)))}removeListener(t){this.removeEventListener(t,(t=>this.activateHandler(t)))}activateHandler(t){let e=t.target;const i=this.items;for(;e&&e!==this;){const t=i.indexOf(e);if(t>=0){const i=this.indexToValue(t);return void this.itemActivate(i,e)}e=e.parentNode}}itemActivate(t,e){this.dispatchEvent(new CustomEvent("selector-item-activate",{detail:{selected:t,item:e},composed:!0,cancelable:!0}))&&this.select(t)}select(t){this.selected=t}updateSelected(){this.selectSelected(this.selected)}selectSelected(t){if(!this._items)return;const e=this.valueToItem(this.selected);e?this._selection.select(e):this._selection.clear()}valueToItem(t){return null==t?null:this._items[this.valueToIndex(t)]}valueToIndex(t){return Number(t)}indexToValue(t){return t}indexOf(t){return this._items?this._items.indexOf(t):-1}},e([dt({type:String,attribute:"activate-event"}),i("design:type",Object)],t.LitSelector.prototype,"activateEvent",void 0),e([dt({type:String,attribute:"selected-attribute"}),i("design:type",String)],t.LitSelector.prototype,"selectedAttribute",void 0),e([dt({type:Number,reflect:!0}),i("design:type",Object)],t.LitSelector.prototype,"selected",void 0),t.LitSelector=e([ht("lit-selector")],t.LitSelector),t}({});
diff --git a/dist/lit-google-map.esm.js b/dist/lit-google-map.esm.js
index c8fd38f..1141b9b 100644
--- a/dist/lit-google-map.esm.js
+++ b/dist/lit-google-map.esm.js
@@ -17,6 +17,30 @@ let LitGoogleMap = class LitGoogleMap extends LitElement {
this.mapId = "DEMO_MAP_ID";
this.map = null;
}
+ attributeChangedCallback(name, oldValue, newValue) {
+ super.attributeChangedCallback(name, oldValue, newValue);
+ if (this.map && oldValue !== newValue && newValue !== null) {
+ if (name === "center-latitude" || name === "center-longitude") {
+ this.map.setCenter({
+ lat: this.centerLatitude,
+ lng: this.centerLongitude,
+ });
+ }
+ else if (name === "zoom") {
+ this.map.setZoom(this.zoom);
+ }
+ }
+ }
+ dispatchViewChanged() {
+ this.dispatchEvent(new CustomEvent("view_changed", {
+ detail: {
+ center: this.map.getCenter().toJSON(),
+ zoom: this.map.getZoom(),
+ },
+ bubbles: true,
+ composed: true,
+ }));
+ }
initGMap() {
if (this.map != null) {
return;
@@ -40,6 +64,22 @@ let LitGoogleMap = class LitGoogleMap extends LitElement {
composed: true,
}));
});
+ this.map.addListener("center_changed", () => {
+ this.dispatchEvent(new CustomEvent("center_changed", {
+ detail: this.map.getCenter().toJSON(),
+ bubbles: true,
+ composed: true,
+ }));
+ this.dispatchViewChanged();
+ });
+ this.map.addListener("zoom_changed", () => {
+ this.dispatchEvent(new CustomEvent("zoom_changed", {
+ detail: { zoom: this.map.getZoom() },
+ bubbles: true,
+ composed: true,
+ }));
+ this.dispatchViewChanged();
+ });
this.map.addListener("click", (event) => {
if ("placeId" in event) {
event.stop();
@@ -69,6 +109,27 @@ let LitGoogleMap = class LitGoogleMap extends LitElement {
super.connectedCallback();
this.initGMap();
}
+ updated(changedProperties) {
+ super.updated(changedProperties);
+ if (this.map) {
+ if (changedProperties.has("centerLatitude") ||
+ changedProperties.has("centerLongitude")) {
+ changedProperties.get("centerLatitude");
+ changedProperties.get("centerLongitude");
+ this.map.setCenter({
+ lat: this.centerLatitude,
+ lng: this.centerLongitude,
+ });
+ }
+ if (changedProperties.has("zoom")) {
+ changedProperties.get("zoom");
+ this.map.setZoom(this.zoom);
+ }
+ }
+ else {
+ console.log("Map not initialized yet, skipping update");
+ }
+ }
attachChildrenToMap(children) {
if (this.map) {
for (const child of children) {
@@ -126,10 +187,9 @@ let LitGoogleMap = class LitGoogleMap extends LitElement {
}
}
fitToMarkersChanged(retryAttempt = 0) {
- const markers = this.markers.filter((m) => !m.omitFromFit);
- if (this.map && this.fitToMarkers && markers.length > 0) {
+ if (this.map && this.fitToMarkers && this.markers.length > 0) {
const latLngBounds = new google.maps.LatLngBounds();
- for (const marker of markers) {
+ for (const marker of this.markers) {
latLngBounds.extend(new google.maps.LatLng(marker.latitude, marker.longitude));
}
const domDimensions = this.getBoundingClientRect();
@@ -141,7 +201,7 @@ let LitGoogleMap = class LitGoogleMap extends LitElement {
}, timeout);
return;
}
- if (markers.length > 1) {
+ if (this.markers.length > 1) {
this.map.fitBounds(latLngBounds, 0);
}
this.map.setCenter(latLngBounds.getCenter());
@@ -149,12 +209,10 @@ let LitGoogleMap = class LitGoogleMap extends LitElement {
}
checkBoundsChanged(oldMarkers, newMarkers) {
const addedInBounds = newMarkers.filter((m) => {
- return (!m.omitFromFit &&
- (!oldMarkers || !oldMarkers.includes(m)));
+ return !oldMarkers || !oldMarkers.includes(m);
});
const removedInBounds = oldMarkers === null || oldMarkers === void 0 ? void 0 : oldMarkers.filter((m) => {
- return (!m.omitFromFit &&
- (!newMarkers || !newMarkers.includes(m)));
+ return !newMarkers || !newMarkers.includes(m);
});
return addedInBounds.length > 0 || removedInBounds.length > 0;
}
@@ -355,7 +413,6 @@ let LitGoogleMapMarker = class LitGoogleMapMarker extends LitElement {
this.background = null;
this.borderColor = null;
this.scale = null;
- this.omitFromFit = false;
this.map = null;
this.marker = null;
this.pin = null;
@@ -554,10 +611,6 @@ __decorate([
property({ type: Number, reflect: true }),
__metadata("design:type", Number)
], LitGoogleMapMarker.prototype, "scale", void 0);
-__decorate([
- property({ type: Boolean, attribute: "omit-from-fit" }),
- __metadata("design:type", Object)
-], LitGoogleMapMarker.prototype, "omitFromFit", void 0);
LitGoogleMapMarker = __decorate([
customElement("lit-google-map-marker")
], LitGoogleMapMarker);
diff --git a/dist/lit-google-map.esm.min.js b/dist/lit-google-map.esm.min.js
index 8c002d5..f9edbe7 100644
--- a/dist/lit-google-map.esm.min.js
+++ b/dist/lit-google-map.esm.min.js
@@ -1,4 +1,4 @@
-import{__decorate as t,__metadata as e}from"tslib";import{css as i,LitElement as s,html as o}from"lit";import{property as r,customElement as a}from"lit/decorators.js";let n=class extends s{constructor(){super(...arguments),this.apiKey="",this.version="3.48",this.styles={},this.zoom=8,this.fitToMarkers=!1,this.mapType="roadmap",this.centerLatitude=-34.397,this.centerLongitude=150.644,this.language="",this.mapId="DEMO_MAP_ID",this.map=null}initGMap(){if(null!=this.map)return;const t=this.shadowRoot.getElementById("api");null!=t&&!0===t.libraryLoaded&&(this.map=new google.maps.Map(this.shadowRoot.getElementById("map"),this.getMapOptions()),this.map.addListener("bounds_changed",(()=>{this.dispatchEvent(new CustomEvent("bounds_changed",{detail:this.map.getBounds().toJSON(),bubbles:!0,composed:!0}))})),this.map.addListener("tilesloaded",(()=>{this.dispatchEvent(new CustomEvent("tilesloaded",{detail:this.map.getBounds().toJSON(),bubbles:!0,composed:!0}))})),this.map.addListener("click",(t=>{"placeId"in t&&(t.stop(),this.dispatchEvent(new CustomEvent("place_click",{detail:{placeId:t.placeId},bubbles:!0,composed:!0})))})),this.updateMarkers(),this.updateShapes())}getMapOptions(){return{zoom:this.zoom,center:{lat:this.centerLatitude,lng:this.centerLongitude},mapTypeId:this.mapType,styles:this.styles,mapId:this.mapId}}mapApiLoaded(){this.initGMap()}connectedCallback(){super.connectedCallback(),this.initGMap()}attachChildrenToMap(t){if(this.map)for(const e of t)e.changeMap(this.map)}detachChildrenFromMap(t){if(this.map)for(const e of t)e.changeMap(null)}observeMarkers(){this.markerObserverSet||(this.addEventListener("selector-items-changed",(()=>{this.updateMarkers()})),this.markerObserverSet=!0)}updateMarkers(){var t;this.observeMarkers();const e=this.shadowRoot.getElementById("markers-selector");if(!e)return;const i=e.items;if(this.markers&&i.length===this.markers.length){if(0===i.filter((t=>this.markers&&-1===this.markers.indexOf(t))).length)return}const s=this.checkBoundsChanged(this.markers,i),o=(null===(t=this.markers)||void 0===t?void 0:t.filter((t=>-1===i.indexOf(t))))||[];this.detachChildrenFromMap(o),this.markers=i,this.attachChildrenToMap(this.markers),this.fitToMarkers&&s&&this.fitToMarkersChanged()}updateShapes(){const t=this.shadowRoot.getElementById("shapes-selector");if(t){this.shapes=t.items;for(const t of this.shapes)t.attachToMap(this.map)}}fitToMarkersChanged(t=0){const e=this.markers.filter((t=>!t.omitFromFit));if(this.map&&this.fitToMarkers&&e.length>0){const i=new google.maps.LatLngBounds;for(const t of e)i.extend(new google.maps.LatLng(t.latitude,t.longitude));const s=this.getBoundingClientRect();if(0===s.width||0===s.height){console.log("Invalid DOM width or height for lit-google-map");return void setTimeout((()=>{this.fitToMarkersChanged(t+1)}),2**t*100)}e.length>1&&this.map.fitBounds(i,0),this.map.setCenter(i.getCenter())}}checkBoundsChanged(t,e){const i=e.filter((e=>!(e.omitFromFit||t&&t.includes(e)))),s=null==t?void 0:t.filter((t=>!(t.omitFromFit||e&&e.includes(t))));return i.length>0||s.length>0}deselectMarker(t){}deselectShape(t){}render(){return o`
+import{__decorate as t,__metadata as e}from"tslib";import{css as i,LitElement as s,html as o}from"lit";import{property as a,customElement as r}from"lit/decorators.js";let n=class extends s{constructor(){super(...arguments),this.apiKey="",this.version="3.48",this.styles={},this.zoom=8,this.fitToMarkers=!1,this.mapType="roadmap",this.centerLatitude=-34.397,this.centerLongitude=150.644,this.language="",this.mapId="DEMO_MAP_ID",this.map=null}attributeChangedCallback(t,e,i){super.attributeChangedCallback(t,e,i),this.map&&e!==i&&null!==i&&("center-latitude"===t||"center-longitude"===t?this.map.setCenter({lat:this.centerLatitude,lng:this.centerLongitude}):"zoom"===t&&this.map.setZoom(this.zoom))}dispatchViewChanged(){this.dispatchEvent(new CustomEvent("view_changed",{detail:{center:this.map.getCenter().toJSON(),zoom:this.map.getZoom()},bubbles:!0,composed:!0}))}initGMap(){if(null!=this.map)return;const t=this.shadowRoot.getElementById("api");null!=t&&!0===t.libraryLoaded&&(this.map=new google.maps.Map(this.shadowRoot.getElementById("map"),this.getMapOptions()),this.map.addListener("bounds_changed",(()=>{this.dispatchEvent(new CustomEvent("bounds_changed",{detail:this.map.getBounds().toJSON(),bubbles:!0,composed:!0}))})),this.map.addListener("tilesloaded",(()=>{this.dispatchEvent(new CustomEvent("tilesloaded",{detail:this.map.getBounds().toJSON(),bubbles:!0,composed:!0}))})),this.map.addListener("center_changed",(()=>{this.dispatchEvent(new CustomEvent("center_changed",{detail:this.map.getCenter().toJSON(),bubbles:!0,composed:!0})),this.dispatchViewChanged()})),this.map.addListener("zoom_changed",(()=>{this.dispatchEvent(new CustomEvent("zoom_changed",{detail:{zoom:this.map.getZoom()},bubbles:!0,composed:!0})),this.dispatchViewChanged()})),this.map.addListener("click",(t=>{"placeId"in t&&(t.stop(),this.dispatchEvent(new CustomEvent("place_click",{detail:{placeId:t.placeId},bubbles:!0,composed:!0})))})),this.updateMarkers(),this.updateShapes())}getMapOptions(){return{zoom:this.zoom,center:{lat:this.centerLatitude,lng:this.centerLongitude},mapTypeId:this.mapType,styles:this.styles,mapId:this.mapId}}mapApiLoaded(){this.initGMap()}connectedCallback(){super.connectedCallback(),this.initGMap()}updated(t){super.updated(t),this.map?((t.has("centerLatitude")||t.has("centerLongitude"))&&(t.get("centerLatitude"),t.get("centerLongitude"),this.map.setCenter({lat:this.centerLatitude,lng:this.centerLongitude})),t.has("zoom")&&(t.get("zoom"),this.map.setZoom(this.zoom))):console.log("Map not initialized yet, skipping update")}attachChildrenToMap(t){if(this.map)for(const e of t)e.changeMap(this.map)}detachChildrenFromMap(t){if(this.map)for(const e of t)e.changeMap(null)}observeMarkers(){this.markerObserverSet||(this.addEventListener("selector-items-changed",(()=>{this.updateMarkers()})),this.markerObserverSet=!0)}updateMarkers(){var t;this.observeMarkers();const e=this.shadowRoot.getElementById("markers-selector");if(!e)return;const i=e.items;if(this.markers&&i.length===this.markers.length){if(0===i.filter((t=>this.markers&&-1===this.markers.indexOf(t))).length)return}const s=this.checkBoundsChanged(this.markers,i),o=(null===(t=this.markers)||void 0===t?void 0:t.filter((t=>-1===i.indexOf(t))))||[];this.detachChildrenFromMap(o),this.markers=i,this.attachChildrenToMap(this.markers),this.fitToMarkers&&s&&this.fitToMarkersChanged()}updateShapes(){const t=this.shadowRoot.getElementById("shapes-selector");if(t){this.shapes=t.items;for(const t of this.shapes)t.attachToMap(this.map)}}fitToMarkersChanged(t=0){if(this.map&&this.fitToMarkers&&this.markers.length>0){const e=new google.maps.LatLngBounds;for(const t of this.markers)e.extend(new google.maps.LatLng(t.latitude,t.longitude));const i=this.getBoundingClientRect();if(0===i.width||0===i.height){console.log("Invalid DOM width or height for lit-google-map");return void setTimeout((()=>{this.fitToMarkersChanged(t+1)}),2**t*100)}this.markers.length>1&&this.map.fitBounds(e,0),this.map.setCenter(e.getCenter())}}checkBoundsChanged(t,e){const i=e.filter((e=>!t||!t.includes(e))),s=null==t?void 0:t.filter((t=>!e||!e.includes(t)));return i.length>0||s.length>0}deselectMarker(t){}deselectShape(t){}render(){return o`
{this.dispatchEvent(new CustomEvent("mouseover",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.marker.element.addEventListener("mouseout",(()=>{this.dispatchEvent(new CustomEvent("mouseout",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.marker.addListener("click",(()=>{this.dispatchEvent(new CustomEvent("click",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.contentChanged()}contentChanged(){this.contentObserver&&this.contentObserver.disconnect(),this.contentObserver=new MutationObserver(this.contentChanged.bind(this)),this.contentObserver.observe(this,{childList:!0,subtree:!0});const t=this.innerHTML.trim();t?(this.info||(this.info=new google.maps.InfoWindow,this.openInfoHandler=google.maps.event.addListener(this.marker,"click",function(){this.open=!0}.bind(this)),this.closeInfoHandler=google.maps.event.addListener(this.info,"closeclick",function(){this.open=!1}.bind(this))),this.info.setContent(t)):this.info&&(google.maps.event.removeListener(this.openInfoHandler),google.maps.event.removeListener(this.closeInfoHandler),this.info=null)}};t([r({type:Number,reflect:!0}),e("design:type",Object)],p.prototype,"latitude",void 0),t([r({type:Number,reflect:!0}),e("design:type",Object)],p.prototype,"longitude",void 0),t([r({type:Number,reflect:!0,attribute:"z-index"}),e("design:type",Object)],p.prototype,"zIndex",void 0),t([r({type:Boolean,reflect:!0}),e("design:type",Object)],p.prototype,"open",void 0),t([r({type:String,reflect:!0}),e("design:type",String)],p.prototype,"id",void 0),t([r({type:String,reflect:!0}),e("design:type",String)],p.prototype,"glyph",void 0),t([r({type:String,reflect:!0}),e("design:type",String)],p.prototype,"glyphColor",void 0),t([r({type:String,reflect:!0}),e("design:type",String)],p.prototype,"background",void 0),t([r({type:String,reflect:!0}),e("design:type",String)],p.prototype,"borderColor",void 0),t([r({type:Number,reflect:!0}),e("design:type",Number)],p.prototype,"scale",void 0),t([r({type:Boolean,attribute:"omit-from-fit"}),e("design:type",Object)],p.prototype,"omitFromFit",void 0),p=t([a("lit-google-map-marker")],p);let h=class extends s{constructor(){super(...arguments),this.paths=[],this.fillColor="#FF0000",this.fillOpacity=.35,this.strokeColor="#FF0000",this.strokeOpacity=.8,this.strokeWeight=2,this.map=null,this.polygon=null}attachToMap(t){this.map=t,this.mapChanged()}mapChanged(){this.polygon&&(this.polygon.setMap(null),google.maps.event.clearInstanceListeners(this.polygon)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.polygon=new google.maps.Polygon({map:this.map,strokeColor:this.strokeColor,strokeOpacity:this.strokeOpacity,strokeWeight:this.strokeWeight,fillColor:this.fillColor,fillOpacity:this.fillOpacity,paths:this.paths})}};t([r({type:Array}),e("design:type",Array)],h.prototype,"paths",void 0),t([r({type:String,attribute:"fill-color"}),e("design:type",Object)],h.prototype,"fillColor",void 0),t([r({type:Number,attribute:"fill-opacity"}),e("design:type",Object)],h.prototype,"fillOpacity",void 0),t([r({type:String,attribute:"stroke-color"}),e("design:type",Object)],h.prototype,"strokeColor",void 0),t([r({type:Number,attribute:"stroke-opacity"}),e("design:type",Object)],h.prototype,"strokeOpacity",void 0),t([r({type:Number,attribute:"stroke-weight"}),e("design:type",Object)],h.prototype,"strokeWeight",void 0),h=t([a("lit-google-map-polygon")],h);class c{constructor(){this.apiMap={}}require(t,e,i){const s=this.nameFromUrl(t);this.apiMap[s]||(this.apiMap[s]=new d(s,t,i)),this.apiMap[s].requestNotify(e)}static getInstance(){return c.instance||(c.instance=new c),c.instance}nameFromUrl(t){return`${t.replace(/[:/%?&.=\-,]/g,"_")}_api`}}class d{constructor(t,e,i){this.callbackMacro="%%callback%%",this.loaded=!1,this.script=null,this.notifiers=[];let s=e,o=i;if(!o){if(!(s.indexOf(this.callbackMacro)>=0))return void console.error("ScriptLoader class: a %%callback%% parameter is required in libraryUrl");o=`${t}_loaded`,s=s.replace(this.callbackMacro,o)}this.callbackName=o,window[this.callbackName]=this.success.bind(this),this.addScript(s)}addScript(t){const e=document.createElement("script");e.src=t,e.onerror=this.handleError.bind(this);const i=document.querySelector("script")||document.body;i.parentNode.insertBefore(e,i),this.script=e}removeScript(){this.script.parentNode&&this.script.parentNode.removeChild(this.script),this.script=null}handleError(t){this.error=new Error("Library failed to load"),this.notifyAll(),this.cleanup()}success(...t){this.loaded=!0,this.result=t,this.notifyAll(),this.cleanup()}cleanup(){delete window[this.callbackName]}notifyAll(){this.notifiers.forEach(function(t){t(this.error,this.result)}.bind(this)),this.notifiers=[]}requestNotify(t){this.loaded||this.error?t(this.error,this.result):this.notifiers.push(t)}}class g extends s{constructor(){super(...arguments),this.libraryLoaded=!1,this.libraryErrorMessage=null,this.isReady=!1}get callbackName(){return null}libraryUrlChanged(){this.isReady&&null!=this.libraryUrl&&this.loadLibrary()}libraryLoadCallback(t,e){t?(console.warn("Library load failed:",t.message),this.libraryErrorMessage=t.message):(this.libraryErrorMessage=null,this.libraryLoaded=!0,null!=this.notifyEvent&&this.dispatchEvent(new CustomEvent(this.notifyEvent,{detail:e,composed:!0})))}loadLibrary(){c.getInstance().require(this.libraryUrl,this.libraryLoadCallback.bind(this),this.callbackName)}connectedCallback(){super.connectedCallback(),this.isReady=!0,null!=this.libraryUrl&&this.loadLibrary()}}let u=class extends g{constructor(){super(...arguments),this.apiKey="",this.clientId="",this.mapsUrl="https://maps.googleapis.com/maps/api/js?callback=%%callback%%",this.version="3.39",this.language="",this.mapId=""}get libraryUrl(){return this.computeUrl(this.mapsUrl,this.version,this.apiKey,this.clientId,this.language,this.mapId)}get notifyEvent(){return"api-load"}computeUrl(t,e,i,s,o,r){let a=`${t}&v=${e}`;if(a+="&libraries=drawing,geometry,places,visualization,marker",i&&!s&&(a+=`&key=${i}`),s&&(a+=`&client=${s}`),!i&&!s){const t="No Google Maps API Key or Client ID specified. See https://developers.google.com/maps/documentation/javascript/get-api-key for instructions to get started with a key or client id.";console.warn(t)}return o&&(a+=`&language=${o}`),r&&(a+=`&map_ids=${r}`),a}};t([r({type:String,attribute:"api-key"}),e("design:type",Object)],u.prototype,"apiKey",void 0),t([r({type:String,attribute:"client-id"}),e("design:type",Object)],u.prototype,"clientId",void 0),t([r({type:String,attribute:"maps-url"}),e("design:type",Object)],u.prototype,"mapsUrl",void 0),t([r({type:String}),e("design:type",Object)],u.prototype,"version",void 0),t([r({type:String}),e("design:type",Object)],u.prototype,"language",void 0),t([r({type:String,attribute:"map-id"}),e("design:type",Object)],u.prototype,"mapId",void 0),u=t([a("lit-google-maps-api")],u);class m{constructor(t){this.multi=!1,this.selection=[],this.selectCallback=t}get(){return this.multi?this.selection.slice():this.selection[0]}clear(t){for(const e of this.selection.slice())(!t||t.indexOf(e)<0)&&this.setItemSelected(e,!1)}isSelected(t){return this.selection.indexOf(t)>=0}setItemSelected(t,e){if(null!=t&&e!==this.isSelected(t)){if(e)this.selection.push(t);else{const e=this.selection.indexOf(t);e>=0&&this.selection.splice(e,1)}this.selectCallback&&this.selectCallback(t,e)}}select(t){this.multi?this.toggle(t):this.get()!==t&&(this.setItemSelected(this.get(),!1),this.setItemSelected(t,!0))}toggle(t){this.setItemSelected(t,!this.isSelected(t))}}let y=class extends s{constructor(){super(...arguments),this.activateEvent="tap",this.selectedAttribute=null,this.selected=null,this._selection=new m(((t,e)=>this.applySelection(t,e))),this._items=[]}get items(){return this._items}connectedCallback(){super.connectedCallback(),this.addEventListener("slotchange",(t=>{t.stopPropagation(),this.updateItems(),this.dispatchEvent(new CustomEvent("selector-items-changed",{detail:{},composed:!0}))})),this.addListener(this.activateEvent)}disconnectedCallback(){super.disconnectedCallback(),this.removeListener(this.activateEvent)}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback(t,e,i),"selected"===t)this.updateSelected()}applySelection(t,e){this.selectedAttribute&&t instanceof Element&&e!==t.hasAttribute(this.selectedAttribute)&&t.toggleAttribute(this.selectedAttribute)}updateItems(){var t;const e=this.querySelector("slot");this._items=null!==(t=null==e?void 0:e.assignedNodes())&&void 0!==t?t:[]}addListener(t){this.addEventListener(t,(t=>this.activateHandler(t)))}removeListener(t){this.removeEventListener(t,(t=>this.activateHandler(t)))}activateHandler(t){let e=t.target;const i=this.items;for(;e&&e!==this;){const t=i.indexOf(e);if(t>=0){const i=this.indexToValue(t);return void this.itemActivate(i,e)}e=e.parentNode}}itemActivate(t,e){this.dispatchEvent(new CustomEvent("selector-item-activate",{detail:{selected:t,item:e},composed:!0,cancelable:!0}))&&this.select(t)}select(t){this.selected=t}updateSelected(){this.selectSelected(this.selected)}selectSelected(t){if(!this._items)return;const e=this.valueToItem(this.selected);e?this._selection.select(e):this._selection.clear()}valueToItem(t){return null==t?null:this._items[this.valueToIndex(t)]}valueToIndex(t){return Number(t)}indexToValue(t){return t}indexOf(t){return this._items?this._items.indexOf(t):-1}};t([r({type:String,attribute:"activate-event"}),e("design:type",Object)],y.prototype,"activateEvent",void 0),t([r({type:String,attribute:"selected-attribute"}),e("design:type",String)],y.prototype,"selectedAttribute",void 0),t([r({type:Number,reflect:!0}),e("design:type",Object)],y.prototype,"selected",void 0),y=t([a("lit-selector")],y);export{n as LitGoogleMap,l as LitGoogleMapCircle,p as LitGoogleMapMarker,h as LitGoogleMapPolygon,u as LitGoogleMapsApi,y as LitSelector};
+ `,t([a({type:String,attribute:"api-key"}),e("design:type",Object)],n.prototype,"apiKey",void 0),t([a({type:String}),e("design:type",Object)],n.prototype,"version",void 0),t([a({type:Object}),e("design:type",Object)],n.prototype,"styles",void 0),t([a({type:Number}),e("design:type",Object)],n.prototype,"zoom",void 0),t([a({type:Boolean,attribute:"fit-to-markers"}),e("design:type",Object)],n.prototype,"fitToMarkers",void 0),t([a({type:String,attribute:"map-type"}),e("design:type",Object)],n.prototype,"mapType",void 0),t([a({type:Number,attribute:"center-latitude"}),e("design:type",Object)],n.prototype,"centerLatitude",void 0),t([a({type:Number,attribute:"center-longitude"}),e("design:type",Object)],n.prototype,"centerLongitude",void 0),t([a({type:String}),e("design:type",Object)],n.prototype,"language",void 0),t([a({type:String,attribute:"map-id"}),e("design:type",Object)],n.prototype,"mapId",void 0),n=t([r("lit-google-map")],n);let l=class extends s{constructor(){super(...arguments),this.centerLatitude=-34.397,this.centerLongitude=150.644,this.radius=1e5,this.fillColor="#FF0000",this.fillOpacity=.35,this.strokeColor="#FF0000",this.strokeOpacity=.8,this.strokeWeight=2,this.map=null,this.circle=null}attributeChangedCallback(t,e,i){var s;switch(super.attributeChangedCallback(t,e,i),t){case"center-latitude":case"center-longitude":this.updateCenter();break;case"radius":null===(s=this.circle)||void 0===s||s.setRadius(this.radius)}}updateCenter(){var t;null===(t=this.circle)||void 0===t||t.setCenter(new google.maps.LatLng(this.centerLatitude,this.centerLongitude))}attachToMap(t){this.map=t,this.mapChanged()}mapChanged(){this.circle&&(this.circle.setMap(null),google.maps.event.clearInstanceListeners(this.circle)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.circle=new google.maps.Circle({map:this.map,strokeColor:this.strokeColor,strokeOpacity:this.strokeOpacity,strokeWeight:this.strokeWeight,fillColor:this.fillColor,fillOpacity:this.fillOpacity,center:{lat:this.centerLatitude,lng:this.centerLongitude},radius:this.radius})}};t([a({type:Number,attribute:"center-latitude"}),e("design:type",Object)],l.prototype,"centerLatitude",void 0),t([a({type:Number,attribute:"center-longitude"}),e("design:type",Object)],l.prototype,"centerLongitude",void 0),t([a({type:Number}),e("design:type",Object)],l.prototype,"radius",void 0),t([a({type:String,attribute:"fill-color"}),e("design:type",Object)],l.prototype,"fillColor",void 0),t([a({type:Number,attribute:"fill-opacity"}),e("design:type",Object)],l.prototype,"fillOpacity",void 0),t([a({type:String,attribute:"stroke-color"}),e("design:type",Object)],l.prototype,"strokeColor",void 0),t([a({type:Number,attribute:"stroke-opacity"}),e("design:type",Object)],l.prototype,"strokeOpacity",void 0),t([a({type:Number,attribute:"stroke-weight"}),e("design:type",Object)],l.prototype,"strokeWeight",void 0),l=t([r("lit-google-map-circle")],l);let p=class extends s{constructor(){super(...arguments),this.latitude=0,this.longitude=0,this.zIndex=0,this.open=!1,this.id=null,this.glyph=null,this.glyphColor=null,this.background=null,this.borderColor=null,this.scale=null,this.map=null,this.marker=null,this.pin=null}attributeChangedCallback(t,e,i){switch(super.attributeChangedCallback(t,e,i),t){case"open":this.openChanged();break;case"latitude":case"longitude":this.updatePosition();break;case"glyph":this.pin&&(this.pin.glyph=this.glyph);break;case"glyphColor":this.pin&&(this.pin.glyphColor=this.glyphColor);break;case"background":this.pin&&(this.pin.background=this.background);break;case"borderColor":this.pin&&(this.pin.borderColor=this.borderColor);break;case"scale":this.pin&&(this.pin.scale=this.scale);break;case"z-index":this.marker&&(this.marker.zIndex=this.zIndex)}}openChanged(){this.info&&(this.open?(this.info.open(this.map,this.marker),this.dispatchEvent(new CustomEvent("google-map-marker-open",{bubbles:!0}))):(this.info.close(),this.dispatchEvent(new CustomEvent("google-map-marker-close",{bubbles:!0}))))}updatePosition(){this.marker&&(this.marker.position=new google.maps.LatLng(this.latitude,this.longitude))}changeMap(t){this.map=t,this.mapChanged()}mapChanged(){this.marker&&(this.marker.map=null,google.maps.event.clearInstanceListeners(this.marker)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.pin=new google.maps.marker.PinElement({glyph:this.glyph,glyphColor:this.glyphColor,background:this.background,borderColor:this.borderColor,scale:this.scale}),this.marker=new google.maps.marker.AdvancedMarkerElement({map:this.map,position:{lat:this.latitude,lng:this.longitude},content:this.pin.element,zIndex:this.zIndex,gmpClickable:!0}),this.marker.element.addEventListener("mouseover",(()=>{this.dispatchEvent(new CustomEvent("mouseover",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.marker.element.addEventListener("mouseout",(()=>{this.dispatchEvent(new CustomEvent("mouseout",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.marker.addListener("click",(()=>{this.dispatchEvent(new CustomEvent("click",{detail:{id:this.id},bubbles:!0,composed:!0}))})),this.contentChanged()}contentChanged(){this.contentObserver&&this.contentObserver.disconnect(),this.contentObserver=new MutationObserver(this.contentChanged.bind(this)),this.contentObserver.observe(this,{childList:!0,subtree:!0});const t=this.innerHTML.trim();t?(this.info||(this.info=new google.maps.InfoWindow,this.openInfoHandler=google.maps.event.addListener(this.marker,"click",function(){this.open=!0}.bind(this)),this.closeInfoHandler=google.maps.event.addListener(this.info,"closeclick",function(){this.open=!1}.bind(this))),this.info.setContent(t)):this.info&&(google.maps.event.removeListener(this.openInfoHandler),google.maps.event.removeListener(this.closeInfoHandler),this.info=null)}};t([a({type:Number,reflect:!0}),e("design:type",Object)],p.prototype,"latitude",void 0),t([a({type:Number,reflect:!0}),e("design:type",Object)],p.prototype,"longitude",void 0),t([a({type:Number,reflect:!0,attribute:"z-index"}),e("design:type",Object)],p.prototype,"zIndex",void 0),t([a({type:Boolean,reflect:!0}),e("design:type",Object)],p.prototype,"open",void 0),t([a({type:String,reflect:!0}),e("design:type",String)],p.prototype,"id",void 0),t([a({type:String,reflect:!0}),e("design:type",String)],p.prototype,"glyph",void 0),t([a({type:String,reflect:!0}),e("design:type",String)],p.prototype,"glyphColor",void 0),t([a({type:String,reflect:!0}),e("design:type",String)],p.prototype,"background",void 0),t([a({type:String,reflect:!0}),e("design:type",String)],p.prototype,"borderColor",void 0),t([a({type:Number,reflect:!0}),e("design:type",Number)],p.prototype,"scale",void 0),p=t([r("lit-google-map-marker")],p);let h=class extends s{constructor(){super(...arguments),this.paths=[],this.fillColor="#FF0000",this.fillOpacity=.35,this.strokeColor="#FF0000",this.strokeOpacity=.8,this.strokeWeight=2,this.map=null,this.polygon=null}attachToMap(t){this.map=t,this.mapChanged()}mapChanged(){this.polygon&&(this.polygon.setMap(null),google.maps.event.clearInstanceListeners(this.polygon)),this.map&&this.map instanceof google.maps.Map&&this.mapReady()}mapReady(){this.polygon=new google.maps.Polygon({map:this.map,strokeColor:this.strokeColor,strokeOpacity:this.strokeOpacity,strokeWeight:this.strokeWeight,fillColor:this.fillColor,fillOpacity:this.fillOpacity,paths:this.paths})}};t([a({type:Array}),e("design:type",Array)],h.prototype,"paths",void 0),t([a({type:String,attribute:"fill-color"}),e("design:type",Object)],h.prototype,"fillColor",void 0),t([a({type:Number,attribute:"fill-opacity"}),e("design:type",Object)],h.prototype,"fillOpacity",void 0),t([a({type:String,attribute:"stroke-color"}),e("design:type",Object)],h.prototype,"strokeColor",void 0),t([a({type:Number,attribute:"stroke-opacity"}),e("design:type",Object)],h.prototype,"strokeOpacity",void 0),t([a({type:Number,attribute:"stroke-weight"}),e("design:type",Object)],h.prototype,"strokeWeight",void 0),h=t([r("lit-google-map-polygon")],h);class c{constructor(){this.apiMap={}}require(t,e,i){const s=this.nameFromUrl(t);this.apiMap[s]||(this.apiMap[s]=new d(s,t,i)),this.apiMap[s].requestNotify(e)}static getInstance(){return c.instance||(c.instance=new c),c.instance}nameFromUrl(t){return`${t.replace(/[:/%?&.=\-,]/g,"_")}_api`}}class d{constructor(t,e,i){this.callbackMacro="%%callback%%",this.loaded=!1,this.script=null,this.notifiers=[];let s=e,o=i;if(!o){if(!(s.indexOf(this.callbackMacro)>=0))return void console.error("ScriptLoader class: a %%callback%% parameter is required in libraryUrl");o=`${t}_loaded`,s=s.replace(this.callbackMacro,o)}this.callbackName=o,window[this.callbackName]=this.success.bind(this),this.addScript(s)}addScript(t){const e=document.createElement("script");e.src=t,e.onerror=this.handleError.bind(this);const i=document.querySelector("script")||document.body;i.parentNode.insertBefore(e,i),this.script=e}removeScript(){this.script.parentNode&&this.script.parentNode.removeChild(this.script),this.script=null}handleError(t){this.error=new Error("Library failed to load"),this.notifyAll(),this.cleanup()}success(...t){this.loaded=!0,this.result=t,this.notifyAll(),this.cleanup()}cleanup(){delete window[this.callbackName]}notifyAll(){this.notifiers.forEach(function(t){t(this.error,this.result)}.bind(this)),this.notifiers=[]}requestNotify(t){this.loaded||this.error?t(this.error,this.result):this.notifiers.push(t)}}class g extends s{constructor(){super(...arguments),this.libraryLoaded=!1,this.libraryErrorMessage=null,this.isReady=!1}get callbackName(){return null}libraryUrlChanged(){this.isReady&&null!=this.libraryUrl&&this.loadLibrary()}libraryLoadCallback(t,e){t?(console.warn("Library load failed:",t.message),this.libraryErrorMessage=t.message):(this.libraryErrorMessage=null,this.libraryLoaded=!0,null!=this.notifyEvent&&this.dispatchEvent(new CustomEvent(this.notifyEvent,{detail:e,composed:!0})))}loadLibrary(){c.getInstance().require(this.libraryUrl,this.libraryLoadCallback.bind(this),this.callbackName)}connectedCallback(){super.connectedCallback(),this.isReady=!0,null!=this.libraryUrl&&this.loadLibrary()}}let u=class extends g{constructor(){super(...arguments),this.apiKey="",this.clientId="",this.mapsUrl="https://maps.googleapis.com/maps/api/js?callback=%%callback%%",this.version="3.39",this.language="",this.mapId=""}get libraryUrl(){return this.computeUrl(this.mapsUrl,this.version,this.apiKey,this.clientId,this.language,this.mapId)}get notifyEvent(){return"api-load"}computeUrl(t,e,i,s,o,a){let r=`${t}&v=${e}`;if(r+="&libraries=drawing,geometry,places,visualization,marker",i&&!s&&(r+=`&key=${i}`),s&&(r+=`&client=${s}`),!i&&!s){const t="No Google Maps API Key or Client ID specified. See https://developers.google.com/maps/documentation/javascript/get-api-key for instructions to get started with a key or client id.";console.warn(t)}return o&&(r+=`&language=${o}`),a&&(r+=`&map_ids=${a}`),r}};t([a({type:String,attribute:"api-key"}),e("design:type",Object)],u.prototype,"apiKey",void 0),t([a({type:String,attribute:"client-id"}),e("design:type",Object)],u.prototype,"clientId",void 0),t([a({type:String,attribute:"maps-url"}),e("design:type",Object)],u.prototype,"mapsUrl",void 0),t([a({type:String}),e("design:type",Object)],u.prototype,"version",void 0),t([a({type:String}),e("design:type",Object)],u.prototype,"language",void 0),t([a({type:String,attribute:"map-id"}),e("design:type",Object)],u.prototype,"mapId",void 0),u=t([r("lit-google-maps-api")],u);class m{constructor(t){this.multi=!1,this.selection=[],this.selectCallback=t}get(){return this.multi?this.selection.slice():this.selection[0]}clear(t){for(const e of this.selection.slice())(!t||t.indexOf(e)<0)&&this.setItemSelected(e,!1)}isSelected(t){return this.selection.indexOf(t)>=0}setItemSelected(t,e){if(null!=t&&e!==this.isSelected(t)){if(e)this.selection.push(t);else{const e=this.selection.indexOf(t);e>=0&&this.selection.splice(e,1)}this.selectCallback&&this.selectCallback(t,e)}}select(t){this.multi?this.toggle(t):this.get()!==t&&(this.setItemSelected(this.get(),!1),this.setItemSelected(t,!0))}toggle(t){this.setItemSelected(t,!this.isSelected(t))}}let y=class extends s{constructor(){super(...arguments),this.activateEvent="tap",this.selectedAttribute=null,this.selected=null,this._selection=new m(((t,e)=>this.applySelection(t,e))),this._items=[]}get items(){return this._items}connectedCallback(){super.connectedCallback(),this.addEventListener("slotchange",(t=>{t.stopPropagation(),this.updateItems(),this.dispatchEvent(new CustomEvent("selector-items-changed",{detail:{},composed:!0}))})),this.addListener(this.activateEvent)}disconnectedCallback(){super.disconnectedCallback(),this.removeListener(this.activateEvent)}attributeChangedCallback(t,e,i){if(super.attributeChangedCallback(t,e,i),"selected"===t)this.updateSelected()}applySelection(t,e){this.selectedAttribute&&t instanceof Element&&e!==t.hasAttribute(this.selectedAttribute)&&t.toggleAttribute(this.selectedAttribute)}updateItems(){var t;const e=this.querySelector("slot");this._items=null!==(t=null==e?void 0:e.assignedNodes())&&void 0!==t?t:[]}addListener(t){this.addEventListener(t,(t=>this.activateHandler(t)))}removeListener(t){this.removeEventListener(t,(t=>this.activateHandler(t)))}activateHandler(t){let e=t.target;const i=this.items;for(;e&&e!==this;){const t=i.indexOf(e);if(t>=0){const i=this.indexToValue(t);return void this.itemActivate(i,e)}e=e.parentNode}}itemActivate(t,e){this.dispatchEvent(new CustomEvent("selector-item-activate",{detail:{selected:t,item:e},composed:!0,cancelable:!0}))&&this.select(t)}select(t){this.selected=t}updateSelected(){this.selectSelected(this.selected)}selectSelected(t){if(!this._items)return;const e=this.valueToItem(this.selected);e?this._selection.select(e):this._selection.clear()}valueToItem(t){return null==t?null:this._items[this.valueToIndex(t)]}valueToIndex(t){return Number(t)}indexToValue(t){return t}indexOf(t){return this._items?this._items.indexOf(t):-1}};t([a({type:String,attribute:"activate-event"}),e("design:type",Object)],y.prototype,"activateEvent",void 0),t([a({type:String,attribute:"selected-attribute"}),e("design:type",String)],y.prototype,"selectedAttribute",void 0),t([a({type:Number,reflect:!0}),e("design:type",Object)],y.prototype,"selected",void 0),y=t([r("lit-selector")],y);export{n as LitGoogleMap,l as LitGoogleMapCircle,p as LitGoogleMapMarker,h as LitGoogleMapPolygon,u as LitGoogleMapsApi,y as LitSelector};
diff --git a/package.json b/package.json
index a6dbba8..5458154 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "lit-google-map",
- "version": "1.0.3",
+ "version": "0.0.4",
"description": "Google Maps web components based on Lit v2",
"private": false,
"license": "MIT",
diff --git a/src/lit-google-map-marker.ts b/src/lit-google-map-marker.ts
index d17d1bb..76ef0d9 100644
--- a/src/lit-google-map-marker.ts
+++ b/src/lit-google-map-marker.ts
@@ -33,12 +33,6 @@ export class LitGoogleMapMarker extends LitElement {
@property({ type: Number, reflect: true })
scale: number = null;
- /**
- * If set, the marker will not be used to calculate the map's bounds.
- */
- @property({ type: Boolean, attribute: "omit-from-fit" })
- omitFromFit = false;
-
map: google.maps.Map = null;
marker: google.maps.marker.AdvancedMarkerElement = null;
pin: google.maps.marker.PinElement = null;
diff --git a/src/lit-google-map.ts b/src/lit-google-map.ts
index 6405b23..ae193fb 100644
--- a/src/lit-google-map.ts
+++ b/src/lit-google-map.ts
@@ -64,6 +64,35 @@ export class LitGoogleMap extends LitElement {
markerObserverSet: boolean;
+ attributeChangedCallback(name: string, oldValue: string, newValue: string) {
+ super.attributeChangedCallback(name, oldValue, newValue);
+
+ // Update map when center/zoom attributes change
+ if (this.map && oldValue !== newValue && newValue !== null) {
+ if (name === "center-latitude" || name === "center-longitude") {
+ this.map.setCenter({
+ lat: this.centerLatitude,
+ lng: this.centerLongitude,
+ });
+ } else if (name === "zoom") {
+ this.map.setZoom(this.zoom);
+ }
+ }
+ }
+
+ dispatchViewChanged() {
+ this.dispatchEvent(
+ new CustomEvent("view_changed", {
+ detail: {
+ center: this.map.getCenter().toJSON(),
+ zoom: this.map.getZoom(),
+ },
+ bubbles: true,
+ composed: true,
+ }),
+ );
+ }
+
initGMap() {
if (this.map != null) {
return; // already initialized
@@ -103,6 +132,28 @@ export class LitGoogleMap extends LitElement {
);
});
+ this.map.addListener("center_changed", () => {
+ this.dispatchEvent(
+ new CustomEvent("center_changed", {
+ detail: this.map.getCenter().toJSON(),
+ bubbles: true,
+ composed: true,
+ }),
+ );
+ this.dispatchViewChanged();
+ });
+
+ this.map.addListener("zoom_changed", () => {
+ this.dispatchEvent(
+ new CustomEvent("zoom_changed", {
+ detail: { zoom: this.map.getZoom() },
+ bubbles: true,
+ composed: true,
+ }),
+ );
+ this.dispatchViewChanged();
+ });
+
// https://developers.google.com/maps/documentation/javascript/examples/event-poi
this.map.addListener(
"click",
@@ -143,10 +194,36 @@ export class LitGoogleMap extends LitElement {
connectedCallback() {
super.connectedCallback();
-
this.initGMap();
}
+ updated(changedProperties: Map) {
+ super.updated(changedProperties);
+
+ // Update map center and zoom when properties change
+ if (this.map) {
+ if (
+ changedProperties.has("centerLatitude") ||
+ changedProperties.has("centerLongitude")
+ ) {
+ const _oldLat = changedProperties.get("centerLatitude");
+ const _oldLng = changedProperties.get("centerLongitude");
+
+ this.map.setCenter({
+ lat: this.centerLatitude,
+ lng: this.centerLongitude,
+ });
+ }
+
+ if (changedProperties.has("zoom")) {
+ const _oldZoom = changedProperties.get("zoom");
+ this.map.setZoom(this.zoom);
+ }
+ } else {
+ console.log("Map not initialized yet, skipping update");
+ }
+ }
+
attachChildrenToMap(children: Array) {
if (this.map) {
for (const child of children) {
@@ -222,12 +299,9 @@ export class LitGoogleMap extends LitElement {
}
fitToMarkersChanged(retryAttempt = 0) {
- const markers = this.markers.filter(
- (m) => !(m as LitGoogleMapMarker).omitFromFit,
- );
- if (this.map && this.fitToMarkers && markers.length > 0) {
+ if (this.map && this.fitToMarkers && this.markers.length > 0) {
const latLngBounds = new google.maps.LatLngBounds();
- for (const marker of markers) {
+ for (const marker of this.markers) {
latLngBounds.extend(
new google.maps.LatLng(
(marker as LitGoogleMapMarker).latitude,
@@ -249,7 +323,7 @@ export class LitGoogleMap extends LitElement {
}
// For one marker, don't alter zoom, just center it.
- if (markers.length > 1) {
+ if (this.markers.length > 1) {
this.map.fitBounds(latLngBounds, 0);
}
this.map.setCenter(latLngBounds.getCenter());
@@ -258,20 +332,12 @@ export class LitGoogleMap extends LitElement {
checkBoundsChanged(oldMarkers: Array, newMarkers: Array) {
const addedInBounds = newMarkers.filter((m) => {
- return (
- // skip items that are omitted from fit
- !(m as LitGoogleMapMarker).omitFromFit &&
- // if we have no markers, or the item wasn't there before, the bounds need to be updated
- (!oldMarkers || !oldMarkers.includes(m))
- );
+ // if we have no markers, or the item wasn't there before, the bounds need to be updated
+ return !oldMarkers || !oldMarkers.includes(m);
});
const removedInBounds = oldMarkers?.filter((m) => {
- return (
- // skip items that are omitted from fit
- !(m as LitGoogleMapMarker).omitFromFit &&
- // if we have no markers, or the item isn't there anymore, the bounds need to be updated
- (!newMarkers || !newMarkers.includes(m))
- );
+ // if we have no markers, or the item isn't there anymore, the bounds need to be updated
+ return !newMarkers || !newMarkers.includes(m);
});
return addedInBounds.length > 0 || removedInBounds.length > 0;