Changeset 493
- Timestamp:
- 02/16/08 19:22:58 (9 months ago)
- Files:
-
- trunk/processing/sketches/modest_maps_interactive/code/modestmaps.jar (modified) (previous)
- trunk/processing/sketches/modest_maps_interactive/modest_maps_interactive.pde (modified) (6 diffs)
- trunk/processing/sketches/modest_maps_interactive_test/code/modestmaps.jar (modified) (previous)
- trunk/processing/sketches/modest_maps_lib/code/modestmaps.jar (modified) (previous)
- trunk/processing/src/com/modestmaps/AbstractMapProvider.java (modified) (1 diff)
- trunk/processing/src/com/modestmaps/Coordinate.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/processing/sketches/modest_maps_interactive/modest_maps_interactive.pde
r492 r493 43 43 44 44 // 0 when sideLength == 256, 1 when sideLength == 512, 2 when sideLength == 1024 45 int zoom = min(20, max( 0, (int)round(log(sideLength/zoom0Length) / log(2))));45 int zoom = min(20, max(1, (int)round(log(sideLength/zoom0Length) / log(2)))); 46 46 47 47 int cols = (int)pow(2,zoom); … … 54 54 55 55 // find the biggest box the screen would fit in, aligned with the map: 56 float screenMinX = -tx;57 float screenMinY = -ty;58 float screenMaxX = width -tx;59 float screenMaxY = height -ty;56 float screenMinX = 0; 57 float screenMinY = 0; 58 float screenMaxX = width; 59 float screenMaxY = height; 60 60 // println("screen: " + nf(screenMinX,1,3) + " " + nf(screenMinY,1,3) + " : " + nf(screenMaxX,1,3) + " " + nf(screenMaxY,1,3)); 61 61 // TODO align this box! … … 68 68 // println("row/col: " + minCol + ", " + minRow + " : " + maxCol + ", " + maxRow); 69 69 70 minCol -= 1; 71 minRow -= 1; 72 maxCol += 1; 73 maxRow += 1; 74 75 Vector visibleKeys = new Vector(); 76 70 77 pushMatrix(); 71 78 scale(1.0/pow(2,zoom)); 72 79 for (int col = minCol; col <= maxCol; col++) { 73 80 for (int row = minRow; row <= maxRow; row++) { 74 Coordinate coord = new Coordinate(row,col,zoom); 75 String coordKey = coord.toString(); 76 if (images.containsKey(coordKey)) { 77 PImage tile = (PImage)images.get(coord.toString()); 81 Coordinate coord = provider.sourceCoordinate(new Coordinate(row,col,zoom)); 82 coord.row = round(coord.row); 83 coord.column = round(coord.column); 84 coord.zoom = round(coord.zoom); 85 visibleKeys.add(coord); 86 if (images.containsKey(coord)) { 87 PImage tile = (PImage)images.get(coord); 78 88 image(tile,col*256,row*256,256,256); 79 89 } 80 90 else { 81 if (!pending.containsKey(coordKey)) { 82 grabTile(coord); 83 } 91 grabTile(coord); 84 92 fill(col >= 0 && col < cols && row >= 0 && row < rows ? 128 : 80); 85 93 stroke(255); 86 94 rect(col*256,row*256,256,256); 95 fill(255); 96 noStroke(); 97 textAlign(LEFT, TOP); 98 text("c:"+col+" "+"r:"+row+" "+"z:"+zoom, col*256, row*256); 99 /* textAlign(RIGHT, TOP); 100 text("c:"+col+" "+"r:"+row, (1+col)*256, row*256); 101 textAlign(LEFT, BOTTOM); 102 text("c:"+col+" "+"r:"+row, col*256, (1+row)*256); 103 textAlign(RIGHT, BOTTOM); 104 text("c:"+col+" "+"r:"+row, (1+col)*256, (1+row)*256); */ 87 105 } 88 fill(255);89 noStroke();90 textAlign(LEFT, TOP);91 text("c:"+col+" "+"r:"+row+" "+"z:"+zoom, col*256, row*256);92 /* textAlign(RIGHT, TOP);93 text("c:"+col+" "+"r:"+row, (1+col)*256, row*256);94 textAlign(LEFT, BOTTOM);95 text("c:"+col+" "+"r:"+row, col*256, (1+row)*256);96 textAlign(RIGHT, BOTTOM);97 text("c:"+col+" "+"r:"+row, (1+col)*256, (1+row)*256); */98 106 } 99 107 } … … 101 109 102 110 popMatrix(); 111 112 // println(pending.size() + " pending..."); 113 // println(queue.size() + " in queue, pruning..."); 114 queue.retainAll(visibleKeys); 115 // println(queue.size() + " in queue"); 116 // println(); 117 118 processQueue(); 103 119 104 120 if (keyPressed) { … … 139 155 } 140 156 141 Hashtable pending = new Hashtable(); 142 Hashtable images = new Hashtable(); 157 // loading tiles 158 Hashtable pending = new Hashtable(); // coord.toString() -> TileLoader 159 // loaded tiles 160 Hashtable images = new Hashtable(); // coord.toString() -> PImage 161 // coords waiting to load 162 Vector queue = new Vector(); // coord 143 163 144 164 void grabTile(Coordinate coord) { 145 Thread thread = new Thread(new TileLoader(coord)); 146 pending.put(coord.toString(), thread); 147 thread.start(); // TODO throttle this 165 if (!pending.containsKey(coord) && !queue.contains(coord) && !images.containsKey(coord)) { 166 // println("adding " + coord.toString() + " to queue"); 167 queue.add(coord); 168 } 148 169 } 149 170 … … 157 178 println("loading: " + url); 158 179 PImage img = loadImage(url); // TODO: layered tiles 159 println("loaded: " + url); 160 images.put(coord.toString(), img); 161 pending.remove(coord.toString()); 180 // println("loaded: " + url); 181 tileDone(coord, img); 162 182 } 163 183 } 184 185 void tileDone(Coordinate coord, PImage img) { 186 images.put(coord, img); 187 pending.remove(coord); 188 } 189 190 void processQueue() { 191 while (pending.size() < 4 && queue.size() > 0) { 192 Coordinate coord = (Coordinate)queue.remove(0); 193 TileLoader tileLoader = new TileLoader(coord); 194 pending.put(coord, tileLoader); 195 new Thread(tileLoader).start(); 196 } 197 } trunk/processing/src/com/modestmaps/AbstractMapProvider.java
r485 r493 34 34 35 35 public Coordinate sourceCoordinate(Coordinate coordinate) { 36 float wrappedColumn = coordinate.column %PApplet.pow(2, coordinate.zoom);36 float gridSize = PApplet.pow(2, coordinate.zoom); 37 37 38 float wrappedColumn = coordinate.column % gridSize; 38 39 while (wrappedColumn < 0) { 39 wrappedColumn += PApplet.pow(2, coordinate.zoom);40 wrappedColumn += gridSize; 40 41 } 41 42 42 return new Coordinate(coordinate.row, wrappedColumn, coordinate.zoom); 43 float wrappedRow = coordinate.row % gridSize; 44 while (wrappedRow < 0) { 45 wrappedRow += gridSize; 46 } 47 48 return new Coordinate(wrappedRow, wrappedColumn, coordinate.zoom); 43 49 } 44 50 trunk/processing/src/com/modestmaps/Coordinate.java
r485 r493 17 17 public String toString() { 18 18 return "(" + PApplet.nf(row,1,3) + ", " + PApplet.nf(column,1,3) + " @" + PApplet.nf(zoom,1,3) + ")"; 19 } 20 21 public boolean equals(Object o) { 22 Coordinate c = (Coordinate)o; 23 //return PApplet.abs(c.row - row) < PApplet.EPSILON && PApplet.abs(c.column - column) < PApplet.EPSILON && PApplet.abs(c.zoom - zoom) < PApplet.EPSILON; 24 return c.row == row && c.column == column && c.zoom == zoom; 25 } 26 27 public int hashCode() { 28 return toString().hashCode(); 19 29 } 20 30
