UNPKG

@vuemap/vue-amap

Version:

高德地图vue3版本封装

105 lines (102 loc) 3.29 kB
import { defineComponent, ref, nextTick, onUnmounted, openBlock, createElementBlock, createBlock, Teleport, renderSlot, createCommentVNode } from 'vue'; import '../../../mixins/index.mjs'; import guid from '../../../utils/guid.mjs'; import { propsTypes } from './props.mjs'; import { useRegister } from '../../../mixins/useRegister.mjs'; const _hoisted_1 = { style: { "display": "none" } }; var script = /* @__PURE__ */ defineComponent({ ...{ name: "ElAmapInfoWindow", inheritAttrs: false }, __name: "InfoWindow", 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()}`; const divId = ref(""); let $amapComponent; const { $$getInstance, parentInstance } = 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; 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; nextTick(() => { $amapComponent.setAnchor($amapComponent.getAnchor()); }); } } } } }, destroyComponent() { if ($amapComponent) { if ($amapComponent.getIsOpen()) { $amapComponent.close(); } $amapComponent = null; } } }); onUnmounted(() => { if ($amapComponent) { $amapComponent.close(); } }); __expose({ $$getInstance }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", _hoisted_1, [ !!divId.value ? (openBlock(), createBlock(Teleport, { key: 0, to: "#" + divId.value }, [ renderSlot(_ctx.$slots, "default") ], 8, ["to"])) : createCommentVNode("v-if", true) ]); }; } }); export { script as default }; //# sourceMappingURL=InfoWindow.vue2.mjs.map