Changeset 641
- Timestamp:
- 08/17/08 18:13:37 (3 months ago)
- Files:
-
- trunk/js (added)
- trunk/js/index.html (added)
- trunk/js/modestmaps.js (added)
- trunk/processing/sketches/modest_maps_interactive/modest_maps_interactive.pde (modified) (4 diffs)
- trunk/processing/src/com/modestmaps/InteractiveMap.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/processing/sketches/modest_maps_interactive/modest_maps_interactive.pde
r500 r641 18 18 19 19 // all the buttons in one place, for looping: 20 Button[] buttons = { in, out, up, down, left, right }; 20 Button[] buttons = { 21 in, out, up, down, left, right }; 21 22 22 23 PFont font; 23 24 25 boolean gui = true; 26 24 27 void setup() { 25 size( 600, 400);28 size(1280, 1024); 26 29 smooth(); 27 30 28 31 // create a new map, optionally specify a provider 29 map = new InteractiveMap(this, new Microsoft.HybridProvider()); 32 map = new InteractiveMap(this, new Microsoft.RoadProvider()); 33 // others would be "new Microsoft.HybridProvider()" or "new Microsoft.AerialProvider()" 34 // the Google ones get blocked after a few hundred tiles 35 // the Yahoo ones look terrible because they're not 256px squares :) 30 36 31 37 // set the initial location and zoom level to London: 32 map.setCenterZoom(new Location(51.500, -0.126), 11);38 // map.setCenterZoom(new Location(51.500, -0.126), 11); 33 39 // zoom 0 is the whole world, 19 is street level 34 40 // (try some out, or use getlatlon.com to search for more) … … 42 48 mouseWheel(evt.getWheelRotation()); 43 49 } 44 }); 50 } 51 ); 45 52 46 53 } … … 53 60 // (that's it! really... everything else is interactions now) 54 61 62 smooth(); 63 55 64 // draw all the buttons and check for mouse-over 56 65 boolean hand = false; 57 for (int i = 0; i < buttons.length; i++) { 58 buttons[i].draw(); 59 hand = hand || buttons[i].mouseOver(); 66 if (gui) { 67 for (int i = 0; i < buttons.length; i++) { 68 buttons[i].draw(); 69 hand = hand || buttons[i].mouseOver(); 70 } 60 71 } 61 72 … … 88 99 map.sc *= 1.0/1.05; 89 100 } 90 else if (key == 'z' || key == 'Z') { 91 map.sc = pow(2, map.getZoom()); 92 } 93 else if (key == ' ') { 94 map.sc = 2.0; 95 map.tx = -128; 96 map.ty = -128; 97 } 98 } 99 100 textFont(font, 12); 101 102 // grab the lat/lon location under the mouse point: 103 Location location = map.pointLocation(mouseX, mouseY); 101 } 102 103 if (gui) { 104 textFont(font, 12); 105 106 // grab the lat/lon location under the mouse point: 107 Location location = map.pointLocation(mouseX, mouseY); 108 109 // draw the mouse location, bottom left: 110 fill(0); 111 noStroke(); 112 rect(5, height-5-g.textSize, textWidth("mouse: " + location), g.textSize+textDescent()); 113 fill(255,255,0); 114 textAlign(LEFT, BOTTOM); 115 text("mouse: " + location, 5, height-5); 116 117 // grab the center 118 location = map.pointLocation(width/2, height/2); 119 120 // draw the center location, bottom right: 121 fill(0); 122 noStroke(); 123 float rw = textWidth("map: " + location); 124 rect(width-5-rw, height-5-g.textSize, rw, g.textSize+textDescent()); 125 fill(255,255,0); 126 textAlign(RIGHT, BOTTOM); 127 text("map: " + location, width-5, height-5); 128 129 /* 130 location = new Location(51.500, -0.126); 131 Point2f p = map.locationPoint(location); 132 133 fill(0,255,128); 134 stroke(255,255,0); 135 ellipse(p.x, p.y, 10, 10); */ 136 } 104 137 105 // draw the mouse location, bottom left: 106 fill(0); 107 noStroke(); 108 rect(5, height-5-g.textSize, textWidth("mouse: " + location), g.textSize+textDescent()); 109 fill(255,255,0); 110 textAlign(LEFT, BOTTOM); 111 text("mouse: " + location, 5, height-5); 138 println((float)map.sc); 139 println((float)map.tx + " " + (float)map.ty); 140 println(); 112 141 113 // grab the center 114 location = map.pointLocation(width/2, height/2); 115 116 // draw the center location, bottom right: 117 fill(0); 118 noStroke(); 119 float rw = textWidth("map: " + location); 120 rect(width-5-rw, height-5-g.textSize, rw, g.textSize+textDescent()); 121 fill(255,255,0); 122 textAlign(RIGHT, BOTTOM); 123 text("map: " + location, width-5, height-5); 124 } 142 } 143 144 void keyReleased() { 145 if (key == 'g' || key == 'G') { 146 gui = !gui; 147 } 148 else if (key == 's' || key == 'S') { 149 save("modest-maps-app.png"); 150 } 151 else if (key == 'z' || key == 'Z') { 152 map.sc = pow(2, map.getZoom()); 153 } 154 else if (key == ' ') { 155 map.sc = 2.0; 156 map.tx = -128; 157 map.ty = -128; 158 } 159 } 160 125 161 126 162 // see if we're over any buttons, otherwise tell the map to drag 127 163 void mouseDragged() { 128 164 boolean hand = false; 129 for (int i = 0; i < buttons.length; i++) { 130 hand = hand || buttons[i].mouseOver(); 131 if (hand) break; 165 if (gui) { 166 for (int i = 0; i < buttons.length; i++) { 167 hand = hand || buttons[i].mouseOver(); 168 if (hand) break; 169 } 132 170 } 133 171 if (!hand) { trunk/processing/src/com/modestmaps/InteractiveMap.java
r498 r641 280 280 /** sets scale according to given zoom level, should leave you with pixel perfect tiles */ 281 281 public void setZoom(int zoom) { 282 sc = p.pow(2.0f, zoom -1);282 sc = p.pow(2.0f, zoom); 283 283 } 284 284
