import { MeshNormalMaterial, MeshLambertMaterial, MeshStandardMaterial, MeshPhysicalMaterial, MeshPhongMaterial, MeshBasicMaterial, LineBasicMaterial, SpriteMaterial, Vector2, Shape, Mesh, ExtrudeGeometry, LineSegments, EdgesGeometry, Object3D } from 'three';

/******************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

function __awaiter(thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
}

const material = {
    MeshNormalMaterial,
    MeshLambertMaterial,
    MeshStandardMaterial,
    MeshPhysicalMaterial,
    MeshPhongMaterial,
    MeshBasicMaterial,
    LineBasicMaterial,
    SpriteMaterial
};
const OBJECT_BASE_CONF = {
    // floor: {
    //   name: 'floor',
    //   material: 'MeshLambertMaterial',
    //   color: '#fff',
    //   transparent: true,
    //   opacity: 1
    // },
    floor: {
        name: 'floor',
        material: 'MeshBasicMaterial',
        color: '#fff',
        transparent: true,
        opacity: 1
    },
    // park: {
    //   name: 'park',
    //   material: 'MeshLambertMaterial',
    //   color: '#44c3b4',
    //   transparent: true,
    //   opacity: 1
    //   // depthWrite: false,
    //   // depthTest: false,
    // },
    park: {
        name: 'park',
        material: 'MeshBasicMaterial',
        color: '#44c3b4',
        transparent: true,
        opacity: 1
        // depthWrite: false,
        // depthTest: false,
    },
    parkBorder: {
        name: 'parkBorder',
        material: 'LineBasicMaterial',
        color: '#f6ffed',
        // color: '#fff',
        transparent: true,
        opacity: 0.8
        // opacity: 1
        // 线框添加这个属性，就比较不会有锯齿闪烁的现象，但是其他物体会挡不住线框
        // depthTest: false
    },
    pillar: {
        name: 'pillar',
        material: 'MeshLambertMaterial',
        // material: 'MeshStandardMaterial',
        color: '#e7e7e7',
        // depthWrite: false,
        transparent: true,
        opacity: 1
    },
    machine: {
        name: 'machine',
        material: 'SpriteMaterial'
    },
    // 通行设施
    connector: {
        name: 'connector',
        material: 'SpriteMaterial'
    }
};
/**
 * @desc 数组坐标转换为 threejs 坐标
 */
const arrayPoints23Points = (points) => {
    const shapePoints = [];
    let point;
    for (let i = 0, len = points.length; i < len; i += 2) {
        point = new Vector2(+points[i], +points[i + 1]);
        shapePoints.push(point);
    }
    return shapePoints;
};
/**
 * @desc 赋值 Material 的时候去掉一些没有必要的属性
 */
const deletePropertyForMaterial = (conf) => {
    const newConf = JSON.parse(JSON.stringify(conf));
    Reflect.deleteProperty(newConf, 'material');
    Reflect.deleteProperty(newConf, 'renderOrder');
    Reflect.deleteProperty(newConf, 'depth');
    return newConf;
};
const renderOrderConf = [
    ['floor'],
    ['park'],
    ['parkBorder'],
    ['pillar'],
    ['machine', 'connector']
];
/**
 * @desc 根据楼层索引返回新的 renderOrder 保证遮盖了比它低的楼层物体
 */
const getRenderOrderPlusByLevel = (level) => renderOrderConf.length * level;
const getRenderOrder = (name) => {
    const index = renderOrderConf.findIndex(item => item.find(itemj => itemj === name));
    return index > -1 ? index : 0;
};
/**
 * ！！！需要替换掉
 * @desc 皮肤颜色，初始化时候需要判断本地存储然后把颜色值赋值给 OBJECT_BASE_CONF
 */
const THEME = {
    normal: {
        // floor: { color: '#484f5a' },
        // park: { color: '#689f79' },
        // parkBorder: { color: '#fff' },
        // pillar: { color: '#fff' },
        // machine: { color: '' },
        // connector: { color: '' }
        // 调整主题颜色
        floor: { color: '#dee3f1' },
        park: { color: '#ffffff' },
        parkBorder: { color: '#dee3f1' },
        pillar: { color: '#ffffff' },
        // pillar: { color: '#e8eef7' },
        // pillar: { color: 'transparent' },
        // pillar: { color: 'red' },
        machine: { color: '' },
        connector: { color: '' }
    }
};
const currTheme = THEME.normal;
for (const key of Object.keys(OBJECT_BASE_CONF)) {
    // @ts-ignore
    OBJECT_BASE_CONF[key].color = currTheme[key].color;
    // @ts-ignore 初始化 渲染顺序 renderOrder
    OBJECT_BASE_CONF[key].renderOrder = getRenderOrder(key);
}
/**
 * @desc 获取当前楼层整体对象
 */
