UNPKG

@vuemap/vue-amap

Version:

高德地图vue3版本封装

104 lines (99 loc) 3.32 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); require('../../../mixins/index.js'); var buildHelper = require('../../../utils/buildHelper.js'); require('../../../utils/index.js'); var guid = require('../../../utils/guid.js'); var props = require('./props.js'); var useRegister = require('../../../mixins/useRegister.js'); var util = require('../../../utils/util.js'); const _hoisted_1 = { style: { "display": "none" } }; var script = /* @__PURE__ */ vue.defineComponent({ ...{ name: "ElAmapMarker", inheritAttrs: false }, __name: "Marker", props: buildHelper.buildProps(props.propsTypes), emits: ["init", "update:position"], setup(__props, { expose: __expose, emit: __emit }) { const props = __props; const emits = __emit; const tempId = `marker-${guid.default()}`; const divId = vue.ref(""); let $amapComponent; let withSlot = false; const $slots = vue.useSlots(); const { $$getInstance, parentInstance } = useRegister.useRegister((options, parentComponent) => { return new Promise((resolve) => { if ($slots.default && $slots.default().length > 0) { withSlot = true; options.content = `<div id="${tempId}"></div>`; } $amapComponent = new AMap.Marker(options); if (util.isMapInstance(parentComponent)) { parentComponent.add($amapComponent); } else if (util.isOverlayGroupInstance(parentComponent)) { parentComponent.addOverlay($amapComponent); } if (withSlot) { divId.value = tempId; vue.nextTick(() => { $amapComponent.setAnchor($amapComponent.getAnchor()); }); } bindModelEvents(); resolve($amapComponent); }); }, { emits, watchRedirectFn: { __position(position) { if (!props.moveOptions) { $amapComponent.setPosition(position); return; } if (parentInstance == null ? void 0 : parentInstance.$amapComponent) { parentInstance.$amapComponent.plugin("AMap.MoveAnimation", () => { $amapComponent.moveTo(position, props.moveOptions); }); } } }, destroyComponent() { if ($amapComponent && (parentInstance == null ? void 0 : parentInstance.$amapComponent)) { $amapComponent.setMap(null); $amapComponent = null; } } }); const bindModelEvents = () => { $amapComponent.on("dragend", () => { emitPosition(); }); $amapComponent.on("touchend", () => { emitPosition(); }); }; const emitPosition = () => { const position = $amapComponent.getPosition(); emits("update:position", position.toArray()); }; __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=Marker.vue2.js.map