UNPKG

@vuemap/vue-amap

Version:

高德地图vue3版本封装

109 lines (104 loc) 3.31 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); require('../../../mixins/index.js'); var guid = require('../../../utils/guid.js'); var props = require('./props.js'); var useRegister = require('../../../mixins/useRegister.js'); const _hoisted_1 = { style: { "display": "none" } }; var script = /* @__PURE__ */ vue.defineComponent({ ...{ name: "ElAmapInfoWindow", inheritAttrs: false }, __name: "InfoWindow", props: props.propsTypes, emits: ["init", "update:visible"], setup(__props, { expose: __expose, emit: __emit }) { const props = __props; const emits = __emit; const needTeleport = !props.content; const tempId = `info-${guid.default()}`; const divId = vue.ref(""); let $amapComponent; const { $$getInstance, parentInstance } = useRegister.useRegister((options, parentComponent) => { return new Promise((resolve) => { if (!options.content) { options.content = `<div id="${tempId}"></div>`; } $amapComponent = new AMap.InfoWindow(options); $amapComponent.on("close", () => { emits("update:visible", false); }); if (props.visible) { $amapComponent.open(parentComponent, props.position); if (needTeleport) { divId.value = tempId; vue.nextTick(() => { $amapComponent.setAnchor($amapComponent.getAnchor()); }); } } resolve($amapComponent); }); }, { emits, watchRedirectFn: { __position(position) { if (props.visible) { $amapComponent.open(parentInstance == null ? void 0 : parentInstance.$amapComponent, position); if (needTeleport) { divId.value = tempId; } } else { $amapComponent.setPosition(position); } }, __visible(flag) { const position = $amapComponent.getPosition(); if (position) { if (!flag) { $amapComponent.close(); } else { $amapComponent.open(parentInstance == null ? void 0 : parentInstance.$amapComponent, [position.lng, position.lat]); if (needTeleport) { divId.value = tempId; vue.nextTick(() => { $amapComponent.setAnchor($amapComponent.getAnchor()); }); } } } } }, destroyComponent() { if ($amapComponent) { if ($amapComponent.getIsOpen()) { $amapComponent.close(); } $amapComponent = null; } } }); vue.onUnmounted(() => { if ($amapComponent) { $amapComponent.close(); } }); __expose({ $$getInstance }); return (_ctx, _cache) => { return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [ !!divId.value ? (vue.openBlock(), vue.createBlock(vue.Teleport, { key: 0, to: "#" + divId.value }, [ vue.renderSlot(_ctx.$slots, "default") ], 8, ["to"])) : vue.createCommentVNode("v-if", true) ]); }; } }); exports.default = script; //# sourceMappingURL=InfoWindow.vue2.js.map