Map driver

From Navit's Wiki
Revision as of 09:18, 21 October 2007 by KaZeR (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Writing a map driver

The API point of view : You first have to call

plugin_register_map_type("your maptype", map_new_your_maptype);

struct map_priv *map_new_your_maptype(struct map_methods *meth, char *filename, char charset, enum projection *pro)

meth are the methods to access the map (explained later) filename is the path to the map (set via navit.xml) charset is a pointer you have to fill with the character set of your map pro is a pointer you have to fill with your map projection (see projection.h for this, maybe we need some new here)

map_methods contains the following - map_destroy: To destroy the map - map_rect_new: To open a new rectangular area of the map. Actually there can be multiple rects, specified by the parameter sel, which is a linked list - map_get_item to get a item from the area specified by map_rect_new. It has to specify item_methods, which contains: - item_coord_rewind: To put the coordinate pointer back to start (needed if you want to read the coordinates multiple times) - item_coord_get: To get one or more coordinates of the item - item_attr_rewind: To put the attribute pointer back to start (similar to item_coord_rewind) - item_attr_get: To get an attribute of the item

Raw notes about iGuidance : It uses a format quite similar as ViaMichelin Take a look at the hawaiian map, since it is the simplest, but the other maps have a similar format (but not exactly the same, the tile configuration seems to differ)

It has a 36 byte header (which is unknown for now) Then there are 307 pointers to data. The 307 probably consists of 256 + 32 + 16 + 2 + 1 tiles Each pointer is either 0 (no data for this tile) or points to a position in the file where there are two integers: the compressed data size and the uncompressed data size

Following that are (uncompressed data size) bytes which are compressed with a slightly modified zlib. Therefore the little program below will work on viamichelin, but not on iguidance, since the crc verification fails and it returns "Invalid Data" instead of the uncompressed length

Only difference is that it doesn't use crcs. So a good starting point would be to write a little tool which extracts all tiles from a file and take a look at the tile data.

Redirect stdin from your extracted data and stdout to a new file which will contain the uncompressed data Then look at the uncompressed data with an hex editor Usually the coordinates in this data are clearly visible. Write out the coordinates into a textfile and load this textfile into navit.

Then you can see the dots and guess what they mean. And then you probably will find out what the other data in the tiles besides the coordinates mean.

So for a first step you need to compile zlib and disable its crc check. Then if you write a little program which decompresses all tiles we are already a big step further.

Skip the data you don't understand for now. Maybe you will know later.

Raw notes about ViaMichelin : It has a quite similar format, except that the tile configuration is different, they are using 16-Bit-Lenghts instead of 32-Bit-Pointers to the data, and their compressed stream includes the crc. So basically, it's as previously, excepted the following :

Look for the hex bytes "78 da". They usually indicate the start of a zlib compressed stream.

Cut out an area of 64 kBytes after 78 da (including 78 da) Then run this data through the following program:

  1. include <stdio.h>
  2. include <zlib.h>

char inb[65536]; char outb[65536*10]; int main(int argc, char argv) {

   long ins,outs=0;
   int ret;
   ins=read(0, inb, 65536);
   fprintf(stderr,"outs=%d ret=%d\n", outs, ret);
   write(1, outb, outs);


As previously, look at the uncompressed data with an hex editor. The coordinates are usually quite easy to identify For a first test put each coordinate into a textfile and load this textfile as map with the textfile map driver Then take a look what the coordinates might mean Skip the data you don't understand for now. Maybe you will know later