views:

87

answers:

3

I want to write a navigator application, which draws maps from images. Maps need to be drawn dynamically, based on user's navigation. My idea is loading 9 images into memory, and then create a view to show needed map:

alt text

When user navigates, the view is moved. When needed, images which no longer seen will be destroyed, and new ones will be loaded.

My first problem is that I can't get it worked. :(. My second problem is that it seems to be too complex and resource-wasting. It's also hard to scale in case screen size is changed.

Can you please so me an effective algorithm to draw maps? A demo code in C# will help a lot. An open source library will be much appreciated. :)

Thank you.

+2  A: 

depending on what you want to do this could be a pretty hard problem. e.g. georeferencing, projection, GCS, you don't want to roll your own

there are a number of gis tools available that already do this sort of thing, for c# and open source there is SharpMap or possibly google maps/earth

there are various commerical libs available as well e.g. ESRI or Luciad

jk
+1  A: 

We actually use this as an interview question. I agree with jk, you should use a third party library, but I'll give you an idea

First storing this data as an image is the wrong approach. We actually word our question to immediately direct people away from this approach. You really want to store individual roads or features as a series of points (preferably using splines so you can efficiently represent curves) and then render the correct roads. Now because you're using vector (rather than raster) data your scaling and rotation issues are solved.

You were going down the right path when you discussed breaking it into smaller squares. Each square should contain data about all of the roads that pass through it. If a road crosses an edge, break it into two road pieces, one in each square. That way each square has enough data to render itself completely.

Looking up the squares you need to draw can be a bit of a pain, but no worse than you had to solve with images. Personally I'd store a bunch of data structures in a binary file with an index at the beginning, listing where each square begins in the file and how long it is. That way you can read the data for the square pretty efficiently (jump to correct position in TOC, read TOC data, jump to start of square, read square data). You could even optimize for empty squares sharing space.

Last, you'll probably want to do different levels of zoom. Personally I'd store a completely separate set of blocks at a few different zoom levels. That way you can vary the size of the block as appropriate.

Again, to reiterate, use a product off the shelf, but there's no problem using this as a gedankenexperimente.

Hounshell
My requirements are simple, no need to add roads/points to maps. Just maps, because this app is running on a mobile device, which is limited resources :)
Vimvq1987
I think you'll actually find that you get better compression this way. What kind of scale will your maps get to? Google maps zoomed all the way in is 1 pixel : ~50cm. Even if you drop it down to 1 pixel : 2m you're still going to need a ton of pixels (The US is 9,826,675 sq km, which would be 2,456,668,750,000 pixels). On a PNG with average compression you're still looking at 982,667,500,000 bytes (2,456... pixels * 4 * 0.1). Plus I'd wager that drawing the map from line segments with knowledge of the zoom and rotation would be more efficient than zooming and rotating an existing image.
Hounshell
my map data is about 11MB in size, actually :)
Vimvq1987
+1  A: 

OSMTracker is made in VB.NET uses OpenStreetMap tiles(images) as map and dos what you want. the source is available. if you don't like VB then you can search for OpenStreetMap on codeplex.com for similar projects made in c#

LiFo