Skip to content

Commit db8f119

Browse files
author
richard
committed
purge tiles when they go off-screen. This basically removes the single biggest memory hog in P2
git-svn-id: http://svn.openstreetmap.org/applications/editors/potlatch2@25530 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
1 parent e03adac commit db8f119

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

net/systemeD/halcyon/TileSet.as

+16-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ package net.systemeD.halcyon {
2424
private var requests:Array=[];
2525
private var tiles:Object={}; // key is "z,x,y"; value "true" if queued, or reference to loader object if requested
2626
private var waiting:int=0; // number of tiles currently being downloaded
27+
private var loadcount:int=0; // number of tiles fully downloaded
2728
private var baseurl:String; // e.g. http://npe.openstreetmap.org/$z/$x/$y.png
2829
private var scheme:String; // 900913 or microsoft
2930
public var blocks:Array; // array of regexes which are verboten
3031

3132
private var map:Map;
32-
private const MAXTILEREQUESTS:int= 4;
33+
private const MAXTILEREQUESTS:uint= 4;
34+
private const MAXTILESLOADED:uint=30;
3335

3436
private var sharpenFilter:BitmapFilter = new ConvolutionFilter(3, 3,
3537
[0, -1, 0,
@@ -186,12 +188,25 @@ package net.systemeD.halcyon {
186188
t.addEventListener(TimerEvent.TIMER,function():void { upFade(DisplayObject(event.target.loader)); });
187189
t.start();
188190
waiting--;
191+
loadcount++;
192+
if (loadcount>MAXTILESLOADED) purgeTiles();
189193
return;
190194
}
191195

192196
protected function upFade(s:DisplayObject):void {
193197
s.alpha+=0.1;
194198
}
199+
200+
protected function purgeTiles():void {
201+
for (var tile:String in tiles) {
202+
var coords:Array=tile.split(','); var tz:uint=coords[0]; var tx:uint=coords[1]; var ty:uint=coords[1];
203+
if (tz!=map.scale || tx<tile_l || tx>tile_r || ty<tile_t || ty<tile_b) {
204+
if (tiles[tile].parent) tiles[tile].parent.removeChild(tiles[tile]);
205+
delete tiles[tile];
206+
loadcount--;
207+
}
208+
}
209+
}
195210

196211

197212
// Assemble tile URL

0 commit comments

Comments
 (0)