We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › hox to zoom in/out and move on a map
Page Index Toggle Pages: 1
hox to zoom in/out and move on a map (Read 2977 times)
hox to zoom in/out and move on a map
May 2nd, 2008, 4:33pm
 
Hi,
I´m quiet new to processing. I want to find solution for this problem:

I got a citiy map (54cmx82cm)as jpeg (300dpi, 11mb).

Now I want to realize two functions:
a) to move the map to see a special segmaent of the map on the screen and
b) I want to zoom in and out on the map because I´ve to draw lines in the map.

does anbody on the list already solved such a problem?

thanks!!

frank
Re: hox to zoom in/out and move on a map
Reply #1 - May 3rd, 2008, 8:07pm
 
You can check out Ben Fry's examples on zip code in his book: Visualizing Data.  Otherwise, image, translate, and scale may take care of it.
Re: how to zoom in/out and move on a map
Reply #2 - May 13th, 2008, 9:04am
 
Hi,
thanks to sw01.-
I did find 2 ways to move the map and to zomm in/out.-


Version 1 - Here´s my code:

PImage a;  // Declare variable "a" of type PImage
int updown = 0;
int leftright = 0;
int zoom = 1;

void setup(){
size(600,600);
smooth();
frameRate(10);
a = loadImage("kartec.jpg");
noStroke();
}

void draw () {
scale(zoom);
translate (leftright,updown);
image(a,0,0);
}


// Tastkommandos erkennen
 void keyPressed() {
     if (key == CODED) {
       if (keyCode == UP) {
       updown = updown-30;
   } else
       if (keyCode == DOWN) {
       updown = updown+30;
   } else
       if (keyCode == LEFT) {
       leftright = leftright-30;
  }  else
       if (keyCode == RIGHT) {
       leftright = leftright+30;
     }  
  }
   if(key == '+') {
   zoom = 2;
   println(zoom);
 } else if (key == '-') {
   zoom = 1;
   println(zoom);
 }
}

Version 2 - Matt Patey:

Well this one is OK - but the quiet big map-image is diplayed bad, if I push the buttons to move the image quickly.-

Now I found this solution from Matt Patey. It works fine, but the movement of the image is very slow.- Is there a possibility to change this? Or is this a problem of the hardware memory speed?

Thanks for any help!


/**
* PanDemo.pde
 * @author Matt Patey
*/
PImage imgBorealis;
PImage bufSlice;
PGraphics buf;
int copyOffsetX;
int copyOffsetY;
int copyWidth;
int copyHeight;
int zoom = 1;
void setup() {
 size(600, 600, P3D);
 // Load our image.
 imgBorealis = loadImage("kartec.jpg");
 
 // Create an off-screen buffer that will contain the entire image.
 buf = createGraphics(imgBorealis.width, imgBorealis.height, P3D);
 buf.beginDraw();
 buf.image(imgBorealis, 0, 0);
 buf.endDraw();
 copyOffsetX = 0;
 copyOffsetY = 0;
 copyWidth = width;
 copyHeight = height;
}

void draw() {
 background(0);
 scale(zoom);
 image(getBufSlice(), 0, 0);
}
/**
* Updates the copied version of the off-screen buffer.
*/
PImage getBufSlice() {
 return buf.get(copyOffsetX, copyOffsetY, copyWidth, copyHeight);
}

/**
* Handle key presses.
*/
void keyPressed() {
 switch(keyCode) {
   case LEFT:
     if(copyOffsetX < buf.width - width) {
       copyOffsetX++;
     }
   break;
   
   case RIGHT:
     if(copyOffsetX > 0) {
       copyOffsetX--;
     }
   break;
   
   case UP:
     if(copyOffsetY < buf.height - height) {
       copyOffsetY++;
     }
   break;
   
   case DOWN:
     if(copyOffsetY > 0) {
       copyOffsetY--;
     }
   break;    
 }
}
Re: hox to zoom in/out and move on a map
Reply #3 - May 15th, 2008, 5:21am
 
To solve the speed issue, you can:
1) increase the movement "steps":
e.g.,    updown = updown-30;  would be updown = updown-60;
would make the increment (decrement in this case) twice as fast.
I also notice in the second one, the offset++ is incrementing the value by 1.  you can do offset += 30  or something like that and keep adjusting it.

2) increase the framerate.  I see the the first one is set to 10 fps.  That's way too slow for interactive programs.  try deleting the line.

3) use lower resolution map to speed up the draw process, or break it up to pieces so you only need to draw a certain segment.

I also recommend using mouse drag to manipulate maps, which relegates the speed adjustment to the user.  Responsiveness tends to be more of a user interface issue rather than performance issue, so keep playing around 'till you get what you like.
Re: hox to zoom in/out and move on a map
Reply #4 - May 15th, 2008, 3:38pm
 
Hi,
thanks once again.-

1)speed
uhh, this I´ve had to find by my own.
Changing with updown-30 works grat

2)framerate
I did also delete the framerate with 10fps

3) break the map in pieces
This seems to be my next problem: breaking the map in pieces. Finally the goal is to get something like the "modest maps" project. But I don´t want to use open street maps or Google & Yahoo maps. Tom Carden did actually port this to processing:

http://www.tom-carden.co.uk/2008/02/18/modest-maps-vs-processing/

I just have a big file with 4000px*4500px as jpeg. The navigation works fine now in a window with 600px*600px.
The only thing, what´s missing bow is, how to find the absolute coorinate by selecting coordinates in the small window. hm.

thanks once again!





Re: hox to zoom in/out and move on a map
Reply #5 - Oct 20th, 2009, 3:06pm
 
What you need to do is split your large image into smaller tiles, or save it as JPEG2000 and write some fancy code to load certain bits at certain resolutions. This process is automated by 'Deep Zoom Composer', and is the approach taken by 'Seadragon'.
The problem you're tackling seems to have acquired the name 'deep zoom' - searching will bring up lots of information about this topic but little related to Processing. I'm going to be working on the topic in the next couple weeks so PM if interested.
Seadragon revived interest in 'deep zoom' a few years ago with some nice tech demos (youtube.com/watch?v=0ra5tp7K--I and youtube.com/watch?v=PKwTurQgiak - the second one is pretty interesting). They were bought by Microsoft who incorporated their tech into Silverlight, a Flash competitor. Silverlight includes libraries/components within the browser plugin to do this stuff, which makes the app load very fast, as it doesn't have to load any zoom/pan code. They also produced 'Deep Zoom Composer'; a tool for creating these applets. Download from: microsoft.com/DOWNLOADS/details.aspx?familyid=457B17B7-52BF-4BDA-87A3-FA8A4673F8
BF&displaylang=en
The Deep Zoom Composer can also output 'image pyramids'. You load the big image and specify how many layers of decreasing resolution you want, and the tile size for each level. This keeps the app responsive because you only load into memory the stuff which is needed there and then.
Page Index Toggle Pages: 1