Creating an image map
Hi guys,
I have a list of images, that I want to draw as a map, and I want to drag it an zoom it like you'll do in google map.
I have tried with a NSImage for each square, but I see lines between them when zooming, and mouseDragged event isn't called when I drag over an NSImage.
Does anyone has an idea on how to do this ?
Thanx for all !
I suggest you use a user defined control. You'll be called to draw the display and you should paint your images at that time. And of course you can register for notifications from the mouse.
There's an example (about p250) in Aaron Hillegas' book where he draws some lines. I think he's rubber banding an image (or something like that). I think it's called ImageFun and I believe that's very close to what you want. The code's available from http://www.bignerdranch.com/solutions/Cocoa-3rd.tgz and it's 18_Mouse/Events - see StretchView.m drawRect (line 54).
You can set up a matrix to define the scaling (and pan and rotation) between device and real coords. When you pan and zoom you only have to modify that matrix and repaint.
If you want to drag'n'drop images into your window, that's possible as well of course. However in the first place, try getting the image(s) to paint from the nib using Aaron's code and figure out the zoom and pan. That's the hard bit, drag'n'droping images from the Finder is a little trick you can add when you've mastered the mouse and zoom and pan.
I hope that helps. If you're still stuck, please let me know and I'll cook up something on Friday evening for you and post it on my web site for you to collect.