← Back
Editing: Map.a24dd248.js
var m=Object.defineProperty;var u=(t,e,a)=>e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a;var o=(t,e,a)=>u(t,typeof e!="symbol"?e+"":e,a);import{b as f,e as g,l as k,u as b}from"./index.44a18132.js";import{f as y,M as w,o as l,c,a as p,j as _,b as h}from"./runtime-dom.esm-bundler.647fa2bb.js";import"./translations.d159963e.js";import{_ as M}from"./_plugin-vue_export-helper.eefbdd86.js";import{i as v}from"./isEqual.3170db16.js";import{t as I}from"./toString.98bc71ed.js";import{_ as S}from"./default-i18n.20001971.js";var x=0;function d(t){var e=++x;return I(t)+e}const V=()=>({getDataObject:y(()=>{var i,r;const e=w(),a=f(),s=g();return((r=(i=e==null?void 0:e.root)==null?void 0:i.data)==null?void 0:r.screenContext)==="metabox"?s.currentPost.local_seo.maps:a.options.localBusiness.maps})});function Y(t,e,a){if(!t||!e)return Promise.resolve(!1);switch(e){case"places/embed":return a.post(k.restUrl("local-business/maps/check-api-enabled")).send({apiKey:t,apiName:e}).then(s=>s.statusCode===200).catch(s=>!1);default:return Promise.resolve(!1)}}async function B(t,e,a){if(!(t!=null&&t.maps))return!1;let s=null;switch(e){case"places":return t.maps.places?(s=new t.maps.places.AutocompleteService,new Promise(i=>{s.getQueryPredictions({input:a||"NYC"},function(r,n){i(n===t.maps.places.PlacesServiceStatus.OK)})})):!1;case"geocoder":return s=new t.maps.Geocoder,new Promise(i=>{s.geocode({address:a||"NYC"},function(r,n){n===t.maps.GeocoderStatus.OK&&i({enabled:!0,result:r[0].geometry.location}),i({enabled:!1})})});default:return!1}}class L{constructor({apiKey:e,version:a,libraries:s}){o(this,"url","https://maps.googleapis.com/maps/api/js");o(this,"scriptId","localseo-maps-script");o(this,"loading",!1);o(this,"googleMapCallback","aioseoGoogleMapsLoaded");o(this,"callbacks",[]);this.apiKey=e,this.version=a||"weekly",this.libraries=s||[]}createUrl(){let e=this.url;return e+=`?callback=${this.googleMapCallback}`,this.apiKey&&(e+=`&key=${this.apiKey}`),0<this.libraries.length&&(e+=`&libraries=${this.libraries.join(",")}`),0<this.libraries.length&&(e+=`&libraries=${this.libraries.join(",")}`),this.version&&(e+=`&v=${this.version}`),e}async load(){return new Promise((e,a)=>{this.loadCallback(s=>{s?a(s):e(window.google)})})}loadCallback(e){this.callbacks.push(e),this.execute()}setCallback(){window.aioseoGoogleMapsLoaded=this.callback.bind(this)}callback(){this.loading=!1,this.callbacks.forEach(e=>{e(this.onerrorEvent)}),this.callbacks=[]}setScript(){this.reset();const e=this.createUrl(),a=document.createElement("script");a.id=this.scriptId,a.type="text/javascript",a.src=e,a.onerror=this.loadErrorCallback.bind(this),a.defer=!0,a.async=!0,this.nonce&&(a.nonce=this.nonce),document.head.appendChild(a)}loadErrorCallback(e){this.onerrorEvent=e,this.callback()}reset(){this.deleteScript(),window.google&&window.google.maps&&(window.google.maps=null)}deleteScript(){const e=document.getElementById(this.scriptId);e&&e.remove()}execute(){this.setCallback(),this.setScript()}}const C="aioseo-pro",E={emits:["zoom-changed","marker-position-changed","map-loaded","places-library-available","place-information","click"],setup(){return{rootStore:b()}},props:{apiKey:String,options:Object,marker:Object,placeId:String,address:String,searchBox:{type:Boolean,default(){return!1}},preventInteraction:{type:Boolean,default(){return!1}},watchOptions:{type:Boolean,default(){return!1}}},data(){return{mapDivId:null,mapSearchBoxId:null,google:null,map:null,mapMarker:null,loader:null,placesLibraryAvailable:!1,strings:{map:S("Map",C)}}},watch:{marker(){this.mapMarker&&this.changeIcon(this.marker.icon)},"options.mapTypeId":{handler:function(){this.map.setOptions(this.options)}},apiKey(){this.loadMap()}},methods:{createMap(){this.map=new this.google.maps.Map(document.getElementById(this.mapDivId),this.options),this.map.addListener("zoom_changed",()=>{this.$emit("zoom-changed",this.map.getZoom())}),this.map.addListener("click",t=>{this.$emit("click",t),this.mapMarker&&(t.placeId?this.removeMarker():this.createMarker(t.latLng),this.placeInformation(t))})},createSearchBox(){if(!this.searchBox)return;const t=document.getElementById(this.mapSearchBoxId),e=new this.google.maps.places.SearchBox(t);this.map.controls[this.google.maps.ControlPosition.TOP_LEFT].push(t),e.addListener("places_changed",()=>{const a=e.getPlaces();if(a.length===0)return;this.removeMarker();const s=new this.google.maps.LatLngBounds;a.forEach(i=>{if(!i.geometry||!i.geometry.location){console.warn("Returned place contains no geometry");return}this.createMarker(i.geometry.location),i.geometry.viewport?s.union(i.geometry.viewport):s.extend(i.geometry.location)}),this.map.fitBounds(s)})},changeIcon(t){if(!t){this.mapMarker.setIcon(null);return}this.mapMarker.setIcon({url:t,size:new this.google.maps.Size(25,25),origin:new this.google.maps.Point(0,0),anchor:new this.google.maps.Point(17,34),scaledSize:new this.google.maps.Size(25,25)})},createMarker(t,e=!1){this.mapMarker||(this.mapMarker=new this.google.maps.Marker({map:this.map,draggable:!0}),this.mapMarker.addListener("position_changed",()=>{this.placeInformation({latLng:this.mapMarker.getPosition()}),this.$emit("marker-position-changed",this.mapMarker.getPosition())})),t&&(this.mapMarker.setPosition(t),e&&this.map.setCenter(t)),this.changeIcon(this.marker.icon),this.mapMarker.setMap(this.map)},removeMarker(){this.mapMarker&&this.mapMarker.setMap(null)},loadMap(){(typeof window.google<"u"&&typeof window.google.maps<"u"&&typeof window.google.maps.plugins<"u"&&typeof window.google.maps.plugins.loader<"u"?new window.google.maps.plugins.loader.Loader({apiKey:this.apiKey,libraries:["places"]}):new L({apiKey:this.apiKey,libraries:["places"]})).load().then(e=>{this.google=e,this.createMap(),this.createMarker(),!this.placeId&&this.marker&&this.createMarker(this.marker.position),this.libraryEnabled("places").then(a=>{this.$emit("places-library-available",a),a&&(this.placesLibraryAvailable=!0,this.createSearchBox())}),this.$emit("map-loaded"),this.placeInformation({placeId:this.placeId,latLng:this.marker.position})})},placeInformation(t){typeof t.latLng<"u"&&typeof t.latLng.lat=="function"&&(t.latLng=t.latLng.toJSON()),this.$emit("place-information",t)},libraryEnabled(t,e){return B(this.google,t,e)},isMarkerDefault(){return this.marker&&v(this.marker.position,this.rootStore.aioseo.localBusiness.mapDefaults.center)}},mounted(){this.apiKey&&(this.mapDivId=d("map_"),this.mapSearchBoxId=d("search_box_"),this.loadMap())}},P={class:"mapBox"},K=["id"],O=["id"],$={key:1,class:"preventInteraction"};function j(t,e,a,s,i,r){return l(),c("div",null,[p("div",P,[a.searchBox?(l(),c("input",{key:0,class:"searchInput",id:i.mapSearchBoxId,style:_({display:i.placesLibraryAvailable?"block":"none"})},null,12,K)):h("",!0),p("div",{id:i.mapDivId,class:"map"},null,8,O),a.preventInteraction?(l(),c("div",$)):h("",!0)])])}const q=M(E,[["render",j],["__scopeId","data-v-9a86271f"]]);export{q as C,Y as i,V as u};
Save File
Cancel