UNPKG

@orca-fe/x-map

Version:
62 lines (61 loc) 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const THREE = tslib_1.__importStar(require("three")); const ThreeObject_1 = tslib_1.__importDefault(require("./ThreeObject")); const coord_1 = require("../../utils/coord"); class BuildingObject extends ThreeObject_1.default { constructor(options) { super(options); this.object3D = new THREE.Group(); this.createObject = () => { const { fill, buildings, layer, z = 0 } = this; if (layer === null || layer === void 0 ? void 0 : layer.map) { const { threeCenter } = layer.map; this.object3D.clear(); this.object3D.renderOrder = Math.round(z); const color = new THREE.Color(fill.color); const polygonMaterial = new THREE.MeshLambertMaterial({ color, opacity: fill.opacity, depthWrite: false, depthTest: false, transparent: true, }); // let geometry = new THREE.BufferGeometry(); const shapes = {}; for (let i = 0; i < buildings.length; i++) { const shape = new THREE.Shape(); const path = buildings[i].path .map(coord_1.lonLat2Mercator) .map(([x, y]) => [x - threeCenter[0], y - threeCenter[1]]); path.forEach(([x, y], j) => { if (j === 0) { shape.moveTo(x, y); } shape.lineTo(x, y); }); const { height } = buildings[i]; if (!shapes[height]) shapes[height] = []; shapes[height].push(shape); } Object.entries(shapes).forEach(([height, shapes]) => { const polygonGeometry = new THREE.ExtrudeGeometry(shapes, { steps: 1, bevelEnabled: false, depth: Math.max(Number(height) * 6, 0.001), }); const polygonMesh = new THREE.Mesh(polygonGeometry, polygonMaterial); this.object3D.add(polygonMesh); }); } }; const { fill, buildings } = options; this.buildings = buildings; this.fill = fill; this.object3D.position.set(0, 0, this.z); } updatePosition() { } } exports.default = BuildingObject;