// export function getCurrentLevelObj(
//   currentLevel: number | string,
//   parent: Object3D
// ) {
//   currentLevel = parseInt(currentLevel as string);
//   const levelObj = getObjectsByName<Object3D>(OBJECT_NAME.level, parent).find(
//     _ => _.userData.zIndex === currentLevel
//   );
//   return levelObj;
// }
// export function getDollys(
//   targetMesh: Mesh,
//   controls: MyCameraControls,
//   offset = 5
// ) {
//   if (!targetMesh) {
//     return { fitDistance: 0, dollys: [0] };
//   }
//   const bb = new Box3().setFromObject(targetMesh);
//   const fitDistance = controls.getDistanceToFitBox(
//     bb.max.x - bb.min.x,
//     bb.max.y - bb.min.y,
//     bb.max.z - bb.min.z
//   );
//   const minDollys = [...new Array(offset)]
//     .map((_, i) => fitDistance / (i + 2))
//     .reverse();
//   const maxDollys = [...new Array(offset)].map((_, i) => fitDistance * (i + 2));
//   const dollys = [...minDollys, fitDistance, ...maxDollys];
//   return { fitDistance, dollys };
// }

/**
 * @desc 统一配置对象的 name 属性
 */
var OBJECT_NAME;
(function (OBJECT_NAME) {
    OBJECT_NAME["level"] = "level";
    OBJECT_NAME["floor"] = "floor";
    OBJECT_NAME["park"] = "park";
    OBJECT_NAME["parkBorder"] = "parkBorder";
    OBJECT_NAME["pillar"] = "pillar";
    OBJECT_NAME["machine"] = "machine";
    OBJECT_NAME["connector"] = "connector";
})(OBJECT_NAME || (OBJECT_NAME = {}));
var ICONNECTOR;
(function (ICONNECTOR) {
    ICONNECTOR[ICONNECTOR["zhiti"] = 1] = "zhiti";
    ICONNECTOR[ICONNECTOR["futi"] = 2] = "futi";
    ICONNECTOR[ICONNECTOR["louti"] = 3] = "louti";
    ICONNECTOR[ICONNECTOR["churukou"] = 4] = "churukou";
})(ICONNECTOR || (ICONNECTOR = {}));

function mitt(n){return {all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e]);},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]));},emit:function(t,e){var i=n.get(t);i&&i.slice().map(function(n){n(e);}),(i=n.get("*"))&&i.slice().map(function(n){n(t,e);});}}}

/**
 * mitt 事件总程
 */
class MyMitt {
    constructor() {
        Object.defineProperty(this, "emitter", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: mitt()
        });
    }
    on(type, handler) {
        this.emitter.on(type, handler);
        return this;
    }
    off(type, handler) {
        this.emitter.off(type, handler);
        return this;
    }
}

/**
 * 基类，element
 *
 * 被添加到地图上的元素
 *
 * 若当前扩展类不需要 mitt，在继承时，泛型填写 any，如：
 *
 * ```ts
 * class Foo extends Element<any>{
 *
 * }
 * ```
 */
