import Vue from 'vue';
import Label from './index.vue';
const WindowVm = Vue.extend(Label);
export default class Bubble {
    innerHTML;
    vmInstance;
    childNode;
    viewer;
    type;
    postRender;
    constructor(viewer) {
        this.viewer = viewer;
    }
    create(val) {
        this.vmInstance = new WindowVm({
            propsData: {
                lng: val.lng,
                lat: val.lat,
                height: val.height,
                unit: val.unit,
                type: val.type
            }
        }).$mount(); // 根据模板创建一个面板
        if (!this.vmInstance) {
            return;
        }
        this.innerHTML = this.vmInstance.$el.innerHTML;
        this.childNode = this.vmInstance.$el;
        this.vmInstance.closeEvent = () => {
            this.windowClose();
        };
        if (!this.postRender) {
            this.postRender = val.postRender;
        }
    }
    changValue(value) {
        if (this.vmInstance && this.vmInstance.changValue) {
            this.vmInstance.changValue(value);
        }
    }
    changePositions(left, bottom, pointPosition) {
        if (!this.vmInstance.$el || !this.vmInstance.$el.style)
            return;
        this.vmInstance.$el.style.left = left + 10 + 'px';
        this.vmInstance.$el.style.bottom =
            bottom - this.vmInstance.$el.clientHeight - 5 + 'px';
        this.vmInstance.$el.style.position = 'absolute';
        // 3D模式
        console.log('🚀 ~ Bubble ~ pointPosition', pointPosition);
        // const cameraPosition = this.viewer.camera.position
        // let height = this.viewer.scene.globe.ellipsoid.cartesianToCartographic(
        //   cameraPosition
        // ).height
        // height += this.viewer.scene.globe.ellipsoid.maximumRadius
        // if (!(Cesium.Cartesian3.distance(cameraPosition, pointPosition) > height)) {
        //   this.vmInstance.$el.style.display = 'block'
        // } else {
        //   this.vmInstance.$el.style.display = 'none'
        // }
        // 2.5D模式
        this.vmInstance.$el.style.display = 'block';
    }
    windowClose() {
        if (this.vmInstance) {
            this.vmInstance.$el.remove();
            this.vmInstance.$destroy();
        }
        this.viewer &&
            this.viewer.scene.postRender.addEventListener(() => this.postRender, this);
    }
}
