UNPKG

vicowa-web-components

Version:
2 lines 3.29 kB
import{WebComponentBaseClass as t}from"/third_party/web-component-base-class/dist/web-component-base-class.js";import"../vicowa-string/vicowa-string.js";import"../vicowa-icon/vicowa-icon.js";import e from"../utilities/translate.js";const i=[];window.customElements.define("vicowa-google-maps",class VicowaGoogleMaps extends t{#t;#e;#i;#a;constructor(){super(),this.#t=null,this.#e=[],this.#i=[]}static get properties(){return{latitude:{type:Number,value:58.8282216,reflectToAttribute:!0,observer:t=>t.#o()},longitude:{type:Number,value:-112.261819,reflectToAttribute:!0,observer:t=>t.#o()},zoom:{type:Number,value:0,reflectToAttribute:!0,observer:t=>t.#s()},marker:{type:String,value:"",reflectToAttribute:!0,observer:t=>t.#o()},info:{type:String,value:"",reflectToAttribute:!0,observer:t=>t.#o()},type:{type:String,value:"roadmap",reflectToAttribute:!0,observer:t=>t.#n()},apiKey:{type:String,value:"",reflectToAttribute:!1,observer:t=>t.#r()}}}addMarker(t,e,i,a){this.#p((o=>{const s=new window.google.maps.Marker({position:new window.google.maps.LatLng(e,i),map:o,title:a});this.#e.push({marker:s,title:a}),t&&t(s)}))}addInfo(t,e,i,a){this.#p((o=>{const s=new window.google.maps.InfoWindow({content:e});this.#i.push({info:s,content:e}),this.updateTranslation(),s&&"number"!=typeof i?s.open(o,i):i&&a&&(s.setPosition(new window.google.maps.LatLng(i,a)),s.open(o)),t&&t(s)}))}updateTranslation(){this.#e.forEach((t=>{t.marker.setTitle(this.#t.translate(t.title).fetch())})),this.#i.forEach((t=>{t.info.setContent(this.#t.translate(t.content).fetch())}))}detached(){e.removeTranslationUpdatedObserverOwner(this)}attached(){this.#r(),e.addTranslationUpdatedObserver((t=>{this.#t=t,this.updateTranslation()}),this)}#p(t){if(this.#a)t(this.#a);else{const e=()=>{if(window.google.maps.LatLng){const e=new window.google.maps.LatLng(this.latitude,this.longitude);this.#a=new window.google.maps.Map(this.$.map,{zoom:Math.max(0,this.zoom),center:e,mapTypeId:this.type}),this.marker&&this.addMarker((t=>{this.info&&this.addInfo(null,this.info||this.marker,t)}),this.latitude,this.longitude,this.marker),this.#a&&t(this.#a)}};"google"in window&&window.google.maps&&window.google.maps.LatLng?e():i.push((()=>{this.#a?t(this.#a):e()}))}}#o(){this.#p((t=>{const e=new window.google.maps.LatLng(this.latitude,this.longitude);t&&t.panTo(e)}))}#s(){this.#p((t=>{t&&t.setZoom(Math.max(0,this.zoom))}))}#n(){this.#p((t=>{t&&this.type in["roadmap","satellite","hybrid","terrain"]&&t.setMapTypeId(this.type)}))}#r(){if("google"in window)this.#o();else{let t=document.querySelector('head script[src*="https://maps.googleapis.com"]');if(i.push((()=>{this.#o()})),this.apiKey&&!t){const e=()=>{i.forEach((t=>{t()}))};"google"in window?e():(t||(t=document.createElement("script"),t.src=`https://maps.googleapis.com/maps/api/js?key=${this.apiKey}`,document.querySelector("head").appendChild(t),t.onload=()=>{t.notifyList.forEach((t=>{t()}))},t.notifyList=t.notifyList||[]),t.notifyList.push(e))}}}static get template(){return'\n\t\t\t<style>\n\t\t\t\t:host {\n\t\t\t\t\tdisplay: block;\n\t\t\t\t}\n\t\t\t\n\t\t\t\t#map {\n\t\t\t\t\tposition: relative;\n\t\t\t\t\twidth: 100%;\n\t\t\t\t\theight: 100%;\n\t\t\t\t}\n\t\t\t</style>\n\t\t\t<div id="map"></div>\n\t\t'}}); //# sourceMappingURL=vicowa-google-maps.js.map