针对切片管理
BuildTileTool类
const BABYLON = require('babylonjs');
import {TileTexture} from './TileTexture';
import {EarthTool} from './EarthTool';
import {EarthControl} from './EarthControl';
export class BuildTileTool {
constructor(scene, quadKey, size, offsetX, offsetY, subd, level, a, c, l) {
if (this.scene = scene,
this.quadKey = quadKey,
this.size = size,
this.offsetX = offsetX,
this.offsetY = offsetY,
this.subd = subd,
this.level = level,
this.k = a,
this.j = c,
this.cb = l,
this.tileMapLoaded = false,
this.isReady = false,
this.lock = false,
this.useShader = true,
3 === this.level && (this.lock = true),
this.builTile(),
this.useShader) {
const i = new TileTexture(scene,()=>this.tileTexturCB(),level,a,c,quadKey);
this.tile.material = i.shaderMaterial
}
}
tileTexturCB() {
this.tileMapLoaded = true,
this.cb()
}
builTile() {
this.tile = BABYLON.MeshBuilder.CreateGround("tile", {
height: this.size,
width: this.size,
subdivisions: this.subd,
updatable: true
}, this.scene),
this.tile.renderingGroupId = this.level - 3;
let e = this.tile.getVerticesData(BABYLON.VertexBuffer.PositionKind);
const t = e.length / 3;
for (let i = 0; i < t; i++)
if (this.useShader) {
let t = e[3 * i] + this.offsetX;
const n = e[3 * i + 1];
let r = e[3 * i + 2] + this.offsetY;
t = EarthTool.MapNumberToInterval(t, -180, 180, -EarthTool.EPSG3857_MAX_BOUND, EarthTool.EPSG3857_MAX_BOUND),
r = EarthTool.MapNumberToInterval(r, -180, 180, -EarthTool.EPSG3857_MAX_BOUND, EarthTool.EPSG3857_MAX_BOUND);
const o = EarthTool.InverseWebMercator(t, r, n);
e[3 * i] = o.x,
e[3 * i + 1] = o.y,
e[3 * i + 2] = o.z
更多参考 https://xiaozhuanlan.com/topic/9075264183