在應(yīng)用項(xiàng)目中,我們又很多用戶信息點(diǎn)需要被加載到圖層上,這些點(diǎn)可以使用CustomMarker來顯示。用戶點(diǎn)分布密集程度不一致,而且量很大,一次性的全部加載進(jìn)行圖層是不可取的,幸好使用的是openscales的wmsc圖層,底圖是瓦片(tile)形式加載,所以最簡單的方式就是當(dāng)tile加載和釋放的時(shí)候通知到用戶層,用戶層實(shí)現(xiàn)加載和釋放用戶信息點(diǎn)。
看了一下openscales的代碼,發(fā)現(xiàn)tile的申請(qǐng)和釋放并沒有通知到層對(duì)象,所以我們不能直接獲取這些事件消息。
wmsc類層次結(jié)構(gòu): wmsc->wms->Grid->HttpRequest->Layer
Grid類維護(hù)了瓦片集合的二維數(shù)組,當(dāng)?shù)貓Dextent改變時(shí),openscales將掃描Grid的瓦片數(shù)組,如果發(fā)現(xiàn)有空洞則調(diào)用wms的addTile()創(chuàng)建新的tile,如果發(fā)現(xiàn)可廢棄tile,則調(diào)用Grid.removeExcessTiles()。
addTile()之后openscales將通知layer接收TileEvent.TILE_LOAD_START事件,這個(gè)TILE_LOAD_START事件是可以利用的,作為tile加載時(shí)的通知事件,在使用的wmsc層時(shí)添加一個(gè)事件偵聽便可獲取tile加載事件;
ImageTile從Tile派生下來,當(dāng)Grid作廢無效Tile時(shí),將調(diào)用Tile.destroy()方法,所以我在TileEvent添加新事件TILE_DESTROY,在Tile.destroy()通知layer獲取tile銷毀的消息
1 public function destroy():void {
2 if (this.layer!=null){
3 this.layer.dispatchEvent(new TileEvent(TileEvent.TILE_DESTROY,this));
4 }
5 this.layer = null;
6 this.bounds = null;
7 this.size = null;
8 this.position = null;
10 }
修改文件 TileEvent.as,Tile.as
好了,事件接收只需要在Layer的實(shí)例添加如下代碼:
addEventListener(TileEvent.TILE_LOAD_START,tileLoadHandler);
addEventListener(TileEvent.TILE_DESTROY,tileDestroyHandler);
TileEvent.tile攜帶了tile的boundle信息可供我們?nèi)フ?qǐng)求feature對(duì)象了