Changeset 496
- Timestamp:
- 02/18/08 15:52:55 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/processing/sketches/modest_maps_interactive/InteractiveMap.java
r495 r496 63 63 } 64 64 65 /** draw the map on the given PApplet */ 65 66 void draw() { 66 67 … … 83 84 float maxX = p.screenX(TILE_WIDTH, TILE_HEIGHT); 84 85 float maxY = p.screenY(TILE_WIDTH, TILE_HEIGHT); 85 p.println(minX + " " + minY);86 p.println(maxX + " " + maxY);87 86 88 87 // what power of 2 are we at? … … 95 94 int cols = (int)p.pow(2,zoom); 96 95 int rows = (int)p.pow(2,zoom); 97 98 // p.println(cols + " " + rows);99 96 100 97 // find the biggest box the screen would fit in:, aligned with the map: … … 163 160 if (!gotParent) { 164 161 Coordinate zoomed = coord.zoomBy(1).container(); 165 Coordinate[] kids = new Coordinate[] { 166 zoomed, zoomed.right(), zoomed.down(), zoomed.right().down() }; 162 Coordinate[] kids = { zoomed, zoomed.right(), zoomed.down(), zoomed.right().down() }; 167 163 for (int i = 0; i < kids.length; i++) { 168 164 zoomed = kids[i]; … … 202 198 if (images.containsKey(coord)) { 203 199 PImage tile = (PImage)images.get(coord); 204 p.image(tile,coord.column*256,coord.row*256,256,256); 205 // if (p.frameCount % 100 == 0) { 206 // p.println(p.screenX(coord.column*256,coord.row*256) + ", " + p.screenY(coord.column*256,coord.row*256)); 207 // } 200 p.image(tile,coord.column*TILE_WIDTH,coord.row*TILE_HEIGHT,TILE_WIDTH,TILE_HEIGHT); 208 201 if (recentImages.contains(tile)) { 209 202 recentImages.remove(tile); … … 217 210 p.popMatrix(); 218 211 219 // println(pending.size() + " pending..."); 220 // println(queue.size() + " in queue, pruning..."); 221 queue.retainAll(visibleKeys); // stop fetching things we can't see 222 // println(queue.size() + " in queue"); 223 // println(); 212 // stop fetching things we can't see: 213 // (visibleKeys also has the parents and children, if needed, but that shouldn't matter) 214 queue.retainAll(visibleKeys); 224 215 225 216 // sort what's left by distance from center: 226 217 queueSorter.setCenter(new Coordinate( (minRow + maxRow) / 2.0f, (minCol + maxCol) / 2.0f, zoom)); 227 // println("center: " + center);228 218 Collections.sort(queue, queueSorter); 229 219 … … 231 221 processQueue(); 232 222 223 // clear some images away if we have too many... 233 224 if (recentImages.size() > MAX_IMAGES_TO_KEEP) { 234 //println(recentImages.size() + " images in memory, removing...");235 225 recentImages.subList(0, recentImages.size()-MAX_IMAGES_TO_KEEP).clear(); 236 //println(recentImages.size() + " images in memory");237 226 images.values().retainAll(recentImages); 238 227 } 239 228 240 if (smooth) p.smooth(); 229 // restore smoothing, if needed 230 if (smooth) { 231 p.smooth(); 232 } 241 233 242 234 } … … 252 244 253 245 Coordinate getCenterCoordinate() { 254 float row = (float)(ty*sc/- 256.0);255 float column = (float)(tx*sc/- 256.0);246 float row = (float)(ty*sc/-TILE_WIDTH); 247 float column = (float)(tx*sc/-TILE_HEIGHT); 256 248 float zoom = zoomForScale((float)sc); 257 249 return new Coordinate(row, column, zoom); … … 261 253 //println("setting center to " + center); 262 254 sc = p.pow(2.0f, center.zoom); 263 tx = - 256.0*center.column/sc;264 ty = - 256.0*center.row/sc;255 tx = -TILE_WIDTH*center.column/sc; 256 ty = -TILE_HEIGHT*center.row/sc; 265 257 } 266 258 … … 312 304 } 313 305 314 // TODO: move constructor args to match:315 //float width, float height, boolean draggable, AbstractMapProvider provider, Location[] extent316 317 306 Point2f locationPoint(Location location) { 318 307 PMatrix m = new PMatrix(); … … 324 313 float[] out = new float[3]; 325 314 m.mult3(new float[] { 326 coord.column* 256.0f, coord.row*256.0f, 0 }315 coord.column*TILE_WIDTH, coord.row*TILE_HEIGHT, 0 } 327 316 , out); 328 317 … … 331 320 332 321 Location pointLocation(Point2f point) { 322 return pointLocation(point.x, point.y); 323 } 324 325 Location pointLocation(float x, float y) { 333 326 334 327 // TODO: create this matrix once and keep it around for drawing and projecting … … 345 338 float br[] = new float[3]; 346 339 m.mult3(new float[] { 347 256,256,0 }340 TILE_WIDTH, TILE_HEIGHT, 0 } 348 341 , br); 349 342 350 float col = ( point.x - tl[0]) / (br[0] - tl[0]);351 float row = ( point.y - tl[1]) / (br[1] - tl[1]);343 float col = (x - tl[0]) / (br[0] - tl[0]); 344 float row = (y - tl[1]) / (br[1] - tl[1]); 352 345 Coordinate coord = new Coordinate(row, col, 0); 353 346 … … 446 439 } 447 440 public void run() { 448 p.println("loading " + coord);449 441 String[] urls = provider.getTileUrls(coord); 450 // p.println("loading " + urls[0]); 451 PImage img = p.loadImage(urls[0], "unknown"); 442 PImage img = p.loadImage(urls[0], "unknown"); // use unknown to let loadImage decide 452 443 if (img != null) { 453 444 for (int i = 1; i < urls.length; i++) { 454 // p.println("loading " + urls[i]);455 445 PImage img2 = p.loadImage(urls[i], "unknown"); 456 446 if (img2 != null) { trunk/processing/sketches/modest_maps_interactive/modest_maps_interactive.pde
r495 r496 7 7 8 8 void setup() { 9 size(screen.width , screen.height);9 size(screen.width/2, screen.height/2); 10 10 smooth(); 11 11 … … 24 24 out = new ZoomButton(5,5,14,14,false); 25 25 in = new ZoomButton(22,5,14,14,true); 26 27 26 up = new PanButton(14,25,14,14,UP); 28 27 down = new PanButton(14,57,14,14,DOWN); … … 32 31 buttons = new Button[] { 33 32 in, out, up, down, left, right }; 33 34 textFont(createFont("Helvetica", 12), 12); 34 35 35 36 } … … 79 80 } 80 81 81 // println(map.getCenter()); 82 // println(map.pointLocation(new Point2f(width/2, height/2))); 82 Location location = map.pointLocation(mouseX, mouseY); 83 84 fill(0); 85 noStroke(); 86 rect(5, height-5-g.textSize, textWidth(location.toString()), g.textSize+textDescent()); 87 88 fill(255); 89 textAlign(LEFT, BOTTOM); 90 text(location.toString(), 5, height-5); 83 91 84 92 }
