阅读:2598回复:0
Opensacles::利用网格Tile实现用户feature加载
在应用项目中,我们又很多用户信息点需要被加载到图层上,这些点可以使用CustomMarker来显示。用户点分布密集程度不一致,而且量很大,一次性的全部加载进行图层是不可取的,幸好使用的是openscales的wmsc图层,底图是瓦片(tile)形式加载,所以最简单的方式就是当tile加载和释放的时候通知到用户层,用户层实现加载和释放用户信息点。<br/>看了一下openscales的代码,发现tile的申请和释放并没有通知到层对象,所以我们不能直接获取这些事件消息。<br/>wmsc类层次结构:
wmsc->wms->Grid->HttpRequest->Layer<br/>Grid类维护了瓦片集合的二维数组,当地图extent改变时,openscales将扫描Grid的瓦片数组,如果发现有空洞则调用wms的addTile()创建新的tile,如果发现可废弃tile,则调用Grid.removeExcessTiles()。<br/>addTile()之后openscales将通知layer接收TileEvent.TILE_LOAD_START事件,这个TILE_LOAD_START事件是可以利用的,作为tile加载时的通知事件,在使用的wmsc层时添加一个事件侦听便可获取tile加载事件;<br/>ImageTile从Tile派生下来,当Grid作废无效Tile时,将调用Tile.destroy()方法,所以我在TileEvent添加新事件TILE_DESTROY,在Tile.destroy()通知layer获取tile销毁的消息<br/> <div style="padding: 4px="4px" 5px="5px" 4px="4px" 4px; border: 1px="1px" solid="solid" rgb(204, 204, 204); width: 98%; font-size: 13px; word-break: break-all; background-color: rgb(238, 238, 238);"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);"> public function destroy():void {<br/></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (this.layer</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">null){<br/></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"> this.layer.dispatchEvent(new TileEvent(TileEvent.TILE_DESTROY,this));<br/></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"> }<br/></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);"> this.layer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> null;<br/></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);"> this.bounds </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> null;<br/></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);"> this.size </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> null;<br/></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);"> this.position </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> null;</span><span style="color: rgb(0, 128, 128);"></span><span style="color: rgb(0, 0, 0);"><br/></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);"> }</span></div>修改文件 TileEvent.as,Tile.as<br/>好了,事件接收只需要在Layer的实例添加如下代码: <br/> <div>addEventListener(TileEvent.TILE_LOAD_START,tileLoadHandler);</div> <div>addEventListener(TileEvent.TILE_DESTROY,tileDestroyHandler);<br/>TileEvent.tile携带了tile的boundle信息可供我们去请求feature对象了<br/></div> |
|
|