Babylon.js 構(gòu)建 地球,支持切片地圖 (六)

針對(duì)切片管理


針對(duì)EarthControl類(lèi) 主要是管理主類(lèi) 負(fù)責(zé)事件監(jiān)聽(tīng)后重新刷新切片

```javascript

const BABYLON = require('babylonjs');

import {EarthTool} from './EarthTool';

import {BuildTileTool} from './BuildTileTool';

export class EarthControl {

constructor(scene) {

this.scene = scene,

this.rangeAera = 6,

this.maxTilesCount = 512,

this.tilesCount = 0,

this.tilesRemoveCount = 0,

this.level = 0,

this.tiles = [],

this.checkForTile = true,

this.stoprendering = false,

this.nVisible = 0,

this.nHidden = 0,

EarthTool.SetLevel(),

this.addObserver(),

this.camera = this.scene.getCameraByName("EarthCamera"),

this.drawMinimalEarth(),

this._tick = ()=>this.tick(),

this.scene.registerBeforeRender(this._tick),

this.keyHelper()

}

drawMinimalEarth() {

this.pixelXY = EarthTool.LatLongToPixelXY(90, -180, 3),

this.tileXY = EarthTool.PixelXYToTileXY(this.pixelXY.x, this.pixelXY.y),

this.tileInfo = EarthTool.ComputeVisibleTiles(this.tileXY.x, this.tileXY.y, 3, 8, false);

for (let t = 0; t < this.tileInfo.length; t++) { if (void 0 !== EarthControl.TilesbyQuadKey[this.tileInfo[t].quadKey]) continue; this._tileTexturCB = ()=>this.updateGeoInfo();

const i = new BuildTileTool(this.scene,this.tileInfo[t].quadKey,360 / this.tileInfo[t].nFaces,this.tileInfo[t].offsetX,this.tileInfo[t].offsetY,16,this.tileInfo[t].level,this.tileInfo[t].k,this.tileInfo[t].j,this._tileTexturCB);

console.log(360 / this.tileInfo[t].nFaces),

this.tiles.push(i),

EarthControl.TilesbyQuadKey[this.tileInfo[t].quadKey] = i,

this.tilesCount++

}

}

tick() {

this.camera.isDirty ? (this.level = this.getBestLevelResolution(),

this.checkForTile = true) : true === this.checkForTile && (this.level = this.getBestLevelResolution(),

this.getGeoInfo(this.level),

this.checkForTile = false)

}

getBestLevelResolution() {

const e = EarthTool.MapNumberToInterval(this.camera.radius, 50, 150, 0, 50);

return EarthTool.GetBestLevelResolution(e, this.scene.getEngine().getRenderHeight())

}

pointerup(e) {

const t = e.pickInfo.pickedPoint;

t && "earth" === e.pickInfo.pickedMesh.name && EarthTool.Vec3ToLatLong(t, false)

}

getGeoInfo(t) {

const i = EarthTool.CameraToLatlong(this.camera.beta, this.camera.alpha);

this.pixelXY = EarthTool.LatLongToPixelXY(i.x, i.y, t),

this.tileXY = EarthTool.PixelXYToTileXY(this.pixelXY.x, this.pixelXY.y),

this.tileInfo = EarthTool.ComputeVisibleTiles(this.tileXY.x, this.tileXY.y, t, this.rangeAera, true);

for (let n = 0; n < this.tileInfo.length; n++) { if (void 0 !== EarthControl.TilesbyQuadKey[this.tileInfo[n].quadKey]) continue; const t = new BuildTileTool(this.scene,this.tileInfo[n].quadKey,360 / this.tileInfo[n].nFaces,this.tileInfo[n].offsetX,this.tileInfo[n].offsetY,8,this.tileInfo[n].level,this.tileInfo[n].k,this.tileInfo[n].j,this._tileTexturCB); this.tiles.push(t), EarthControl.TilesbyQuadKey[this.tileInfo[n].quadKey] = t, this.tilesCount++ } this.topleftLatLon = void 0, this.showHide(this.level), this.removeTile() } updateGeoInfo() { this.time = Date.now(), this.checkInterval || (this.checkInterval = setInterval(()=>{

Date.now() - this.time >= 150 && (this.level = this.getBestLevelResolution(),

this.getGeoInfo(this.level),

clearInterval(this.checkInterval),

this.checkInterval = null)

}

, 150))

?更多參考?https://xiaozhuanlan.com/topic/2753480169

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末澈吨,一起剝皮案震驚了整個(gè)濱河市把敢,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌谅辣,老刑警劉巖修赞,帶你破解...
    沈念sama閱讀 217,826評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異桑阶,居然都是意外死亡柏副,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)蚣录,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)割择,“玉大人,你說(shuō)我怎么就攤上這事萎河±笥荆” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,234評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵虐杯,是天一觀的道長(zhǎng)玛歌。 經(jīng)常有香客問(wèn)我,道長(zhǎng)厦幅,這世上最難降的妖魔是什么沾鳄? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,562評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮确憨,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘瓤的。我一直安慰自己休弃,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,611評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布圈膏。 她就那樣靜靜地躺著塔猾,像睡著了一般。 火紅的嫁衣襯著肌膚如雪稽坤。 梳的紋絲不亂的頭發(fā)上丈甸,一...
    開(kāi)封第一講書(shū)人閱讀 51,482評(píng)論 1 302
  • 那天糯俗,我揣著相機(jī)與錄音,去河邊找鬼睦擂。 笑死得湘,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的顿仇。 我是一名探鬼主播淘正,決...
    沈念sama閱讀 40,271評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼臼闻!你這毒婦竟也來(lái)了鸿吆?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,166評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤述呐,失蹤者是張志新(化名)和其女友劉穎惩淳,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體乓搬,經(jīng)...
    沈念sama閱讀 45,608評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡黎泣,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,814評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了缤谎。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片抒倚。...
    茶點(diǎn)故事閱讀 39,926評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖坷澡,靈堂內(nèi)的尸體忽然破棺而出托呕,到底是詐尸還是另有隱情,我是刑警寧澤频敛,帶...
    沈念sama閱讀 35,644評(píng)論 5 346
  • 正文 年R本政府宣布项郊,位于F島的核電站,受9級(jí)特大地震影響斟赚,放射性物質(zhì)發(fā)生泄漏着降。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,249評(píng)論 3 329
  • 文/蒙蒙 一拗军、第九天 我趴在偏房一處隱蔽的房頂上張望任洞。 院中可真熱鬧,春花似錦发侵、人聲如沸交掏。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,866評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)盅弛。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間挪鹏,已是汗流浹背见秽。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,991評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留讨盒,地道東北人解取。 一個(gè)月前我還...
    沈念sama閱讀 48,063評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像催植,于是被迫代替她去往敵國(guó)和親肮蛹。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,871評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容