class Element extends MyMitt {
    constructor() {
        super();
        /**
         * NAME
         * 一般为子类的类名（防止工具压缩把类名压缩了，导致一些拿类名判断的逻辑失效，所以手动加上类名）
         */
        // abstract NAME: string;
        Object.defineProperty(this, "map", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
    }
    /**
     * __inject
     * 当元素被 map.add 之后，会注入整个 map 对象到子类，提供子类使用 map
     */
    __inject(map) {
        this.map = map;
        return this;
    }
}

// import Facility from './facility'
const tempIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAjCAYAAACD1LrRAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAARISURBVHgBzVdtaFtlFH5uetsmWZY0pWm3ZvZLhA23dgoV/GW1nYgoY/6QDoSuiIRRFOZQsGt+hOFAEWUqiEz8mOLU4aYUrDB0Y9pYBFltVwcTBt3akDVb0nwsTZrk3p2T3Rtu892Qwp7Lk3vf+557nnvO+77nvgE0kGW5g3ieGJCri7PEduSDIlptQS0CWnFBvZAk6SdBEPby9URwGu/7xjEdm0dKllAJ6gQRO/R2jLbsw57N3ertC6TxpFZYpLdJ8MW50AyGr3+CqBxHNWDU1eOzBxx4xrybm8skbKNzUqe+oGp47ObZqokyolIc7y2Nq80GVUsVrlV7rsQXUW38uzKvbdYQaSDupVt9AazKyYyFTTSj37QLgoB1Qabjt/AsfMlwup2ClC0MMWObB/2mnTjYtAe/hC5hPXjW/Eja43fL7oI2qnDemARBh8ux63hn6WesB211TeSweJp02AAkaLiSlOANF9ZRdMe27oddtKbbTu8POBP8u8QzVYBEA3oltogv20fQUWdDOLVSsvCownL+bhmSjLLwTeAPnPRfxMf2l7FVbChmmvZYdHJN0Gz+PTyXvu41PIg3mp/H/vkPM8vjsO052GrNGXueUFbRiPGuN9H3vwuR/IVIpxXOi+VUlH6jadGPtg3j0OLJNWtyLrYAc8KQadfQKug1dGEh6cdqiclVVBhKpO+2voTDnq/xV/Tqmr5fw9OZa47W2fICrq0u4XWy1RaiLKxJdd6RbKox4duO1xCTkjhCXxktFhMBvHLjU0UUOLrlRbTWNuKQ5yuE0pkqjqJj7CcHn98+j6c398Dl/ZFSH8n0RaWExlLAXHwBb988gxU5gXJQNNUSHcdvTaBOJ2K48Qm85TmFgHQnx45r86nAJNaDkuuYP2tHKdrbyQiObztQshSWCzH3ho7K3drFzwVizPs9Ht/0EAou+SKoE3ITm1NAug0F9mR0uO9crUAW2F5vLygspFKp9MeTi4JRqEe1wL6ObNlXUBixWOw/PvPe6Iu2g+jRt+dNUbmoIdePGjpxos2BAdpMMILB4DmtjWC1Wi1jY2NPJZPJkLxBYN+jo6P9pMc1NjNDjcROh8Ox1+PxXJSriEQiEfb5fJfYt16v7ySdTSyc2d4SLcRm5Y1qs1M3NDTUOjg4uHtgYOBVURRN2j6KJjIzM3N6ZGTk9NTUlFplZCUyXiJcVXgO3SIG+BHt8/WKcBdxB/Fh4k7NuYf4mNPpPJAdlcvlGqK+XiJvnndpnmNu52wSbYpGTiEQlEiNStQNFouFtxTMRpPJ1Kw46HG73R+oorOzsyfoHv9V6CC2sK3CBobiy6j4Lll9hCzy7OdtKY8PL8puv9//j9frvcARGgwGu9InKrbZz+egBuVBVphSKMTj8cuTk5N/0pjeoDH2070V3BvPsmpMJYWXI+LJpW49QsSIIrrh4JTy1sPY19dXeZWpEAXH777GXafq3MOcWpbiAAAAAElFTkSuQmCC';
// enum FACILITY_ICON {
//   futi = require('./imgs/icon_futi.png'),
//   machine = require('./imgs/icon_zhaocheji.png'),
//   louti = require('./imgs/icon_louti.png'),
//   zhiti = require('./imgs/icon_zhiti.png'),
//   churukou = require('./imgs/icon_churukou.png')
// }
var FACILITY_ICON;
(function (FACILITY_ICON) {
    // @ts-ignore
    FACILITY_ICON[FACILITY_ICON["futi"] = tempIcon] = "futi";
    // @ts-ignore
    FACILITY_ICON[FACILITY_ICON["machine"] = tempIcon] = "machine";
    // @ts-ignore
    FACILITY_ICON[FACILITY_ICON["louti"] = tempIcon] = "louti";
    // @ts-ignore
    FACILITY_ICON[FACILITY_ICON["zhiti"] = tempIcon] = "zhiti";
    // @ts-ignore
    FACILITY_ICON[FACILITY_ICON["churukou"] = tempIcon] = "churukou";
})(FACILITY_ICON || (FACILITY_ICON = {}));
class ParkingLayer extends Element {
    constructor({ name = '', data, poiCollision = true }) {
        super();
        Object.defineProperty(this, "options", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "info", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: new Map()
        });
        Object.defineProperty(this, "floorIdSort", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: []
        });
        // 基础配置
        Object.defineProperty(this, "basicSetting", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: {
                // 50米
                floorHeight: 50,
                // 1:1mm
                coordinateScale: 1
            }
        });
        /**
         * @desc 绘制策略
         */
        Object.defineProperty(this, "drawObjectStrategy", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: {
                floor: (data, renderOrderPlus, height) => {
                    const zHeight = this.getZHeight(height);
                    const item = data && data[0];
                    if (!item)
                        return [];
                    const conf = OBJECT_BASE_CONF[OBJECT_NAME.floor];
                    const newConf = deletePropertyForMaterial(conf);
                    const mat = new material[conf.material](Object.assign({}, newConf));
                    const points = arrayPoints23Points(item.outline);
                    const shape = new Shape(points);
                    const mesh = new Mesh();
                    mesh.material = mat;
                    // const updateGeometry = (depth?: number) => {
                    //   depth = depth ?? zHeight
                    //   // 拉伸造型
                    //   const geo = new ExtrudeGeometry(
                    //     // 二维轮廓
                    //     shape,
                    //     {
                    //       // 拉伸长度
                    //       depth,
                    //       // 无倒角
                    //       bevelEnabled: false
                    //     }
                    //   )
                    //   // @ts-ignore
                    //   mesh.material.depthTest = !(depth === 0)
                    //   return generateGeometry(mesh, geo)
                    // }
                    // updateGeometry()
                    const geo = new ExtrudeGeometry(
                    // 二维轮廓
                    shape, {
                        // 拉伸长度
                        // depth: zHeight,
                        depth: 1,
                        // 无倒角
                        bevelEnabled: false
                    });
                    mesh.geometry = geo;
                    mesh.name = OBJECT_NAME.floor;
                    // // 自定义赋值该对象的相关，添加闭包方法 generateGeometryFn ，为了更新灵活
                    // mesh.userData = { ...item, zHeight, updateGeometry }
                    mesh.userData = Object.assign(Object.assign({}, item), { zHeight });
                    mesh.renderOrder = conf.renderOrder + renderOrderPlus;
                    return [mesh];
                },
                park: (data, renderOrderPlus, height, zIndex) => {
                    const zHeight = this.getZHeight(height);
                    const item = data[0];
                    if (!item)
                        return [];
                    const conf = OBJECT_BASE_CONF[OBJECT_NAME.park];
                    const newConf = deletePropertyForMaterial(conf);
                    const mat = new material[conf.material](Object.assign({}, newConf));
                    let points;
                    const meshs = [];
                    for (const item of data) {
                        points = arrayPoints23Points(item.outline);
                        const shape = new Shape(points);
                        const mesh = new Mesh();
                        mesh.position.z = 2;
                        const line = new LineSegments();
                        // 防止重叠闪烁
                        line.position.z = mesh.position.z * 2 + 1;
                        mesh.material = mat;
                        const conf2 = OBJECT_BASE_CONF[OBJECT_NAME.parkBorder];
                        const newConf2 = deletePropertyForMaterial(conf2);
                        const matLine = new material[conf2.material](newConf2);
                        line.material = matLine;
                        // const updateGeometry = (depth?: number) => {
                        //   depth = depth ?? zHeight
                        //   // 拉伸造型
                        //   const geo = new ExtrudeGeometry(
                        //     // 二维轮廓
                        //     shape,
                        //     {
                        //       // 拉伸长度
                        //       depth,
                        //       // 无倒角
                        //       bevelEnabled: false
                        //     }
                        //   )
                        //   generateGeometry(line, new EdgesGeometry(geo, 20))
                        //   // @ts-ignore
                        //   mesh.material.depthTest = !(depth === 0)
                        //   return generateGeometry(mesh, geo)
                        // }
                        // updateGeometry()
                        const geo = new ExtrudeGeometry(
                        // 二维轮廓
                        shape, {
                            // 拉伸长度
                            // depth: zHeight,
                            // 防止重叠闪烁
                            depth: 1,
                            // 无倒角
                            bevelEnabled: false
                        });
                        mesh.geometry = geo;
                        // line.geometry = new EdgesGeometry(geo, 20)
                        line.geometry = new EdgesGeometry(geo);
                        mesh.name = OBJECT_NAME.park;
                        // mesh.position.z += 10
                        // line.position.z += 15
                        line.renderOrder = conf2.renderOrder + renderOrderPlus;
                        mesh.renderOrder = conf.renderOrder + renderOrderPlus;
                        // const parkInfo = unref(currentExtraInfo).info?.park || {}
                        // const extraInfo = parkInfo[item.id] || {}
                        mesh.userData = {
                            id: item.id,
                            type: item.type,
                            zHeight,
                            zIndex,
                            // updateGeometry,
                            // ...extraInfo,
                            // 存入相关基础数据，供给 sandTable 使用到
                            data: points
                        };
                        meshs.push(mesh, line);
                    }
                    return meshs;
                },
                pillar: (data, renderOrderPlus, height) => {
                    const item = data[0];
                    if (!item)
                        return [];
                    const zHeight = this.getZHeight(height);
                    const conf = OBJECT_BASE_CONF[OBJECT_NAME.pillar];
                    const newConf = deletePropertyForMaterial(conf);
                    const mat = new material[conf.material](Object.assign({}, newConf));
                    const meshs = [];
                    const draw = (item) => {
                        const mesh = new Mesh();
                        const points = arrayPoints23Points(item.outline);
                        const shape = new Shape(points);
                        mesh.material = mat;
                        // // 闭包，替换成这样的方式，方便可以动态更新一些 geometry 的属性
                        // const updateGeometry = (depth?: number) => {
                        //   depth = depth ?? zHeight
                        //   // 拉伸造型
                        //   const geo = new ExtrudeGeometry(
                        //     // 二维轮廓
                        //     shape,
                        //     {
                        //       // 拉伸长度
                        //       depth,
                        //       // 无倒角
                        //       bevelEnabled: false
                        //     }
                        //   )
                        //   // @ts-ignore
                        //   mesh.material.depthTest = !(depth === 0)
                        //   return generateGeometry(mesh, geo)
                        // }
                        // updateGeometry()
                        const geo = new ExtrudeGeometry(
                        // 二维轮廓
                        shape, {
                            // 拉伸长度
                            depth: zHeight,
                            // 无倒角
                            bevelEnabled: false
                        });
                        mesh.geometry = geo;
                        // 自定义赋值该对象的相关，添加闭包方法 updateGeometry ，为了更新灵活
                        // mesh.userData = { ...item, updateGeometry }
                        mesh.userData = Object.assign({}, item);
                        mesh.name = OBJECT_NAME.pillar;
                        mesh.renderOrder = conf.renderOrder + renderOrderPlus;
                        meshs.push(mesh);
                    };
                    for (const item of data)
                        draw(item);
                    return meshs;
                }
            }
        });
        // private facilityLayer!: PoisLayer;
        Object.defineProperty(this, "_nextTick", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: () => { }
        });
        Object.defineProperty(this, "_updateSize", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: () => { }
        });
        this.options = { name, data, poiCollision };
    }
    nextTick(cb) {
        if (cb) {
            this._nextTick = cb;
            return undefined;
        }
        else {
            return new Promise(resolve => (this._nextTick = resolve));
        }
    }
    __init() {
        return __awaiter(this, void 0, void 0, function* () {
            // // 创建放置交通设施图标图层
            // this.facilityLayer = new PoisLayer({
            //   name: 'facilityLayer',
            //   // collision: false
            //   collision: this.options.poiCollision
            // });
            // TODO:暂时不添加交通设施相关
            // this.facilityLayer.__inject(this.map).__init();
            if (typeof this.options.data === 'function') {
                try {
                    const res = yield this.options.data();
                    const { coordinateScale, floorDatas } = res;
                    // #region 准备相关数据，由于后续添加对象使用
                    this.floorIdSort = floorDatas
                        .map((_) => _.sort)
                        .sort((a, b) => a - b);
                    this.basicSetting.coordinateScale = coordinateScale;
                    // #endregion
                    this.createFloors(floorDatas);
                    // 触发回调
                    this._nextTick();
                    this.emitter.emit('complete');
                }
                catch (error) { }
            }
            else {
                // 直接传递一个 json 数据
                console.log('this.options.data :>> ', this.options.data);
                const res = this.options.data;
                const { coordinateScale, floorDatas } = res;
                // #region 准备相关数据，由于后续添加对象使用
                this.floorIdSort = floorDatas
                    .map((_) => _.sort)
                    .sort((a, b) => a - b);
                this.basicSetting.coordinateScale = coordinateScale;
                // #endregion
                this.createFloors(floorDatas);
                // 触发回调
                this._nextTick();
                this.emitter.emit('complete');
            }
        });
    }
    /**
     * @desc 获取物体需要的高度
     */
    getZHeight(height) {
        return (height * 1000) / this.basicSetting.coordinateScale;
    }
    /**
     * @desc 【待优化？】对楼层数据进行加工
     */
    createFloorBefore(item) {
        // 这里的 data 是新增的属性用来渲染找车机的，之前都是通过url获取的
        const { id, sort, floorName, url, jsonData: extraInfo, data } = item;
        const height = {};
        Object.entries(extraInfo).forEach(item => {
            const [type, data] = item;
            // @ts-ignore
            height[type] = (data === null || data === void 0 ? void 0 : data.h) || 0;
        });
        const floorInfo = {
            id,
            floorName,
            height,
            sort,
            floorData: data
        };
        data.length && this.createFloor(floorInfo);
    }
    /**
     * @desc 创建所有楼层入口
     */
    createFloors(data) {
        for (const item of data) {
            this.createFloorBefore(item);
        }
        const { reDraw, options } = this.map;
        reDraw();
        if (options.viewMode === '2D') {
            this.map.fitToBox2d();
        }
        else if (options.viewMode === '3D') {
            this.map.fitToBox3d();
        }
        // // 自适应
        // const _getTarget = () => {
        //   const allLevelObjs = getObjectsByName(OBJECT_NAME.level, this.map.scene)
        //   // 最高楼层
        //   return allLevelObjs[allLevelObjs.length - 1]
        // }
        // const target = _getTarget()
        // const { fitDistance, dollys } = getDollys(target, this.map.cameraControls)
        // console.log('dollys :>> ', fitDistance, dollys)
        // this.map.cameraControls.dollyTo(fitDistance, true)
    }
    /**
     * @desc 创建单层
     */
    createFloor(floorInfo) {
        // const floorIdSort = computed(
        //   () => (store.state as AllStates).mapModule.floorIdSort
        // )
        // const extraInfoMapArr = computed(
        //   () => (store.state as AllStates).mapModule.extraInfoMapArr
        // )
        const { floorHeight, coordinateScale } = this.basicSetting;
        // const { jsonData: mapData, height, id, sort, floorName: name } = floorInfo
        const { floorData, height, id, sort, floorName: name } = floorInfo;
        console.log('height :>> ', height);
        // const curLevelInfo =
        //   unref(extraInfoMapArr).length &&
        //   unref(extraInfoMapArr).find((f: any) => f.id === id)
        // currentExtraInfo.value = curLevelInfo
        const zIndex = this.floorIdSort.indexOf(sort);
        const renderOrderPlus = getRenderOrderPlusByLevel(zIndex);
        const zHeight = (zIndex * (floorHeight * 1000)) / coordinateScale;
        const dataFloor = floorData.filter((_) => _.type === OBJECT_NAME.floor);
        const meshFloors = this.drawObjectStrategy.floor(dataFloor, renderOrderPlus, 
        // height[OBJECT_NAME.floor]
        1);
        const dataPark = floorData.filter((_) => _.type === OBJECT_NAME.park);
        const meshParks = this.drawObjectStrategy.park(dataPark, renderOrderPlus, 
        // height[OBJECT_NAME.park],
        1, zIndex);
        const dataPillar = floorData.filter((_) => _.type === OBJECT_NAME.pillar);
        const meshPillars = this.drawObjectStrategy.pillar(dataPillar, renderOrderPlus, height[OBJECT_NAME.pillar]);
        const floorGroup = new Object3D();
        const conf = OBJECT_BASE_CONF[OBJECT_NAME.floor];
        meshFloors.length && floorGroup.add(...meshFloors);
        meshParks.length && floorGroup.add(...meshParks);
        meshPillars.length && floorGroup.add(...meshPillars);
        // 绘制通行设施
        // this.drawFacility(floorInfo, zIndex, zHeight);
        floorGroup.name = OBJECT_NAME.level;
        floorGroup.renderOrder = conf.renderOrder + renderOrderPlus;
        floorGroup.position.z = zHeight;
        floorGroup.userData = {
            id,
            name,
            zIndex,
            zHeight,
            sort
        };
        // global.scene.add(floorObj)
        this.map.scene.add(floorGroup);
        // global.positoinZs.push(zHeight)
        // store.commit('mapModule/ADD_FLOOR_LIST', {
        //   name,
        //   zIndex
        // })
        // // 创建标签
        // const parkHeight =
        //   (height[OBJECT_NAME.park] * 1000) / global.basicSetting.coordinateScale
        // // drawNameSprites(floorObj, parkHeight, zIndex);
        // reDraw()
    }
}
Object.defineProperty(ParkingLayer, "NAME", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: 'ParkingLayer'
});

export { ParkingLayer };
