UNPKG

@vuemap/vue-amap

Version:

高德地图vue3版本封装

1,575 lines (1,477 loc) 435 kB
/*! @vuemap/vue-amap v2.1.16 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) : typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VueAMap = global.VueAMap || {}, global.Vue)); })(this, (function (exports, vue) { 'use strict'; const makeInstaller = (components = []) => { const apps = []; const install = (app) => { if (apps.includes(app)) return; apps.push(app); components.forEach((c) => app.use(c)); }; return { install }; }; function guid() { const s = []; const hexDigits = "0123456789abcdef"; for (let i = 0; i < 36; i++) { s[i] = hexDigits.charAt(Math.floor(Math.random() * 16)); } s[8] = s[13] = s[18] = s[23] = "-"; return s.join(""); } function isMapInstance(instance) { if (!instance) { return false; } return instance instanceof AMap.Map; } function isOverlayGroupInstance(instance) { if (!instance) { return false; } return instance instanceof AMap.OverlayGroup; } function isIndoorMapInstance(instance) { if (!instance) { return false; } return instance instanceof AMap.IndoorMap; } function isLabelsLayerInstance(instance) { if (!instance) { return false; } return instance instanceof AMap.LabelsLayer; } function isVectorLayerInstance(instance) { if (!instance) { return false; } return instance instanceof AMap.VectorLayer; } function convertEventToLowerCase(functionName) { if (!functionName || functionName.length < 4) { return functionName; } const func = functionName.substring(3, functionName.length); const firstLetter = functionName[2].toLowerCase(); return firstLetter + func; } const eventReg = /^on[A-Z]+/; function loadScript(url, callback) { if (!url) { throw new Error("\u8BF7\u4F20\u5165url"); } const script = document.createElement("script"); script.type = "text/javascript"; script.async = true; script.defer = true; script.src = url; document.body.appendChild(script); if (callback) { script.addEventListener("load", () => { callback(); }); } } function convertLnglat(lnglat) { if (Array.isArray(lnglat)) { return lnglat.map(convertLnglat); } return lnglat.toArray(); } function upperCamelCase(prop) { if (!prop) { return prop; } return prop.charAt(0).toUpperCase() + prop.slice(1); } function bindInstanceEvent(instance, eventName, handler) { if (!instance || !instance.on) { return; } instance.on(eventName, handler); } function removeInstanceEvent(instance, eventName, handler) { if (!instance || !instance.off) { return; } instance.off(eventName, handler); } function toPixel(arr) { return new AMap.Pixel(arr[0], arr[1]); } function toSize(arr) { return new AMap.Size(arr[0], arr[1]); } function pixelTo(pixel) { if (Array.isArray(pixel)) return pixel; return [pixel.getX(), pixel.getY()]; } function toLngLat(arr) { return new AMap.LngLat(arr[0], arr[1]); } function lngLatTo(lngLat) { if (!lngLat) return; if (Array.isArray(lngLat)) return lngLat.slice(); return [lngLat.getLng(), lngLat.getLat()]; } function toBounds(arrs) { return new AMap.Bounds(toLngLat(arrs[0]), toLngLat(arrs[1])); } const pi$1 = 3.141592653589793; const a = 6378245; const ee$2 = 0.006693421622965943; const x_pi = pi$1 * 3e3 / 180; function lonLatToTileNumbers(lon_deg, lat_deg, zoom) { const lat_rad = pi$1 / 180 * lat_deg; const n = Math.pow(2, zoom); const xtile = Math.floor((lon_deg + 180) / 360 * n); const ytile = Math.floor((1 - Math.asinh(Math.tan(lat_rad)) / pi$1) / 2 * n); return [xtile, ytile]; } function tileNumbersToLonLat(xtile, ytile, zoom) { const n = Math.pow(2, zoom); const lon_deg = xtile / n * 360 - 180; const lat_rad = Math.atan(Math.sinh(pi$1 * (1 - 2 * ytile / n))); const lat_deg = lat_rad * 180 / pi$1; return [lon_deg, lat_deg]; } function bd09_To_gps84(lng, lat) { const gcj02 = bd09_To_gcj02(lng, lat); const map84 = gcj02_To_gps84(gcj02.lng, gcj02.lat); return map84; } function gps84_To_bd09(lng, lat) { const gcj02 = gps84_To_gcj02(lng, lat); const bd09 = gcj02_To_bd09(gcj02.lng, gcj02.lat); return bd09; } function gps84_To_gcj02(lng, lat) { let dLat = transformLat(lng - 105, lat - 35); let dLng = transformLng(lng - 105, lat - 35); const radLat = lat / 180 * pi$1; let magic = Math.sin(radLat); magic = 1 - ee$2 * magic * magic; const sqrtMagic = Math.sqrt(magic); dLat = dLat * 180 / (a * (1 - ee$2) / (magic * sqrtMagic) * pi$1); dLng = dLng * 180 / (a / sqrtMagic * Math.cos(radLat) * pi$1); const mgLat = lat + dLat; const mgLng = lng + dLng; const newCoord = { lng: mgLng, lat: mgLat }; return newCoord; } function gcj02_To_gps84(lng, lat) { const coord = transform(lng, lat); const lontitude = lng * 2 - coord.lng; const latitude = lat * 2 - coord.lat; const newCoord = { lng: lontitude, lat: latitude }; return newCoord; } function gcj02_To_bd09(x, y) { const z = Math.sqrt(x * x + y * y) + 2e-5 * Math.sin(y * x_pi); const theta = Math.atan2(y, x) + 3e-6 * Math.cos(x * x_pi); const bd_lng = z * Math.cos(theta) + 65e-4; const bd_lat = z * Math.sin(theta) + 6e-3; const newCoord = { lng: bd_lng, lat: bd_lat }; return newCoord; } function bd09_To_gcj02(bd_lng, bd_lat) { const x = bd_lng - 65e-4; const y = bd_lat - 6e-3; const z = Math.sqrt(x * x + y * y) - 2e-5 * Math.sin(y * x_pi); const theta = Math.atan2(y, x) - 3e-6 * Math.cos(x * x_pi); const gg_lng = z * Math.cos(theta); const gg_lat = z * Math.sin(theta); const newCoord = { lng: gg_lng, lat: gg_lat }; return newCoord; } function transform(lng, lat) { let dLat = transformLat(lng - 105, lat - 35); let dLng = transformLng(lng - 105, lat - 35); const radLat = lat / 180 * pi$1; let magic = Math.sin(radLat); magic = 1 - ee$2 * magic * magic; const sqrtMagic = Math.sqrt(magic); dLat = dLat * 180 / (a * (1 - ee$2) / (magic * sqrtMagic) * pi$1); dLng = dLng * 180 / (a / sqrtMagic * Math.cos(radLat) * pi$1); const mgLat = lat + dLat; const mgLng = lng + dLng; const newCoord = { lng: mgLng, lat: mgLat }; return newCoord; } function transformLat(x, y) { let ret = -100 + 2 * x + 3 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x)); ret += (20 * Math.sin(6 * x * pi$1) + 20 * Math.sin(2 * x * pi$1)) * 2 / 3; ret += (20 * Math.sin(y * pi$1) + 40 * Math.sin(y / 3 * pi$1)) * 2 / 3; ret += (160 * Math.sin(y / 12 * pi$1) + 320 * Math.sin(y * pi$1 / 30)) * 2 / 3; return ret; } function transformLng(x, y) { let ret = 300 + x + 2 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x)); ret += (20 * Math.sin(6 * x * pi$1) + 20 * Math.sin(2 * x * pi$1)) * 2 / 3; ret += (20 * Math.sin(x * pi$1) + 40 * Math.sin(x / 3 * pi$1)) * 2 / 3; ret += (150 * Math.sin(x / 12 * pi$1) + 300 * Math.sin(x / 30 * pi$1)) * 2 / 3; return ret; } const commonProps = { visible: { type: Boolean, default: true }, zIndex: { type: Number }, reEventWhenUpdate: { type: Boolean, default: false }, extraOptions: { type: Object } }; const buildProps = (props) => { return Object.assign({}, commonProps, props); }; var registerComponent = vue.defineComponent({ inject: { parentInstance: { default: null } }, inheritAttrs: false, props: { visible: { type: Boolean, default: true }, // 是否显示,默认 true zIndex: { type: Number }, reEventWhenUpdate: { type: Boolean, default: false }, // 是否在组件更新时重新注册事件,主要用于数组更新时,绑定了事件但事件的对象不会更新问题 extraOptions: { type: Object } // 额外扩展属性 }, emits: ["init"], data() { return { needInitComponents: [], unwatchFns: [], propsRedirect: {}, converters: {}, isDestroy: false, cacheEvents: {}, isMounted: false }; }, created() { this.$amapComponent = null; this.$parentComponent = null; }, mounted() { if (this.parentInstance) { if (this.parentInstance.$amapComponent) { this.register(); } else { this.parentInstance.addChildComponent(this.register); } } }, beforeUnmount() { if (!this.$amapComponent) return; this.unregisterEvents(); this.unwatchFns.forEach((item) => item()); this.unwatchFns = []; this.destroyComponent(); this.isDestroy = true; }, beforeUpdate() { if (this.reEventWhenUpdate && this.isMounted && this.$amapComponent) { this.unregisterEvents(); } }, updated() { if (this.reEventWhenUpdate && this.isMounted && this.$amapComponent) { this.registerEvents(); } }, methods: { getHandlerFun(prop) { if (this[`__${prop}`]) { return this[`__${prop}`]; } if (!this.$amapComponent) { return null; } return this.$amapComponent[`set${upperCamelCase(prop)}`]; }, convertProps() { const props = {}; const { $props, propsRedirect } = this; if (this.extraOptions) { Object.assign(props, this.extraOptions); } const result = Object.keys($props).reduce((res, _key) => { let key = _key; const propsValue = this.convertSignalProp(key, $props[key]); if (propsValue === void 0) return res; if (propsRedirect && propsRedirect[_key]) key = propsRedirect[key]; props[key] = propsValue; return res; }, props); Object.keys(result).forEach((key) => { result[key] = this.convertProxyToRaw(result[key]); }); return result; }, convertProxyToRaw(value) { if (vue.isProxy(value)) { return vue.toRaw(value); } return vue.unref(value); }, convertSignalProp(key, sourceData) { if (this.converters && this.converters[key]) { return this.converters[key].call(this, sourceData); } return sourceData; }, registerEvents() { const $props = this.$attrs; Object.keys($props).forEach((key) => { if (eventReg.test(key)) { const eventKey = convertEventToLowerCase(key); bindInstanceEvent(this.$amapComponent, eventKey, $props[key]); this.cacheEvents[eventKey] = $props[key]; } }); }, unregisterEvents() { Object.keys(this.cacheEvents).forEach((eventKey) => { removeInstanceEvent(this.$amapComponent, eventKey, this.cacheEvents[eventKey]); delete this.cacheEvents[eventKey]; }); }, setPropWatchers() { const { propsRedirect, $props } = this; Object.keys($props).forEach((prop) => { let handleProp = prop; if (propsRedirect && propsRedirect[prop]) handleProp = propsRedirect[prop]; const handleFun = this.getHandlerFun(handleProp); if (!handleFun) return; const watchOptions = { deep: false }; const propValueType = Object.prototype.toString.call($props[prop]); if (propValueType === "[object Object]" || propValueType === "[object Array]") { watchOptions.deep = true; } const unwatch = this.$watch(prop, (nv) => { handleFun.call(this.$amapComponent, this.convertProxyToRaw(this.convertSignalProp(prop, nv))); }, watchOptions); this.unwatchFns.push(unwatch); }); }, // some prop can not init by initial created methods initProps() { const props = ["editable", "visible", "zooms"]; props.forEach((propStr) => { if (this[propStr] !== void 0) { const handleFun = this.getHandlerFun(propStr); handleFun && handleFun.call(this.$amapComponent, this.convertProxyToRaw(this.convertSignalProp(propStr, this[propStr]))); } }); }, lazyRegister() { const $parent = this.parentInstance; if ($parent && $parent.addChildComponent) { $parent.addChildComponent(this); } }, addChildComponent(component) { this.needInitComponents.push(component); }, createChildren() { while (this.needInitComponents.length > 0) { this.needInitComponents[0](); this.needInitComponents.splice(0, 1); } }, register() { if (this.parentInstance && !this.$parentComponent) { this.$parentComponent = this.parentInstance.$amapComponent; } const res = this["__initComponent"] && this["__initComponent"](this.convertProps()); if (res && res.then) res.then((instance) => this.registerRest(instance)); else this.registerRest(res); }, registerRest(instance) { if (!this.$amapComponent && instance) this.$amapComponent = instance; this.registerEvents(); this.initProps(); this.setPropWatchers(); this.$emit("init", this.$amapComponent, this); this.$nextTick(() => { this.createChildren(); }); this.isMounted = true; }, // helper method $$getInstance() { return this.$amapComponent; }, destroyComponent() { this.$amapComponent.setMap && this.$amapComponent.setMap(null); this.$amapComponent.close && this.$amapComponent.close(); this.$amapComponent.editor && this.$amapComponent.editor.close(); }, __visible(flag) { if (!!this.$amapComponent && !!this.$amapComponent.show && !!this.$amapComponent.hide) { flag === false ? this.$amapComponent.hide() : this.$amapComponent.show(); } }, __zIndex(value) { if (this.$amapComponent && this.$amapComponent.setzIndex) { this.$amapComponent.setzIndex(value); } } } }); const provideKey = "parentInstance"; const useRegister = (_init, params) => { let componentInstance = vue.getCurrentInstance(); let { props, attrs } = componentInstance; let parentInstance = vue.inject(provideKey, void 0); const emits = params.emits; let isMounted = false; let $amapComponent; vue.onMounted(() => { if (parentInstance) { if (parentInstance.$amapComponent) { register(); } else { parentInstance.addChildComponent(register); } } else if (params.isRoot) { register(); } }); vue.onBeforeUnmount(() => { if (!$amapComponent) { return; } unregisterEvents(); stopWatchers(); if (params.destroyComponent) { params.destroyComponent(); } else { destroyComponent(); } if (params.provideData) { params.provideData.isDestroy = true; } parentInstance = void 0; props = void 0; attrs = void 0; componentInstance = void 0; $amapComponent = void 0; }); vue.onBeforeUpdate(() => { if (props.reEventWhenUpdate && isMounted && $amapComponent) { unregisterEvents(); } }); vue.onUpdated(() => { if (props.reEventWhenUpdate && isMounted && $amapComponent) { registerEvents(); } }); const register = () => { const options = convertProps(); _init(options, parentInstance == null ? void 0 : parentInstance.$amapComponent).then((mapInstance) => { $amapComponent = mapInstance; registerEvents(); initProps(); setPropWatchers(); Object.assign(componentInstance.ctx, componentInstance.exposed); emits("init", $amapComponent, componentInstance.ctx); vue.nextTick(() => { createChildren(); }).then(); isMounted = true; }); }; const initProps = () => { const propsList = ["editable", "visible", "zooms"]; propsList.forEach((propStr) => { if (props[propStr] !== void 0) { const handleFun = getHandlerFun(propStr); handleFun && handleFun.call($amapComponent, convertProxyToRaw(convertSignalProp(propStr, props[propStr]))); } }); }; const propsRedirect = params.propsRedirect || {}; const convertProps = () => { const propsCache = {}; if (props.extraOptions) { Object.assign(propsCache, props.extraOptions); } Object.keys(props).forEach((_key) => { let key = _key; const propsValue = convertSignalProp(key, props[key]); if (propsValue !== void 0) { if (propsRedirect && propsRedirect[_key]) { key = propsRedirect[key]; } propsCache[key] = propsValue; } }); return propsCache; }; const converters = params.converts || {}; const convertSignalProp = (key, sourceData) => { if (converters && converters[key]) { return converters[key].call(void 0, sourceData); } return sourceData; }; const convertProxyToRaw = (value) => { if (vue.isProxy(value)) { return vue.toRaw(value); } return vue.unref(value); }; let unwatchFns = []; let watchRedirectFn = Object.assign({ __visible: (flag) => { if (!!$amapComponent && !!$amapComponent["show"] && !!$amapComponent["hide"]) { !flag ? $amapComponent["hide"]() : $amapComponent["show"](); } }, __zIndex(value) { if ($amapComponent && $amapComponent["setzIndex"]) { $amapComponent["setzIndex"](value); } } }, params.watchRedirectFn || {}); const setPropWatchers = () => { Object.keys(props).forEach((prop) => { let handleProp = prop; if (propsRedirect && propsRedirect[prop]) handleProp = propsRedirect[prop]; const handleFun = getHandlerFun(handleProp); if (!handleFun) return; const watchOptions = { deep: false }; const propValueType = Object.prototype.toString.call(props[prop]); if (propValueType === "[object Object]" || propValueType === "[object Array]") { watchOptions.deep = true; } const unwatch = vue.watch(() => props[prop], (nv) => { handleFun.call($amapComponent, convertProxyToRaw(convertSignalProp(prop, nv))); }, watchOptions); unwatchFns.push(unwatch); }); }; const stopWatchers = () => { unwatchFns.forEach((fn) => fn()); unwatchFns = []; watchRedirectFn = void 0; }; const getHandlerFun = (prop) => { if (watchRedirectFn[`__${prop}`]) { return watchRedirectFn[`__${prop}`]; } if (!$amapComponent) { return null; } return $amapComponent[`set${upperCamelCase(prop)}`]; }; const cacheEvents = {}; const registerEvents = () => { Object.keys(attrs).forEach((key) => { if (eventReg.test(key)) { const eventKey = convertEventToLowerCase(key); bindInstanceEvent($amapComponent, eventKey, attrs[key]); cacheEvents[eventKey] = attrs[key]; } }); }; const unregisterEvents = () => { Object.keys(cacheEvents).forEach((eventKey) => { removeInstanceEvent($amapComponent, eventKey, cacheEvents[eventKey]); delete cacheEvents[eventKey]; }); }; const createChildren = () => { const needInitComponents = params.needInitComponents || []; while (needInitComponents.length > 0) { needInitComponents[0](); needInitComponents.splice(0, 1); } }; const destroyComponent = () => { if (!$amapComponent) { return; } $amapComponent.setMap && $amapComponent.setMap(null); $amapComponent.close && $amapComponent.close(); $amapComponent.editor && $amapComponent.editor.close(); }; function $$getInstance() { return $amapComponent; } return { $$getInstance, parentInstance, isMounted }; }; var d,e=d||(d={});e.notload="notload";e.loading="loading";e.loaded="loaded";e.failed="failed";let g={key:"",AMap:{version:"1.4.15",plugins:[]},AMapUI:{version:"1.1",plugins:[]},Loca:{version:"1.3.2"}},m={AMap:d.notload,AMapUI:d.notload,Loca:d.notload},n={AMap:[],AMapUI:[],Loca:[]},p=[];function q$1(a){"function"==typeof a&&(m.AMap===d.loaded?a(window.AMap):p.push(a));}function r(a){let h=[];a.AMapUI&&h.push(t(a.AMapUI));a.Loca&&h.push(u$1(a.Loca));return Promise.all(h)} function t(a){return new Promise((h,b)=>{let f=[];if(a.plugins)for(var c=0;c<a.plugins.length;c+=1)-1==g.AMapUI.plugins.indexOf(a.plugins[c])&&f.push(a.plugins[c]);if(m.AMapUI===d.failed)b("\u524d\u6b21\u8bf7\u6c42 AMapUI \u5931\u8d25");else if(m.AMapUI===d.notload){m.AMapUI=d.loading;g.AMapUI.version=a.version||g.AMapUI.version;c=g.AMapUI.version;let k=document.body||document.head,l=document.createElement("script");l.type="text/javascript";l.src=`https://webapi.amap.com/ui/${c}/main.js`;l.onerror= ()=>{m.AMapUI=d.failed;b("\u8bf7\u6c42 AMapUI \u5931\u8d25");};l.onload=()=>{m.AMapUI=d.loaded;if(f.length)window.AMapUI.loadUI(f,function(){for(let a=0,b=f.length;a<b;a++){let b=f[a].split("/").slice(-1)[0];window.AMapUI[b]=arguments[a];}for(h();n.AMapUI.length;)n.AMapUI.splice(0,1)[0]();});else for(h();n.AMapUI.length;)n.AMapUI.splice(0,1)[0]();};k.appendChild(l);}else m.AMapUI===d.loaded?a.version&&a.version!==g.AMapUI.version?b("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c AMapUI \u6df7\u7528"):f.length? window.AMapUI.loadUI(f,function(){for(let a=0,b=f.length;a<b;a++){let b=f[a].split("/").slice(-1)[0];window.AMapUI[b]=arguments[a];}h();}):h():a.version&&a.version!==g.AMapUI.version?b("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c AMapUI \u6df7\u7528"):n.AMapUI.push(a=>{a?b(a):f.length?window.AMapUI.loadUI(f,function(){for(let a=0,b=f.length;a<b;a++){let b=f[a].split("/").slice(-1)[0];window.AMapUI[b]=arguments[a];}h();}):h();});})} function u$1(a){return new Promise((h,b)=>{if(m.Loca===d.failed)b("\u524d\u6b21\u8bf7\u6c42 Loca \u5931\u8d25");else if(m.Loca===d.notload){m.Loca=d.loading;g.Loca.version=a.version||g.Loca.version;let l=g.Loca.version;var f=g.AMap.version.startsWith("2"),c=l.startsWith("2");if(f&&!c||!f&&c)b("JSAPI \u4e0e Loca \u7248\u672c\u4e0d\u5bf9\u5e94\uff01\uff01");else {f=g.key;c=document.body||document.head;var k=document.createElement("script");k.type="text/javascript";k.src=`https://webapi.amap.com/loca?v=${l}&key=${f}`; k.onerror=()=>{m.Loca=d.failed;b("\u8bf7\u6c42 AMapUI \u5931\u8d25");};k.onload=()=>{m.Loca=d.loaded;for(h();n.Loca.length;)n.Loca.splice(0,1)[0]();};c.appendChild(k);}}else m.Loca===d.loaded?a.version&&a.version!==g.Loca.version?b("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c Loca \u6df7\u7528"):h():a.version&&a.version!==g.Loca.version?b("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c Loca \u6df7\u7528"):n.Loca.push(a=>{a?b(a):b();});})} var AMapLoader = {load:function(a){if("undefined"===typeof window)throw Error("AMap JSAPI can only be used in Browser.");return new Promise((h,b)=>{if(m.AMap==d.failed)b("");else if(m.AMap==d.notload){let {key:l,version:k,plugins:v}=a;if(l){window.AMap&&"lbs.amap.com"!==location.host&&b("\u7981\u6b62\u591a\u79cdAPI\u52a0\u8f7d\u65b9\u5f0f\u6df7\u7528");g.key=l;g.AMap.version=k||g.AMap.version;g.AMap.plugins=v||g.AMap.plugins;m.AMap=d.loading;var f=document.body||document.head;window.___onAPILoaded=function(c){delete window.___onAPILoaded; if(c)m.AMap=d.failed,b(c);else for(m.AMap=d.loaded,r(a).then(()=>{h(window.AMap);}).catch(b);p.length;)p.splice(0,1)[0]();};var c=document.createElement("script");c.type="text/javascript";c.src="https://webapi.amap.com/maps?callback=___onAPILoaded&v="+g.AMap.version+"&key="+l+"&plugin="+g.AMap.plugins.join(",");c.onerror=a=>{m.AMap=d.failed;b(a);};f.appendChild(c);}else b("\u8bf7\u586b\u5199key");}else if(m.AMap==d.loaded)if(a.key&&a.key!==g.key)b("\u591a\u4e2a\u4e0d\u4e00\u81f4\u7684 key");else if(a.version&& a.version!==g.AMap.version)b("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c JSAPI \u6df7\u7528");else {f=[];if(a.plugins)for(c=0;c<a.plugins.length;c+=1)-1==g.AMap.plugins.indexOf(a.plugins[c])&&f.push(a.plugins[c]);f.length?window.AMap.plugin(f,()=>{r(a).then(()=>{h(window.AMap);}).catch(b);}):r(a).then(()=>{h(window.AMap);}).catch(b);}else if(a.key&&a.key!==g.key)b("\u591a\u4e2a\u4e0d\u4e00\u81f4\u7684 key");else if(a.version&&a.version!==g.AMap.version)b("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c JSAPI \u6df7\u7528"); else {var k=[];if(a.plugins)for(c=0;c<a.plugins.length;c+=1)-1==g.AMap.plugins.indexOf(a.plugins[c])&&k.push(a.plugins[c]);q$1(()=>{k.length?window.AMap.plugin(k,()=>{r(a).then(()=>{h(window.AMap);}).catch(b);}):r(a).then(()=>{h(window.AMap);}).catch(b);});}})},reset:function(){delete window.AMap;delete window.AMapUI;delete window.Loca;g={key:"",AMap:{version:"1.4.15",plugins:[]},AMapUI:{version:"1.1",plugins:[]},Loca:{version:"1.3.2"}};m={AMap:d.notload,AMapUI:d.notload,Loca:d.notload};n={AMap:[],AMapUI:[], Loca:[]};}}; /** Detect free variable `global` from Node.js. */ var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; /** Detect free variable `self`. */ var freeSelf = typeof self == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ var root = freeGlobal || freeSelf || Function('return this')(); /** Built-in value references. */ var Symbol$1 = root.Symbol; /** Used for built-in method references. */ var objectProto$a = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$8 = objectProto$a.hasOwnProperty; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString$1 = objectProto$a.toString; /** Built-in value references. */ var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined; /** * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. * * @private * @param {*} value The value to query. * @returns {string} Returns the raw `toStringTag`. */ function getRawTag(value) { var isOwn = hasOwnProperty$8.call(value, symToStringTag$1), tag = value[symToStringTag$1]; try { value[symToStringTag$1] = undefined; var unmasked = true; } catch (e) {} var result = nativeObjectToString$1.call(value); if (unmasked) { if (isOwn) { value[symToStringTag$1] = tag; } else { delete value[symToStringTag$1]; } } return result; } /** Used for built-in method references. */ var objectProto$9 = Object.prototype; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString = objectProto$9.toString; /** * Converts `value` to a string using `Object.prototype.toString`. * * @private * @param {*} value The value to convert. * @returns {string} Returns the converted string. */ function objectToString(value) { return nativeObjectToString.call(value); } /** `Object#toString` result references. */ var nullTag = '[object Null]', undefinedTag = '[object Undefined]'; /** Built-in value references. */ var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined; /** * The base implementation of `getTag` without fallbacks for buggy environments. * * @private * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ function baseGetTag(value) { if (value == null) { return value === undefined ? undefinedTag : nullTag; } return (symToStringTag && symToStringTag in Object(value)) ? getRawTag(value) : objectToString(value); } /** * Checks if `value` is object-like. A value is object-like if it's not `null` * and has a `typeof` result of "object". * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is object-like, else `false`. * @example * * _.isObjectLike({}); * // => true * * _.isObjectLike([1, 2, 3]); * // => true * * _.isObjectLike(_.noop); * // => false * * _.isObjectLike(null); * // => false */ function isObjectLike(value) { return value != null && typeof value == 'object'; } /** `Object#toString` result references. */ var symbolTag = '[object Symbol]'; /** * Checks if `value` is classified as a `Symbol` primitive or object. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. * @example * * _.isSymbol(Symbol.iterator); * // => true * * _.isSymbol('abc'); * // => false */ function isSymbol(value) { return typeof value == 'symbol' || (isObjectLike(value) && baseGetTag(value) == symbolTag); } /** * Checks if `value` is classified as an `Array` object. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an array, else `false`. * @example * * _.isArray([1, 2, 3]); * // => true * * _.isArray(document.body.children); * // => false * * _.isArray('abc'); * // => false * * _.isArray(_.noop); * // => false */ var isArray = Array.isArray; /** Used to match a single whitespace character. */ var reWhitespace = /\s/; /** * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace * character of `string`. * * @private * @param {string} string The string to inspect. * @returns {number} Returns the index of the last non-whitespace character. */ function trimmedEndIndex(string) { var index = string.length; while (index-- && reWhitespace.test(string.charAt(index))) {} return index; } /** Used to match leading whitespace. */ var reTrimStart = /^\s+/; /** * The base implementation of `_.trim`. * * @private * @param {string} string The string to trim. * @returns {string} Returns the trimmed string. */ function baseTrim(string) { return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') : string; } /** * Checks if `value` is the * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an object, else `false`. * @example * * _.isObject({}); * // => true * * _.isObject([1, 2, 3]); * // => true * * _.isObject(_.noop); * // => true * * _.isObject(null); * // => false */ function isObject(value) { var type = typeof value; return value != null && (type == 'object' || type == 'function'); } /** Used as references for various `Number` constants. */ var NAN = 0 / 0; /** Used to detect bad signed hexadecimal string values. */ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; /** Used to detect binary string values. */ var reIsBinary = /^0b[01]+$/i; /** Used to detect octal string values. */ var reIsOctal = /^0o[0-7]+$/i; /** Built-in method references without a dependency on `root`. */ var freeParseInt = parseInt; /** * Converts `value` to a number. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to process. * @returns {number} Returns the number. * @example * * _.toNumber(3.2); * // => 3.2 * * _.toNumber(Number.MIN_VALUE); * // => 5e-324 * * _.toNumber(Infinity); * // => Infinity * * _.toNumber('3.2'); * // => 3.2 */ function toNumber(value) { if (typeof value == 'number') { return value; } if (isSymbol(value)) { return NAN; } if (isObject(value)) { var other = typeof value.valueOf == 'function' ? value.valueOf() : value; value = isObject(other) ? (other + '') : other; } if (typeof value != 'string') { return value === 0 ? value : +value; } value = baseTrim(value); var isBinary = reIsBinary.test(value); return (isBinary || reIsOctal.test(value)) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : (reIsBadHex.test(value) ? NAN : +value); } /** * This method returns the first argument it receives. * * @static * @since 0.1.0 * @memberOf _ * @category Util * @param {*} value Any value. * @returns {*} Returns `value`. * @example * * var object = { 'a': 1 }; * * console.log(_.identity(object) === object); * // => true */ function identity(value) { return value; } /** `Object#toString` result references. */ var asyncTag = '[object AsyncFunction]', funcTag$1 = '[object Function]', genTag = '[object GeneratorFunction]', proxyTag = '[object Proxy]'; /** * Checks if `value` is classified as a `Function` object. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a function, else `false`. * @example * * _.isFunction(_); * // => true * * _.isFunction(/abc/); * // => false */ function isFunction(value) { if (!isObject(value)) { return false; } // The use of `Object#toString` avoids issues with the `typeof` operator // in Safari 9 which returns 'object' for typed arrays and other constructors. var tag = baseGetTag(value); return tag == funcTag$1 || tag == genTag || tag == asyncTag || tag == proxyTag; } /** Used to detect overreaching core-js shims. */ var coreJsData = root['__core-js_shared__']; /** Used to detect methods masquerading as native. */ var maskSrcKey = (function() { var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); return uid ? ('Symbol(src)_1.' + uid) : ''; }()); /** * Checks if `func` has its source masked. * * @private * @param {Function} func The function to check. * @returns {boolean} Returns `true` if `func` is masked, else `false`. */ function isMasked(func) { return !!maskSrcKey && (maskSrcKey in func); } /** Used for built-in method references. */ var funcProto$2 = Function.prototype; /** Used to resolve the decompiled source of functions. */ var funcToString$2 = funcProto$2.toString; /** * Converts `func` to its source code. * * @private * @param {Function} func The function to convert. * @returns {string} Returns the source code. */ function toSource(func) { if (func != null) { try { return funcToString$2.call(func); } catch (e) {} try { return (func + ''); } catch (e) {} } return ''; } /** * Used to match `RegExp` * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). */ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; /** Used to detect host constructors (Safari). */ var reIsHostCtor = /^\[object .+?Constructor\]$/; /** Used for built-in method references. */ var funcProto$1 = Function.prototype, objectProto$8 = Object.prototype; /** Used to resolve the decompiled source of functions. */ var funcToString$1 = funcProto$1.toString; /** Used to check objects for own properties. */ var hasOwnProperty$7 = objectProto$8.hasOwnProperty; /** Used to detect if a method is native. */ var reIsNative = RegExp('^' + funcToString$1.call(hasOwnProperty$7).replace(reRegExpChar, '\\$&') .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' ); /** * The base implementation of `_.isNative` without bad shim checks. * * @private * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a native function, * else `false`. */ function baseIsNative(value) { if (!isObject(value) || isMasked(value)) { return false; } var pattern = isFunction(value) ? reIsNative : reIsHostCtor; return pattern.test(toSource(value)); } /** * Gets the value at `key` of `object`. * * @private * @param {Object} [object] The object to query. * @param {string} key The key of the property to get. * @returns {*} Returns the property value. */ function getValue(object, key) { return object == null ? undefined : object[key]; } /** * Gets the native function at `key` of `object`. * * @private * @param {Object} object The object to query. * @param {string} key The key of the method to get. * @returns {*} Returns the function if it's native, else `undefined`. */ function getNative(object, key) { var value = getValue(object, key); return baseIsNative(value) ? value : undefined; } /** Built-in value references. */ var objectCreate = Object.create; /** * The base implementation of `_.create` without support for assigning * properties to the created object. * * @private * @param {Object} proto The object to inherit from. * @returns {Object} Returns the new object. */ var baseCreate = (function() { function object() {} return function(proto) { if (!isObject(proto)) { return {}; } if (objectCreate) { return objectCreate(proto); } object.prototype = proto; var result = new object; object.prototype = undefined; return result; }; }()); /** * A faster alternative to `Function#apply`, this function invokes `func` * with the `this` binding of `thisArg` and the arguments of `args`. * * @private * @param {Function} func The function to invoke. * @param {*} thisArg The `this` binding of `func`. * @param {Array} args The arguments to invoke `func` with. * @returns {*} Returns the result of `func`. */ function apply(func, thisArg, args) { switch (args.length) { case 0: return func.call(thisArg); case 1: return func.call(thisArg, args[0]); case 2: return func.call(thisArg, args[0], args[1]); case 3: return func.call(thisArg, args[0], args[1], args[2]); } return func.apply(thisArg, args); } /** * Copies the values of `source` to `array`. * * @private * @param {Array} source The array to copy values from. * @param {Array} [array=[]] The array to copy values to. * @returns {Array} Returns `array`. */ function copyArray(source, array) { var index = -1, length = source.length; array || (array = Array(length)); while (++index < length) { array[index] = source[index]; } return array; } /** Used to detect hot functions by number of calls within a span of milliseconds. */ var HOT_COUNT = 800, HOT_SPAN = 16; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeNow = Date.now; /** * Creates a function that'll short out and invoke `identity` instead * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN` * milliseconds. * * @private * @param {Function} func The function to restrict. * @returns {Function} Returns the new shortable function. */ function shortOut(func) { var count = 0, lastCalled = 0; return function() { var stamp = nativeNow(), remaining = HOT_SPAN - (stamp - lastCalled); lastCalled = stamp; if (remaining > 0) { if (++count >= HOT_COUNT) { return arguments[0]; } } else { count = 0; } return func.apply(undefined, arguments); }; } /** * Creates a function that returns `value`. * * @static * @memberOf _ * @since 2.4.0 * @category Util * @param {*} value The value to return from the new function. * @returns {Function} Returns the new constant function. * @example * * var objects = _.times(2, _.constant({ 'a': 1 })); * * console.log(objects); * // => [{ 'a': 1 }, { 'a': 1 }] * * console.log(objects[0] === objects[1]); * // => true */ function constant(value) { return function() { return value; }; } var defineProperty = (function() { try { var func = getNative(Object, 'defineProperty'); func({}, '', {}); return func; } catch (e) {} }()); /** * The base implementation of `setToString` without support for hot loop shorting. * * @private * @param {Function} func The function to modify. * @param {Function} string The `toString` result. * @returns {Function} Returns `func`. */ var baseSetToString = !defineProperty ? identity : function(func, string) { return defineProperty(func, 'toString', { 'configurable': true, 'enumerable': false, 'value': constant(string), 'writable': true }); }; /** * Sets the `toString` method of `func` to return `string`. * * @private * @param {Function} func The function to modify. * @param {Function} string The `toString` result. * @returns {Function} Returns `func`. */ var setToString = shortOut(baseSetToString); /** Used as references for various `Number` constants. */ var MAX_SAFE_INTEGER$1 = 9007199254740991; /** Used to detect unsigned integer values. */ var reIsUint = /^(?:0|[1-9]\d*)$/; /** * Checks if `value` is a valid array-like index. * * @private * @param {*} value The value to check. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. */ function isIndex(value, length) { var type = typeof value; length = length == null ? MAX_SAFE_INTEGER$1 : length; return !!length && (type == 'number' || (type != 'symbol' && reIsUint.test(value))) && (value > -1 && value % 1 == 0 && value < length); } /** * The base implementation of `assignValue` and `assignMergeValue` without * value checks. * * @private * @param {Object} object The object to modify. * @param {string} key The key of the property to assign. * @param {*} value The value to assign. */ function baseAssignValue(object, key, value) { if (key == '__proto__' && defineProperty) { defineProperty(object, key, { 'configurable': true, 'enumerable': true, 'value': value, 'writable': true }); } else { object[key] = value; } } /** * Performs a * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) * comparison between two values to determine if they are equivalent. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. * @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @example * * var object = { 'a': 1 }; * var other = { 'a': 1 }; * * _.eq(object, object); * // => true * * _.eq(object, other); * // => false * * _.eq('a', 'a'); * // => true * * _.eq('a', Object('a')); * // => false * * _.eq(NaN, NaN); * // => true */ function eq(value, other) { return value === other || (value !== value && other !== other); } /** Used for built-in method references. */ var objectProto$7 = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$6 = objectProto$7.hasOwnProperty; /** * Assigns `value` to `key` of `object` if the existing value is not equivalent * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) * for equality comparisons. * * @private * @param {Object} object The object to modify. * @param {string} key The key of the property to assign. * @param {*} value The value to assign. */ function assignValue(object, key, value) { var objValue = object[key]; if (!(hasOwnProperty$6.call(object, key) && eq(objValue, value)) || (value === undefined && !(key in object))) { baseAssignValue(object, key, value); } } /** * Copies properties of `source` to `object`. * * @private * @param {Object} source The object to copy properties from. * @param {Array} props The property identifiers to copy. * @param {Object} [object={}] The object to copy properties to. * @param {Function} [customizer] The function to customize copied values. * @returns {Object} Returns `object`. */ function copyObject(source, props, object, customizer) { var isNew = !object; object || (object = {}); var index = -1, length = props.length; while (++index < length) { var key = props[index]; var newValue = customizer ? customizer(object[key], source[key], key, object, source) : undefined; if (newValue === undefined) { newValue = source[key]; } if (isNew) { baseAssignValue(object, key, newValue); } else { assignValue(object, key, newValue); } } return object; } /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeMax$1 = Math.max; /** * A specialized version of `baseRest` which transforms the rest array. * * @private * @param {Function} func The function to apply a rest parameter to. * @param {number} [start=func.length-1] The start position of the rest parameter. * @param {Function} transform The rest array transform. * @returns {Function} Returns the new function. */ function overRest(func, start, transform) { start = nativeMax$1(start === undefined ? (func.length - 1) : start, 0); return function() { var args = arguments, index = -1, length = nativeMax$1(args.length - start, 0), array = Array(length); while (++index < length) { array[index] = args[start + index]; } index = -1; var otherArgs = Array(start + 1); while (++index < start) { otherArgs[index] = args[index]; } otherArgs[start] = transform(array); return apply(func, this, otherArgs); }; } /** * The base implementation of `_.rest` which doesn't validate or coerce arguments. * * @private * @param {Function} func The function to apply a rest parameter to. * @param {number} [start=func.length-1] The start position of the rest parameter. * @returns {Function} Returns the new function. */ function baseRest(func, start) { return setToString(overRest(func, start, identity), func + ''); } /** Used as references for various `Number` constants. */ var MAX_SAFE_INTEGER = 9007199254740991; /** * Checks if `value` is a valid array-like length. * * **Note:** This method is loosely based on * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. * @example * * _.isLength(3); * // => true * * _.isLength(Number.MIN_VALUE); * // => false * * _.isLength(Infinity); * // => false * * _.isLength('3'); * // => false */ function isLength(value) { return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; } /** * Checks if `value` is array-like. A value is considered array-like if it's * not a function and has a `value.length` that's an integer greater than or * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is array-like, else `false`. * @example * * _.isArrayLike([1, 2, 3]); * // => true * * _.isArrayLike(document.body.children); * // => true * * _.isArrayLike('abc'); * // => true * * _.isArrayLike(_.noop); * // => false */ function isArrayLike(value) { return value != null && isLength(value.length) && !isFunction(value); } /** * Checks if the given arguments are from an iteratee call. * * @private * @param {*} value The potential iteratee value argument. * @param {*} index The potential iterate