UNPKG

@vuemap/vue-amap-extra

Version:

@vuemap/vue-amap扩展库,包含threejs相关图层

215 lines (212 loc) 6.02 kB
import { defineComponent, ref, getCurrentInstance, watch, openBlock, createElementBlock, createElementVNode, renderSlot } from 'vue'; import { buildProps, useRegister } from '@vuemap/vue-amap'; import { CSS2DObject } from '../ThreeLayer/CSS2DRenderer.mjs'; import { CSS3DObject } from '../ThreeLayer/CSS3DRenderer.mjs'; import CustomThreeGltf from './CustomThreeGltf.mjs'; const _hoisted_1 = { style: { "display": "none" } }; const _hoisted_2 = { class: "content-container", style: { "transform": "translate(-50%, -100%)", "position": "absolute" } }; var script = /* @__PURE__ */ defineComponent({ ...{ name: "ElAmapThreeGltf", inheritAttrs: false }, __name: "ThreeGltf", props: buildProps({ url: { type: String }, position: { type: Array }, height: { type: Number, default: 0 }, rotation: { type: Object }, scale: { type: [Number, Array], default: 1 }, angle: { type: Number, default: 0 }, moveAnimation: { type: Object }, //位置移动是否开启动画 configLoader: { type: Function }, useModelCache: { type: Boolean, default: false }, showPopup: { type: Boolean, default: false }, popupHeight: { //弹窗距离模型中心点的高度 type: Number, default: 0 }, popupScale: { //三维弹窗的缩放比例(只有在popupType为3D时生效) type: [Number, Array], default: 1 }, popupType: { //信息弹窗类型 type: String, default: "2D" } }), emits: [ "init", "click", "mousemove", "mouseover", "mouseout" ], setup(__props, { expose: __expose, emit: __emit }) { const popupRef = ref(); const props = __props; const emits = __emit; let $amapComponent; let popup; const currentInstance = getCurrentInstance(); const { $$getInstance, parentInstance } = useRegister( (options, parentComponent) => { return new Promise((resolve) => { $amapComponent = new CustomThreeGltf( parentComponent, options, { $emit: emits, ...(currentInstance == null ? void 0 : currentInstance.exposed) || {} }, () => { addPopup($amapComponent); resolve($amapComponent); } ); }); }, { emits, destroyComponent() { var _a, _b, _c; if ($amapComponent && (parentInstance == null ? void 0 : parentInstance.$amapComponent)) { if (!parentInstance.isDestroy) { $amapComponent.remove(); } (_c = (_b = (_a = $amapComponent.layer) == null ? void 0 : _a.cssRenderer) == null ? void 0 : _b.domElement) == null ? void 0 : _c.remove(); $amapComponent.destroy(); $amapComponent = null; } } } ); const addPopup = (instance) => { var _a, _b, _c; const element = popupRef.value; const contentEle = element.querySelector(".content-container"); if (((_a = contentEle == null ? void 0 : contentEle.children) == null ? void 0 : _a.length) == 0) return; if (props.popupType === "2D") { if (!((_b = instance == null ? void 0 : instance.layer) == null ? void 0 : _b.css2DRenderer)) { return; } const css2dObject = new CSS2DObject(element); css2dObject.center.set(0.5, 1); css2dObject.translateY(props.popupHeight || 0); popup = css2dObject; popup.visible = props.showPopup; instance.object.add(popup); } else if (props.popupType === "3D") { if (!((_c = instance == null ? void 0 : instance.layer) == null ? void 0 : _c.css3DRenderer)) { return; } const scales = typeof props.popupScale === "number" ? [props.popupScale, props.popupScale, props.popupScale] : props.popupScale; const css3DObject = new CSS3DObject(element); css3DObject.translateY(props.popupHeight || 0); css3DObject.scale.set(scales[0], scales[1], scales[2]); popup = css3DObject; popup.visible = props.showPopup; instance.object.add(popup); } instance == null ? void 0 : instance.refresh(); }; const $$startAnimations = () => { $amapComponent.startAnimations(); }; const $$stopAnimations = () => { $amapComponent.stopAnimations(); }; __expose({ $$getInstance, $$startAnimations, $$stopAnimations }); watch( () => props.showPopup, (val) => { if (val && !popup) { addPopup($amapComponent); return; } if (popup) { popup.visible = val; $amapComponent.refresh(); } } ); watch( () => props.popupHeight, (val, old) => { if (popup) { const changeVal = (val || 0) - (old || 0); popup.translateY(changeVal || 0); $amapComponent.refresh(); } } ); watch( () => props.popupScale, (val) => { if (popup && val) { const scales = typeof val === "number" ? [val, val, val] : val; popup.scale.set(scales[0], scales[1], scales[2]); $amapComponent.refresh(); } } ); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", _hoisted_1, [ createElementVNode( "div", { ref_key: "popupRef", ref: popupRef, style: { "width": "0", "height": "0", "position": "relative" } }, [ createElementVNode("div", _hoisted_2, [ renderSlot(_ctx.$slots, "default") ]) ], 512 /* NEED_PATCH */ ) ]); }; } }); export { script as default }; //# sourceMappingURL=ThreeGltf.vue2.mjs.map