@advisr/v-mapbox
Version:
Mapbox with Vue 💚
8 lines (7 loc) • 28.8 kB
JavaScript
/*!
* @advisr/v-mapbox v1.12.0
* (c) 2022 GeoSpoc Dev Team
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("map-promisified")):"function"==typeof define&&define.amd?define(["exports","vue","map-promisified"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VMapbox={},e.vue,e.mapPromisified)}(this,(function(e,t,i){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t),a=r(i),s=["mousedown","mouseup","click","dblclick","mousemove","mouseenter","mouseleave","mouseover","mouseout","contextmenu","touchstart","touchend","touchcancel"],n=o.default.extend({methods:{$_emitEvent(e,t={}){this.$emit(e,{map:this.map,component:this,...t})},$_emitMapEvent(e,t={}){this.$_emitEvent(e.type,{mapboxEvent:e,...t})}}});const d={sourceId:{type:String,required:!0},source:{type:[Object,String],default:void 0}},l={layerId:{type:String,required:!0},layer:{type:Object,required:!0},before:{type:String,default:void 0}},h={clearSource:{type:Boolean,default:!0},replaceSource:{type:Boolean,default:!1},replace:{type:Boolean,default:!1}};var u=o.default.extend({mixins:[n],inject:["mapbox","map"],props:{...d,...l,...h},data:()=>({initial:!0}),computed:{sourceLoaded(){return!!this.map&&this.map.isSourceLoaded(this.sourceId)},mapLayer(){return this.map?this.map.getLayer(this.layerId):null},mapSource(){return this.map?this.map.getSource(this.sourceId):null}},watch:{before(e,t){e!==t&&this.move(e)}},created(){this.layer.minzoom&&this.$watch("layer.minzoom",(function(e){this.initial||this.map.setLayerZoomRange(this.layerId,e,this.layer.maxzoom)})),this.layer.maxzoom&&this.$watch("layer.maxzoom",(function(e){this.initial||this.map.setLayerZoomRange(this.layerId,this.layer.minzoom,e)})),this.layer.paint&&this.$watch("layer.paint",(function(e){if(!this.initial&&e)for(const t of Object.keys(e))this.map.setPaintProperty(this.layerId,t,e[t])}),{deep:!0}),this.layer.layout&&this.$watch("layer.layout",(function(e){if(!this.initial&&e)for(const t of Object.keys(e))this.map.setLayoutProperty(this.layerId,t,e[t])}),{deep:!0}),this.layer.filter&&this.$watch("layer.filter",(function(e){this.initial||this.map.setFilter(this.layerId,e)}),{deep:!0})},beforeDestroy(){if(this.map&&this.map.loaded()){try{this.map.removeLayer(this.layerId)}catch(e){this.$_emitEvent("layer-does-not-exist",{layerId:this.sourceId,error:e})}if(this.clearSource)try{this.map.removeSource(this.sourceId)}catch(e){this.$_emitEvent("source-does-not-exist",{sourceId:this.sourceId,error:e})}}},methods:{$_emitLayerMapEvent(e){return this.$_emitMapEvent(e,{layerId:this.layerId})},$_bindLayerEvents(e){Object.keys(this.$listeners).forEach((t=>{e.includes(t)&&this.map.on(t,this.layerId,this.$_emitLayerMapEvent)}))},$_unbindEvents(e){this.map&&e.forEach((e=>{this.map.off(e,this.layerId,this.$_emitLayerMapEvent)}))},$_watchSourceLoading(e){"source"===e.dataType&&e.sourceId===this.sourceId&&(this.$_emitEvent("layer-source-loading",{sourceId:this.sourceId}),this.map.off("dataloading",this.$_watchSourceLoading))},move(e){this.map.moveLayer(this.layerId,e),this.$_emitEvent("layer-moved",{layerId:this.layerId,beforeId:e})},remove(){this.map.removeLayer(this.layerId),this.map.removeSource(this.sourceId),this.$_emitEvent("layer-removed",{layerId:this.layerId}),this.$destroy()}},render(){}}),c=o.default.extend({name:"MglCanvasLayer",mixins:[u],inject:["mapbox","map"],props:{source:{type:Object,required:!0},layer:{type:Object,default:null}},computed:{canvasElement(){return this.mapSource?this.mapSource.getCanvas():null}},watch:{coordinates(e){this.initial||this.mapSource.setCoordinates(e)}},created(){this.$_deferredMount()},methods:{$_deferredMount(){const e={type:"canvas",...this.source};this.map.on("dataloading",this.$_watchSourceLoading);try{this.map.addSource(this.sourceId,e)}catch(t){this.replaceSource&&(this.map.removeSource(this.sourceId),this.map.addSource(this.sourceId,e))}this.$_addLayer(),this.$_bindLayerEvents(s),this.initial=!1},$_addLayer(){const e=this.map.getLayer(this.layerId);if(e){if(!this.replace)return this.$_emitEvent("layer-exists",{layerId:this.layerId}),e;this.map.removeLayer(this.layerId)}const t={id:this.layerId,source:this.sourceId,type:"raster",...this.layer};this.map.addLayer(t,this.before),this.$_emitEvent("added",{layerId:this.layerId,canvas:this.canvasElement})}}}),p=o.default.extend({name:"MglGeojsonLayer",mixins:[u],computed:{getSourceFeatures(){return e=>this.map?this.map.querySourceFeatures(this.sourceId,{filter:e}):null},getRenderedFeatures(){return(e,t)=>this.map?this.map.queryRenderedFeatures(e,{layers:[this.layerId],filter:t}):null},getClusterExpansionZoom(){return e=>new Promise(((t,i)=>{if(!this.mapSource)return i(new Error(`Map source with id ${this.sourceId} not found.`));this.mapSource.getClusterExpansionZoom(e,((e,r)=>e?i(e):t(r)))}))},getClusterChildren(){return e=>new Promise(((t,i)=>{const r=this.mapSource;if(!r)return i(new Error(`Map source with id ${this.sourceId} not found.`));r.getClusterChildren(e,((e,r)=>e?i(e):t(r)))}))},getClusterLeaves(){return(...e)=>new Promise(((t,i)=>{if(!this.mapSource)return i(new Error(`Map source with id ${this.sourceId} not found.`));this.mapSource.getClusterLeaves(...e,((e,r)=>e?i(e):t(r)))}))}},created(){this.source&&this.$watch("source.data",(function(e){this.initial||this.mapSource.setData(e)}),{deep:!0}),this.$_deferredMount()},methods:{$_deferredMount(){if(this.map.on("dataloading",this.$_watchSourceLoading),this.source){const e={type:"geojson",...this.source};try{this.map.addSource(this.sourceId,e)}catch(t){this.replaceSource&&(this.map.removeSource(this.sourceId),this.map.addSource(this.sourceId,e))}}this.$_addLayer(),this.$_bindLayerEvents(s),this.map.off("dataloading",this.$_watchSourceLoading),this.initial=!1},$_addLayer(){const e=this.map.getLayer(this.layerId);if(e){if(!this.replace)return this.$_emitEvent("layer-exists",{layerId:this.layerId}),e;this.map.removeLayer(this.layerId)}const t={id:this.layerId,source:this.sourceId,...this.layer};this.map.addLayer(t,this.before),this.$_emitEvent("added",{layerId:this.layerId})},setFeatureState(e,t){if(this.map){const i={id:e,source:this.source};return this.map.setFeatureState(i,t)}},getFeatureState(e){if(this.map){const t={id:e,source:this.source};return this.map.getFeatureState(t)}},removeFeatureState(e,t,i){if(this.map){const r={id:e,source:this.source,sourceLayer:t};return this.map.removeFeatureState(r,i)}}}}),m=o.default.extend({name:"MglImageLayer",mixins:[u],created(){this.source&&(this.source.coordinates&&this.$watch("source.coordinates",(function(e){this.initial||e&&this.mapSource.setCoordinates(e)}),{deep:!0}),this.source.url&&this.$watch("source.url",(function(e){this.initial||e&&this.mapSource.updateImage({url:e,coordinates:this.source.coordinates})}),{deep:!0})),this.$_deferredMount()},methods:{$_deferredMount(){const e={type:"image",...this.source};this.map.on("dataloading",this.$_watchSourceLoading);try{this.map.addSource(this.sourceId,e)}catch(t){this.replaceSource&&(this.map.removeSource(this.sourceId),this.map.addSource(this.sourceId,e))}this.$_addLayer(),this.$_bindLayerEvents(s),this.initial=!1},$_addLayer(){const e=this.map.getLayer(this.layerId);if(e){if(!this.replace)return this.$_emitEvent("layer-exists",{layerId:this.layerId}),e;this.map.removeLayer(this.layerId)}const t={id:this.layerId,source:this.sourceId,type:"raster",...this.layer};this.map.addLayer(t,this.before),this.$_emitEvent("added",{layerId:this.layerId})}}}),y=o.default.extend({name:"MglRasterLayer",mixins:[u],created(){this.$_deferredMount()},methods:{$_deferredMount(){const e={type:"raster",...this.source};this.map.on("dataloading",this.$_watchSourceLoading);try{this.map.addSource(this.sourceId,e)}catch(t){this.replaceSource&&(this.map.removeSource(this.sourceId),this.map.addSource(this.sourceId,e))}this.$_addLayer(),this.$_bindLayerEvents(s),this.map.off("dataloading",this.$_watchSourceLoading),this.initial=!1},$_addLayer(){const e=this.map.getLayer(this.layerId);if(e){if(!this.replace)return this.$_emitEvent("layer-exists",{layerId:this.layerId}),e;this.map.removeLayer(this.layerId)}const t={id:this.layerId,type:"raster",source:this.sourceId,...this.layer};this.map.addLayer(t,this.before),this.$_emitEvent("added",{layerId:this.layerId})}}}),f=o.default.extend({name:"MglVectorLayer",mixins:[u],computed:{getSourceFeatures(){return e=>this.map?this.map.querySourceFeatures(this.sourceId,{sourceLayer:this.layer["source-layer"],filter:e}):null},getRenderedFeatures(){return(e,t)=>this.map?this.map.queryRenderedFeatures(e,{layers:[this.layerId],filter:t}):null}},watch:{filter(e){this.initial||this.map.setFilter(this.layerId,e)}},created(){this.$_deferredMount()},methods:{$_deferredMount(){const e={type:"vector",...this.source};this.map.on("dataloading",this.$_watchSourceLoading);try{this.map.addSource(this.sourceId,e)}catch(t){this.replaceSource&&(this.map.removeSource(this.sourceId),this.map.addSource(this.sourceId,e))}this.$_addLayer(),this.$_bindLayerEvents(s),this.map.off("dataloading",this.$_watchSourceLoading),this.initial=!1},$_addLayer(){const e=this.map.getLayer(this.layerId);if(e){if(!this.replace)return this.$_emitEvent("layer-exists",{layerId:this.layerId}),e;this.map.removeLayer(this.layerId)}const t={id:this.layerId,source:this.sourceId,...this.layer};this.map.addLayer(t,this.before),this.$_emitEvent("added",{layerId:this.layerId})},setFeatureState(e,t){if(this.map){const i={id:e,source:this.sourceId,"source-layer":this.layer["source-layer"]};return this.map.setFeatureState(i,t)}},getFeatureState(e){if(this.map){const t={id:e,source:this.source,"source-layer":this.layer["source-layer"]};return this.map.getFeatureState(t)}}}}),v=o.default.extend({name:"MglVideoLayer",mixins:[u],computed:{video(){return this.map.getSource(this.sourceId).getVideo()}},created(){this.source&&this.source.coordinates&&this.$watch("source.coordinates",(function(e){this.initial||this.mapSource.setCoordinates(e)})),this.$_deferredMount()},methods:{$_deferredMount(){const e={type:"video",...this.source};this.map.on("dataloading",this.$_watchSourceLoading);try{this.map.addSource(this.sourceId,e)}catch(t){this.replaceSource&&(this.map.removeSource(this.sourceId),this.map.addSource(this.sourceId,e))}this.$_addLayer(),this.$_bindLayerEvents(s),this.initial=!1},$_addLayer(){const e=this.map.getLayer(this.layerId);if(e){if(!this.replace)return this.$_emitEvent("layer-exists",{layerId:this.layerId}),e;this.map.removeLayer(this.layerId)}const t={id:this.layerId,source:this.sourceId,type:"background",...this.layer};this.map.addLayer(t,this.before),this.$_emitEvent("added",{layerId:this.layerId})}}}),g={boxzoomcancel:{name:"boxzoomcancel"},boxzoomend:{name:"boxzoomcancel"},boxzoomstart:{name:"boxzoomstart"},click:{name:"click"},contextmenu:{name:"contextmenu"},data:{name:"data"},dataloading:{name:"dataloading"},dblclick:{name:"dblclick"},drag:{name:"drag"},dragend:{name:"dragend"},dragstart:{name:"dragstart"},error:{name:"error"},idle:{name:"idle"},load:{name:"load"},mousedown:{name:"mousedown"},mouseenter:{name:"mouseenter"},mouseleave:{name:"mouseleave"},mousemove:{name:"mousemove"},mouseout:{name:"mouseout"},mouseover:{name:"mouseover"},mouseup:{name:"mouseup"},move:{name:"move"},moveend:{name:"moveend"},movestart:{name:"movestart"},pitch:{name:"pitch"},pitchend:{name:"pitchend"},pitchstart:{name:"pitchstart"},remove:{name:"remove"},render:{name:"render"},resize:{name:"resize"},rotate:{name:"rotate"},rotateend:{name:"rotateend"},rotatestart:{name:"rotatestart"},sourcedata:{name:"sourcedata"},sourcedataloading:{name:"sourcedataloading"},styledata:{name:"styledata"},styledataloading:{name:"styledataloading"},styleimagemissing:{name:"styleimagemissing"},touchcancel:{name:"touchcancel"},touchend:{name:"touchend"},touchmove:{name:"touchmove"},touchstart:{name:"touchstart"},webglcontextlost:{name:"webglcontextlost"},webglcontextrestored:{name:"webglcontextrestored"},wheel:{name:"wheel"},zoom:{name:"zoom"},zoomend:{name:"zoomend"},zoomstart:{name:"zoomstart"}};var $={antialias:{type:[Boolean,void 0],default:!1,required:!1},attributionControl:{type:[Boolean,void 0],default:!0,required:!1},bearing:{type:[Number,void 0],default:0,required:!1},bearingSnap:{type:[Number,void 0],default:7,required:!1},bounds:{type:[Object,Array,void 0],default:void 0,required:!1},boxZoom:{type:[Boolean,void 0],default:!0,required:!1},center:{type:[Object,Array,void 0],default:void 0,required:!1},clickTolerance:{type:[Number,void 0],default:3,required:!1},collectResourceTiming:{type:[Boolean,void 0],default:!1,required:!1},crossSourceCollisions:{type:[Boolean,void 0],default:!0,required:!1},container:{type:String,required:!1,default:()=>`map-${(""+Math.random()).split(".")[1]}`},customAttribution:{type:[String,Array,void 0],default:null,required:!1},dragPan:{type:[Boolean,void 0],default:!0,required:!1},dragRotate:{type:[Boolean,void 0],default:!0,required:!1},doubleClickZoom:{type:[Boolean,void 0],default:!0,required:!1},hash:{type:[Boolean,String,void 0],default:!1,required:!1},fadeDuration:{type:[Number,void 0],default:300,required:!1},failIfMajorPerformanceCaveat:{type:[Boolean,void 0],default:!1,required:!1},fitBoundsOptions:{type:[Object,void 0],default:void 0,required:!1},interactive:{type:[Boolean,void 0],default:!0,required:!1},keyboard:{type:[Boolean,void 0],default:!0,required:!1},locale:{type:[Object,void 0],default:void 0,required:!1},localIdeographFontFamily:{type:[String,void 0],default:"sans-serif",required:!1},logoPosition:{type:[String,void 0],default:"bottom-left",validator:e=>["top-left","top-right","bottom-left","bottom-right"].includes(e),required:!1},maxBounds:{type:[Array,Object,void 0],default:void 0,required:!1},maxPitch:{type:[Number,void 0],default:0,required:!1},maxZoom:{type:[Number,void 0],default:22,required:!1},minPitch:{type:[Number,void 0],default:0,required:!1},minZoom:{type:[Number,void 0],default:0,required:!1},preserveDrawingBuffer:{type:[Boolean,void 0],default:!1,required:!1},pitch:{type:[Number,void 0],default:0,required:!1},pitchWithRotate:{type:[Boolean,void 0],default:!0,required:!1},refreshExpiredTiles:{type:[Boolean,void 0],default:!0,required:!1},renderWorldCopies:{type:[Boolean,void 0],default:!0,required:!1},scrollZoom:{type:[Boolean,void 0],default:()=>!0,required:!1},mapStyle:{type:[String,Object,void 0],default:void 0,required:!0},trackResize:{type:[Boolean,void 0],default:!0,required:!1},transformRequest:{type:[Function,void 0],default:void 0,required:!1},touchZoomRotate:{type:[Boolean,void 0],default:()=>!0,required:!1},touchPitch:{type:[Boolean,void 0],default:()=>!0,required:!1},zoom:{type:[Number,void 0],default:0,required:!1},maxTileCacheSize:{type:[Number,void 0],default:null,required:!1},accessToken:{type:[String,void 0],default:void 0,required:!1},RTLTextPluginUrl:{type:[String,void 0],default:void 0,required:!1},light:{type:[Object,void 0],default:void 0,required:!1},tileBoundaries:{type:[Boolean,void 0],default:!1,required:!1},collisionBoxes:{type:[Boolean,void 0],default:!1,required:!1},repaint:{type:[Boolean,void 0],default:!1,required:!1}};const _={maxBounds(e){this.map.setMaxBounds(e)},minZoom(e){this.map.setMinZoom(e)},maxZoom(e){this.map.setMaxZoom(e)},minPitch(e){this.map.setMinPitch(e)},maxPitch(e){this.map.setMaxPitch(e)},mapStyle(e){this.map.setStyle(e)},collisionBoxes(e){this.map.showCollisionBoxes=e},tileBoundaries(e){this.map.showTileBoundaries=e},repaint(e){this.map.repaint=e},zoom(e){this.map.setZoom(e)},center(e){this.map.setCenter(e)},bearing(e){this.map.setBearing(e)},pitch(e){this.map.setPitch(e)},light(e){this.map.setLight(e)}};function b(e,t,i,r){this.initial||(this.$listeners[`update:${e}`]?(this.propsIsUpdating[e]?(this._watcher.active=!1,this.$nextTick((()=>{this._watcher.active=!0}))):(this._watcher.active=!0,t(i,r)),this.propsIsUpdating[e]=!1):t(i,r))}var x=o.default.extend({watch:function(){const e={};return Object.entries(_).forEach((t=>{e[t[0]]=function(e,i){return b.call(this,t[0],t[1].bind(this),e,i)}})),e}()}),S=o.default.extend({setup:()=>({container:t.ref()}),methods:{$_updateSyncedPropsFabric(e,t){return()=>{this.propsIsUpdating[e]=!0;const i="function"==typeof t?t():t;return this.$emit(`update:${e}`,i)}},$_bindPropsUpdateEvents(){[{events:["moveend"],prop:"center",getter:this.map.getCenter.bind(this.map)},{events:["zoomend"],prop:"zoom",getter:this.map.getZoom.bind(this.map)},{events:["rotate"],prop:"bearing",getter:this.map.getBearing.bind(this.map)},{events:["pitch"],prop:"pitch",getter:this.map.getPitch.bind(this.map)},{events:["moveend","zoomend","rotate","pitch"],prop:"bounds",getter:()=>{let e=this.map.getBounds();return this.$props.bounds instanceof Array&&(e=e.toArray()),e}}].forEach((({events:e,prop:t,getter:i})=>{e.forEach((e=>{this.$listeners[`update:${t}`]&&this.map.on(e,this.$_updateSyncedPropsFabric(t,i))}))}))},$_loadMap(){return this.mapboxPromise.then((e=>(this.mapbox=e.default?e.default:e,new Promise((e=>{this.accessToken&&(this.mapbox.accessToken=this.accessToken);const t=new this.mapbox.Map({...this._props,container:this.container,style:this.mapStyle});t.on("load",(()=>e(t)))})))))},$_RTLTextPluginError(e){this.$emit("rtl-plugin-error",{map:this.map,error:e})},$_bindMapEvents(e){Object.keys(this.$listeners).forEach((t=>{e.includes(t)&&this.map.on(t,this.$_emitMapEvent)}))},$_unbindEvents(e){e.forEach((e=>{this.map.off(e,this.$_emitMapEvent)}))}}}),I=o.default.extend({created(){this.actions={}},methods:{$_registerAsyncActions(e){this.actions={...a.default(e),stop(){this.map.stop();const e={pitch:this.map.getPitch(),zoom:this.map.getZoom(),bearing:this.map.getBearing(),center:this.map.getCenter()};return Object.entries(e).forEach((e=>{this.$_updateSyncedPropsFabric(e[0],e[1])()})),Promise.resolve(e)}}}}});function L(e,t,i,r,o,a,s,n,d,l){"boolean"!=typeof s&&(d=n,n=s,s=!1);const h="function"==typeof i?i.options:i;let u;if(e&&e.render&&(h.render=e.render,h.staticRenderFns=e.staticRenderFns,h._compiled=!0,o&&(h.functional=!0)),r&&(h._scopeId=r),a?(u=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,d(e)),e&&e._registeredComponents&&e._registeredComponents.add(a)},h._ssrRegister=u):t&&(u=s?function(e){t.call(this,l(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,n(e))}),u)if(h.functional){const e=h.render;h.render=function(t,i){return u.call(i),e(t,i)}}else{const e=h.beforeCreate;h.beforeCreate=e?[].concat(e,u):[u]}return i}const E=o.default.extend({name:"MglMap",mixins:[x,I,S,n],provide(){const e=this;return{get mapbox(){return e.mapbox},get map(){return e.map},get actions(){return e.actions}}},props:{mapboxGl:{type:Object,default:null},...$},emits:["load",...Object.keys(g)],data:()=>({initial:!0,initialized:!1}),computed:{loaded(){return!!this.map&&this.map.loaded()},version(){return this.map?this.map.version:null},isStyleLoaded(){return!!this.map&&this.map.isStyleLoaded()},areTilesLoaded(){return!!this.map&&this.map.areTilesLoaded()},isMoving(){return!!this.map&&this.map.isMoving()},canvas(){return this.map?this.map.getCanvas():null},canvasContainer(){return this.map?this.map.getCanvasContainer():null},images(){return this.map?this.map.listImages():null}},created(){this.map=null,this.propsIsUpdating={},this.mapboxPromise=this.mapboxGl?Promise.resolve(this.mapboxGl):import("mapbox-gl")},mounted(){this.$_loadMap().then((e=>{this.map=e,void 0!==this.RTLTextPluginUrl&&"loaded"!==this.mapbox.getRTLTextPluginStatus()&&this.mapbox.setRTLTextPlugin(this.RTLTextPluginUrl,this.$_RTLTextPluginError);const t=Object.keys(g);this.$_bindMapEvents(t),this.$_registerAsyncActions(e),this.$_bindPropsUpdateEvents(),this.initial=!1,this.initialized=!0,this.$emit("load",{map:e,component:this})}))},beforeDestroy(){this.$nextTick((()=>{this.map&&this.map.remove()}))}});var M=function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{staticClass:"mgl-map-wrapper"},[e._m(0),e._v(" "),e.initialized?e._t("default"):e._e()],2)};M._withStripped=!0;var C=L({render:M,staticRenderFns:[function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{ref:"container",attrs:{id:e.container}})}]},undefined,E,undefined,false,undefined,!1,void 0,void 0,void 0),w=o.default.extend({methods:{$_emitSelfEvent(e,t={}){this.$_emitMapEvent(e,{control:this.control,...t})},$_bindSelfEvents(e,t){Object.keys(this.$listeners).forEach((i=>{e.includes(i)&&t.on(i,this.$_emitSelfEvent)}))},$_unbindSelfEvents(e,t){0!==e.length&&t&&e.forEach((e=>{t.off(e,this.$_emitSelfEvent)}))}}}),k=o.default.extend({mixins:[n,w],inject:["mapbox","map","actions"],props:{position:{type:String,default:"top-right"}},watch:{position(){this.$_removeControl(),this.$_addControl()}},beforeDestroy(){this.$_removeControl()},methods:{$_addControl(){try{this.map.addControl(this.control,this.position)}catch(e){return void this.$_emitEvent("error",{error:e})}this.$_emitEvent("added",{control:this.control})},$_removeControl(){try{this.map&&this.control&&this.map.removeControl(this.control)}catch(e){return void this.$_emitEvent("error",{error:e})}this.$_emitEvent("removed",{control:this.control})}}}),q=o.default.extend({name:"AttributionControl",mixins:[k],props:{compact:{type:Boolean,default:!0},customAttribution:{type:[String,Array],default:void 0}},created(){this.control=new this.mapbox.AttributionControl(this.$props),this.$_addControl()},render(){}}),B=o.default.extend({name:"FullscreenControl",mixins:[k],props:{container:{type:HTMLElement,default:void 0}},created(){this.control=new this.mapbox.FullscreenControl(this.$props),this.$_addControl()},render(){}});const P={trackuserlocationstart:"trackuserlocationstart",trackuserlocationend:"trackuserlocationend",geolocate:"geolocate",error:"error"};var T=o.default.extend({name:"GeolocateControl",mixins:[n,w,k],props:{positionOptions:{type:Object,default:()=>({enableHighAccuracy:!1,timeout:6e3})},fitBoundsOptions:{type:Object,default:()=>({maxZoom:15})},trackUserLocation:{type:Boolean,default:!1},showAccuracyCircle:{type:Boolean,default:!1},showUserLocation:{type:Boolean,default:!0}},created(){const e=this.mapbox.GeolocateControl;this.control=new e(this.$props),this.$_addControl(),this.$_bindSelfEvents(Object.keys(P),this.control)},methods:{trigger(){if(this.control)return this.control.trigger()}},render(){}});class j{constructor(e={},t){this.options=e,this.element=t}onAdd(){return this.element.className="mapboxgl-ctrl mapboxgl-ctrl-group",this.element}onRemove(){this.element.parentNode.removeChild(this.element)}}var O=o.default.extend({name:"IControl",mixins:[k],mounted(){this.control=new j(this.$attrs,this.$el),this.$_addControl()},render(e){return e("div",this.$slots.default)}}),F=o.default.extend({name:"NavigationControl",mixins:[k],props:{showCompass:{type:Boolean,default:!0},showZoom:{type:Boolean,default:!0},visualizePitch:{type:Boolean,default:!0}},created(){this.control=new this.mapbox.NavigationControl(this.$props),this.$_addControl()},render(){}}),z=o.default.extend({name:"ScaleControl",mixins:[k],props:{maxWidth:{type:Number,default:150},unit:{type:String,default:"metric",validator:e=>["imperial","metric","nautical"].includes(e)}},watch:{unit(e,t){this.control&&e!==t&&this.control.setUnit(e)}},created(){this.control=new this.mapbox.ScaleControl(this.$props),this.$_addControl()},render(){}});const R={drag:"drag",dragstart:"dragstart",dragend:"dragend"},A={click:"click",mouseenter:"mouseenter",mouseleave:"mouseleave"};const N=o.default.extend({name:"MapMarker",mixins:[n,w],inject:["mapbox","map"],provide(){const e=this;return{get marker(){return e.marker}}},props:{offset:{type:[Object,Array],default:()=>[0,-14]},coordinates:{type:Array,required:!0},color:{type:String,default:"blue"},anchor:{type:String,default:"center"},draggable:{type:Boolean,default:!1}},data:()=>({initial:!0,marker:void 0}),watch:{coordinates(e){this.initial||this.marker.setLngLat(e)},draggable(e){this.initial||this.marker.setDraggable(e)}},mounted(){const e={...this.$props};this.$slots.marker&&(e.element=this.$slots.marker[0].elm),this.marker=new this.mapbox.Marker(e),this.$listeners["update:coordinates"]&&this.marker.on("dragend",(e=>{let t;t=this.coordinates instanceof Array?[e.target._lngLat.lng,e.target._lngLat.lat]:e.target._lngLat,this.$emit("update:coordinates",t)}));const t=Object.keys(R);this.$_bindSelfEvents(t,this.marker),this.initial=!1,this.$_addMarker()},beforeDestroy(){void 0!==this.map&&void 0!==this.marker&&this.marker.remove()},methods:{$_addMarker(){this.marker.setLngLat(this.coordinates).addTo(this.map),this.$_bindMarkerDOMEvents(),this.$_emitEvent("added",{marker:this.marker})},$_emitSelfEvent(e){this.$_emitMapEvent(e,{marker:this.marker})},$_bindMarkerDOMEvents(){Object.keys(this.$listeners).forEach((e=>{Object.values(A).includes(e)&&this.marker._element.addEventListener(e,(e=>{this.$_emitSelfEvent(e)}))}))},remove(){this.marker.remove(),this.$_emitEvent("removed")},togglePopup(){return this.marker.togglePopup()}}});var Z=function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{staticClass:"mgl-hidden"},[e._t("marker"),e._v(" "),e.marker?e._t("default"):e._e()],2)};Z._withStripped=!0;var U=L({render:Z,staticRenderFns:[]},undefined,N,undefined,false,undefined,!1,void 0,void 0,void 0);const D={open:"open",close:"close"};const G=o.default.extend({name:"MglPopup",mixins:[n,w],inject:{mapbox:{default:null},map:{default:null},marker:{default:null}},props:{className:{type:String,default:void 0},closeButton:{type:Boolean,default:!0},closeOnClick:{type:Boolean,default:!0},closeOnMove:{type:Boolean,default:!1},focusAfterOpen:{type:Boolean,default:!0},anchor:{validator:e=>"string"==typeof e&&["top","bottom","left","right","top-left","top-right","bottom-left","bottom-right"].includes(e),default:void 0},offset:{type:[Number,Object,Array],default:()=>[0,0]},coordinates:{type:Array,default:()=>[0,0]},onlyText:{type:Boolean,default:!1},showed:{type:Boolean,default:!1},maxWidth:{type:String,default:"240px"}},data:()=>({initial:!0,popup:void 0}),computed:{open:{get(){return void 0!==this.popup&&this.popup.isOpen()},set(e){this.map&&this.popup&&(e?this.popup.addTo(this.map):this.popup.remove())}}},watch:{coordinates(e){this.initial||this.popup.setLngLat(e)},showed(e,t){e!==t&&(this.open=e)}},created(){this.popup=new this.mapbox.Popup(this.$props)},mounted(){this.$_addPopup(),this.initial=!1},beforeDestroy(){this.map&&(this.popup.remove(),this.$_emitEvent("removed"))},methods:{$_addPopup(){if(this.popup=new this.mapbox.Popup(this.$props),void 0!==this.coordinates&&this.popup.setLngLat(this.coordinates),void 0!==this.$slots.default)if(this.onlyText)if(3===this.$slots.default[0].elm.nodeType){let e=document.createElement("span");e.appendChild(this.$slots.default[0].elm),this.popup.setText(e.innerText)}else this.popup.setText(this.$slots.default[0].elm.innerText);else this.popup.setDOMContent(this.$slots.default[0].elm);this.$_bindSelfEvents(Object.keys(D),this.popup),this.$_emitEvent("added",{popup:this.popup}),this.marker&&this.marker.setPopup(this.popup),this.showed&&(this.open=!0)},$_emitSelfEvent(e){this.$_emitMapEvent(e,{popup:this.popup})},remove(){this.popup.remove(),this.$_emitEvent("remove",{popup:this.popup})}}});var V=function(){var e=this,t=e.$createElement;return(e._self._c||t)("div",{staticClass:"mgl-hidden"},[e._t("default")],2)};V._withStripped=!0;var W=L({render:V,staticRenderFns:[]},undefined,G,undefined,false,undefined,!1,void 0,void 0,void 0);let H=!1;var X=e=>{if(!H){const t={withEvents:n,withSelfEvents:w,asControl:k,asLayer:u};e.component("MglMap",C),e.component("MglNavigationControl",F),e.component("MglGeolocateControl",T),e.component("MglFullscreenControl",B),e.component("MglAttributionControl",q),e.component("MglScaleControl",z),e.component("MglGeojsonLayer",p),e.component("MglImageLayer",m),e.component("MglCanvasLayer",c),e.component("MglVideoLayer",v),e.component("MglVectorLayer",f),e.component("MglRasterLayer",y),e.component("MglMarker",U),e.component("MglPopup",W),e.prototype.$helpers=t,H=!0}};const J=n,K=w,Q=k,Y=u,ee={withEvents:n,withSelfEvents:w,asControl:k,asLayer:u};e.$helpers=ee,e.MglAttributionControl=q,e.MglCanvasLayer=c,e.MglFullscreenControl=B,e.MglGeojsonLayer=p,e.MglGeolocateControl=T,e.MglIControl=O,e.MglImageLayer=m,e.MglMap=C,e.MglMarker=U,e.MglNavigationControl=F,e.MglPopup=W,e.MglRasterLayer=y,e.MglScaleControl=z,e.MglVectorLayer=f,e.MglVideoLayer=v,e.asControl=Q,e.asLayer=Y,e.default=X,e.withEvents=J,e.withSelfEvents=K,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=v-mapbox.min.js.map