Changeset 641

Show
Ignore:
Timestamp:
08/17/08 18:13:37 (3 months ago)
Author:
tom
Message:

couple of processing fixes and a new super basic js port of modest maps core

Files:

Legend:

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

    r500 r641  
    1818 
    1919// all the buttons in one place, for looping: 
    20 Button[] buttons = { in, out, up, down, left, right }; 
     20Button[] buttons = {  
     21  in, out, up, down, left, right }; 
    2122 
    2223PFont font; 
    2324 
     25boolean gui = true; 
     26 
    2427void setup() { 
    25   size(600, 400); 
     28  size(1280, 1024); 
    2629  smooth(); 
    2730 
    2831  // 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 :) 
    3036 
    3137  // 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); 
    3339  // zoom 0 is the whole world, 19 is street level 
    3440  // (try some out, or use getlatlon.com to search for more) 
     
    4248      mouseWheel(evt.getWheelRotation()); 
    4349    } 
    44   });  
     50  } 
     51  );  
    4552 
    4653} 
     
    5360  // (that's it! really... everything else is interactions now) 
    5461 
     62  smooth(); 
     63 
    5564  // draw all the buttons and check for mouse-over 
    5665  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    } 
    6071  } 
    6172 
     
    8899      map.sc *= 1.0/1.05; 
    89100    } 
    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  }   
    104137   
    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(); 
    112141   
    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 
     144void 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 
    125161 
    126162// see if we're over any buttons, otherwise tell the map to drag 
    127163void mouseDragged() { 
    128164  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    } 
    132170  } 
    133171  if (!hand) { 
  • trunk/processing/src/com/modestmaps/InteractiveMap.java

    r498 r641  
    280280  /** sets scale according to given zoom level, should leave you with pixel perfect tiles */ 
    281281  public void setZoom(int zoom) { 
    282     sc = p.pow(2.0f, zoom-1);  
     282    sc = p.pow(2.0f, zoom);  
    283283  } 
    284284