Changeset 499

Show
Ignore:
Timestamp:
02/18/08 21:11:41 (7 months ago)
Author:
tom
Message:

working Processing sketches and library-ready src folder

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/processing/sketches/modest_maps/modest_maps.pde

    r489 r499  
     1 
     2// 
     3// This is a standalone port of the Python version of Modest Maps, 
     4// based off the version from around 13th February 2008. 
     5// 
     6// It works, but I won't be fixing bugs.  It's all been ported to 
     7// .java files and will shortly be released as a library. 
     8// 
     9// 
    110 
    211void setup() { 
  • trunk/processing/sketches/modest_maps_interactive/modest_maps_interactive.pde

    r497 r499  
    11 
     2// 
     3// This is a test of the interactive Modest Maps library for Processing 
     4// the modestmaps.jar in the code folder of this sketch might not be  
     5// entirely up to date - you have been warned! 
     6// 
     7 
     8// this is the only bit that's needed to show a map: 
    29InteractiveMap map; 
    310 
     11// buttons take x,y and width,height: 
    412ZoomButton out = new ZoomButton(5,5,14,14,false); 
    513ZoomButton in = new ZoomButton(22,5,14,14,true); 
     
    917PanButton right = new PanButton(22,41,14,14,RIGHT); 
    1018 
     19// all the buttons in one place, for looping: 
    1120Button[] buttons = { in, out, up, down, left, right }; 
    1221 
    13 float startTx, endTx; 
    14 float startTy, endTy; 
    15 float startSc, endSc; 
    16  
    17 int startTime; 
    18 int duration; 
    19  
    2022void setup() { 
    21   size(screen.width/2, screen.height/2); 
     23  size(600, 400); 
    2224  smooth(); 
    2325 
     26  // create a new map, optionally specify a provider 
     27  map = new InteractiveMap(this, new Microsoft.HybridProvider()); 
     28 
     29  // set the initial location and zoom level to London: 
     30  map.setCenterZoom(new Location(51.500, -0.126), 11); 
     31  // zoom 0 is the whole world, 19 is street level 
     32  // (try some out, or use getlatlon.com to search for more) 
     33 
     34  // set a default font for labels 
     35  PFont font = createFont("Helvetica", 12); 
     36  textFont(font, 12); 
     37 
     38  // enable the mouse wheel, for zooming 
    2439  addMouseWheelListener(new java.awt.event.MouseWheelListener() {  
    2540    public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {  
     
    2843  });  
    2944 
    30   map = new InteractiveMap(this); 
    31  
    32   // London from getlatlon.com, thanks Simon! 
    33   map.setCenterZoom(new Location(51.500152, -0.126236), 11); 
    34  
    35   textFont(createFont("Helvetica", 12), 12); 
    36  
    37   startTime = millis() + 1000;  
    38   duration = 5000; 
    3945} 
    4046 
     
    4248  background(0); 
    4349 
     50  // draw the map: 
    4451  map.draw(); 
     52  // (that's it! really... everything else is interactions now) 
    4553 
     54  // draw all the buttons and check for mouse-over 
    4655  boolean hand = false; 
    4756  for (int i = 0; i < buttons.length; i++) { 
     
    5059  } 
    5160 
     61  // if we're over a button, use the finger pointer 
     62  // otherwise use the cross 
     63  // (I wish Java had the open/closed hand for "move" cursors) 
    5264  cursor(hand ? HAND : CROSS); 
    5365 
     66  // see if the arrow keys or +/- keys are pressed: 
     67  // (also check space and z, to reset or round zoom levels) 
    5468  if (keyPressed) { 
    5569    if (key == CODED) { 
     
    8397  } 
    8498 
     99  // grab the lat/lon location under the mouse point: 
    85100  Location location = map.pointLocation(mouseX, mouseY); 
    86101   
     102  // draw the mouse location, bottom left: 
    87103  fill(0); 
    88104  noStroke(); 
    89   rect(5, height-5-g.textSize, textWidth(location.toString()), g.textSize+textDescent()); 
     105  rect(5, height-5-g.textSize, textWidth("mouse: " + location), g.textSize+textDescent()); 
     106  fill(255,255,0); 
     107  textAlign(LEFT, BOTTOM); 
     108  text("mouse: " + location, 5, height-5); 
    90109   
    91   fill(255); 
    92   textAlign(LEFT, BOTTOM); 
    93   text(location.toString(), 5, height-5); 
    94  
     110  // grab the center 
     111  location = map.pointLocation(width/2, height/2); 
     112   
     113  // draw the center location, bottom right: 
     114  fill(0); 
     115  noStroke(); 
     116  float rw = textWidth("map: " + location); 
     117  rect(width-5-rw, height-5-g.textSize, rw, g.textSize+textDescent()); 
     118  fill(255,255,0); 
     119  textAlign(RIGHT, BOTTOM); 
     120  text("map: " + location, width-5, height-5); 
    95121} 
    96122 
     123// see if we're over any buttons, otherwise tell the map to drag 
    97124void mouseDragged() { 
    98125  boolean hand = false; 
     
    106133} 
    107134 
     135// zoom in or out: 
    108136void mouseWheel(int delta) { 
    109137  if (delta > 0) { 
     
    115143} 
    116144 
     145// see if we're over any buttons, and respond accordingly: 
    117146void mouseClicked() { 
    118147  if (in.mouseOver()) { 
  • trunk/processing/sketches/modest_maps_interactive_test/modest_maps_interactive_test.pde

    r491 r499  
     1 
     2// 
     3// This was a test for a matrix-math-based continuous pan/zoom set-up for 
     4// Modest Maps, which works, and has subsequently been turned into a library. 
     5// 
     6// There may be bugs in this sketch, and they won't be fixed.   
     7// 
     8// I didn't get around to doing rotations. 
     9// 
    110 
    211// pan, zoom and rotate 
     
    817  size(screen.width/2, screen.height/2, P3D); 
    918 
    10   tx = -128 + width/2
    11   ty = -128 + height/2
     19  tx = -128
     20  ty = -128
    1221   
    1322  PFont f = createFont("Helvetica",16); 
     
    5059 
    5160  // find the biggest box the screen would fit in, aligned with the map: 
    52   float screenMinX = -tx
    53   float screenMinY = -ty
    54   float screenMaxX = width-tx
    55   float screenMaxY = height-ty
     61  float screenMinX = 0
     62  float screenMinY = 0
     63  float screenMaxX = width
     64  float screenMaxY = height
    5665  println("screen: " + nf(screenMinX,1,3) + " " + nf(screenMinY,1,3) + " : " + nf(screenMaxX,1,3) + " " + nf(screenMaxY,1,3)); 
    5766  // TODO align this box! 
     
    104113    else if (key == ' ') { 
    105114      sc = 1.0; 
    106       tx = 0
    107       ty = 0;  
     115      tx = -128
     116      ty = -128;  
    108117      a = 0; 
    109118    } 
  • trunk/processing/sketches/modest_maps_lib/modest_maps_lib.pde

    r491 r499  
     1 
     2// 
     3// This is a test of the static Modest Maps library for Processing 
     4// the modestmaps.jar in the code folder of this sketch might not be  
     5// entirely up to date - you have been warned! 
     6// 
     7// The tests are useful, and seem to pass. 
     8// 
     9// The Atkinson dithering is fun too, but slow. 
     10// 
    111 
    212void setup() { 
    3   size(screen.width, screen.height); 
     13  size(screen.width/2, screen.height/2); 
    414  if (!runTests(false)) { 
    515    println("one or more tests failed"); 
     
    1121void draw() { 
    1222 
    13   MMap m = new MMap(this, new Microsoft.AerialProvider(), new Point2f(width*2, height*2), new Location(51.5, -0.137), 12); 
     23  StaticMap m = new StaticMap(this, new Microsoft.AerialProvider(), new Point2f(width/2, height/2), new Location(51.5, -0.137), 12); 
    1424   
    15 //  PImage img = m.draw(true); 
     25  PImage img = m.draw(true); 
    1626 
    1727//  img.save("data/map.png"); 
    1828 
    19   PImage img = loadImage("map.png"); 
     29//  PImage img = loadImage("map.png"); 
    2030 
    21   img = atkinsonDither(img); 
     31//  img = atkinsonDither(img); 
    2232 
    23   img.save("data/dither.png"); 
     33//  img.save("data/dither.png"); 
    2434   
    25   println("done"); 
     35//  println("done"); 
    2636 
    27 //  image(img,0,0);   
     37  image(img,0,0);   
    2838} 
  • trunk/processing/sketches/modest_maps_lib/tests.pde

    r489 r499  
    2222  boolean passed = true; 
    2323 
    24   MMap m = new MMap(this, new Google.RoadProvider(), new Point2f(600, 600), new Coordinate(3165, 1313, 13), new Point2f(-144, -94)); 
    25   Point2f p = m.locationPoint(new Location(37.804274, -122.262940)); 
     24  StaticMap m = new StaticMap(this, new Google.RoadProvider(), new Point2f(600, 600), new Coordinate(3165, 1313, 13), new Point2f(-144, -94)); 
     25  Point2f p = m.locationPoint2f(new Location(37.804274, -122.262940)); 
    2626  passed = passed && p.toString().equals("(370.688, 342.438)"); 
    2727  if (!quiet) println(passed); 
     
    161161   */ 
    162162 
    163   Coordinate c = Tiles.fromMicrosoftRoad("0"); 
     163  Coordinate c = Microsoft.fromMicrosoftRoad("0"); 
    164164  println(c.column == 0.0 && c.row == 0.0 && c.zoom == 1.0); 
    165   Coordinate d = Tiles.fromMicrosoftRoad("0230102122203031"); 
     165  Coordinate d = Microsoft.fromMicrosoftRoad("0230102122203031"); 
    166166  println(d.column == 25322.0 && d.row == 10507.0 && d.zoom == 16.0); 
    167   Coordinate e = Tiles.fromMicrosoftRoad("0230102033330212"); 
     167  Coordinate e = Microsoft.fromMicrosoftRoad("0230102033330212"); 
    168168  println(e.column == 25333.0 && e.row == 10482.0 && e.zoom == 16.0); 
    169169 
    170   println( "0".equals( Tiles.toMicrosoftRoad(0, 0, 1) ) ); 
    171   println( "0230102122203031".equals(Tiles.toMicrosoftRoad(10507, 25322, 16) ) ); 
    172   println( "0230102033330212".equals(Tiles.toMicrosoftRoad(10482, 25333, 16) ) ); 
    173  
    174   c = Tiles.fromMicrosoftAerial("0"); 
     170  println( "0".equals( Microsoft.toMicrosoftRoad(0, 0, 1) ) ); 
     171  println( "0230102122203031".equals(Microsoft.toMicrosoftRoad(10507, 25322, 16) ) ); 
     172  println( "0230102033330212".equals(Microsoft.toMicrosoftRoad(10482, 25333, 16) ) ); 
     173 
     174  c = Microsoft.fromMicrosoftAerial("0"); 
    175175  println(c.column == 0.0 && c.row == 0.0 && c.zoom == 1.0); 
    176   d = Tiles.fromMicrosoftAerial("0230102122203031"); 
     176  d = Microsoft.fromMicrosoftAerial("0230102122203031"); 
    177177  println(d.column == 25322.0 && d.row == 10507.0 && d.zoom == 16.0); 
    178   e = Tiles.fromMicrosoftAerial("0230102033330212"); 
     178  e = Microsoft.fromMicrosoftAerial("0230102033330212"); 
    179179  println(e.column == 25333.0 && e.row == 10482.0 && e.zoom == 16.0); 
    180180 
    181   println( "0".equals( Tiles.toMicrosoftAerial(0, 0, 1) ) ); 
    182   println( "0230102122203031".equals(Tiles.toMicrosoftAerial(10507, 25322, 16) ) ); 
    183   println( "0230102033330212".equals(Tiles.toMicrosoftAerial(10482, 25333, 16) ) ); 
     181  println( "0".equals( Microsoft.toMicrosoftAerial(0, 0, 1) ) ); 
     182  println( "0230102122203031".equals(Microsoft.toMicrosoftAerial(10507, 25322, 16) ) ); 
     183  println( "0230102033330212".equals(Microsoft.toMicrosoftAerial(10482, 25333, 16) ) ); 
    184184 
    185185} 
  • trunk/processing/src/com/modestmaps/providers/Yahoo.java

    r498 r499  
    6060  public static Coordinate toYahoo(Coordinate coord) { 
    6161    // Return x, y, z for Yahoo tile column, row, zoom. 
    62     return new Coordinate(coord.row, (int)PApplet.pow(2, coord.zoom - 1) - coord.row - 1, 18 - coord.zoom); 
     62    return new Coordinate((int)PApplet.pow(2, coord.zoom - 1) - coord.row - 1, coord.column, 18 - coord.zoom); 
    6363  } 
    6464