Home News speed improvements

speed improvements

By Graham Asher on 14 September 2011

Changes to the CTM1 map data file format allow large maps to be drawn much faster.

Recently we had some trouble getting large maps to draw fast on iOS (on the iPhone and iPad). The CTM1 (CartoType map data) files were in the low hundreds of megabytes and included terrain data so that relief could be shown. At first I suspected the speed of drawing the terrain. Terrain is drawn using a texture - that is, a bitmap which is transformed to cover the correct region of the display and drawn by subsampling or supersampling. Texture drawing involves quite a lot of calculation, so that seemed a good candidate. But in fact it turned out that the problem was simply the time it took to read map objects from the CTM1 file. There were two problem areas:

(i) reading map objects then throwing them away because they were not needed - either they didn't overlap the area to be drawn, or they didn't satisify the search criteria; and

(ii) reading coordinates at high resolution, then simplifying them to be drawn at a lower resolution by omitting detail smaller than a pixel.

These problems have now been solved. We can tell that we solved them because each of the two fixes brought a huge increase in speed in drawing maps, particularly when zoomed out, and on the iOS platform.

The fix for problem (i) was to introduce an incompatible change to the CTM1 format: version 4. It stores the bounding box of an object at the start of its data in the file, allowing it to be skipped before a C++ object is created, or any memory allocation is done. Use the new /v4 option with generate_map_data_type1 to create CTM1 version 4 map files.

The fix for problem (ii) was to create sets of lower-resolution layers - that is, simplification and generalisation of map objects for lower resolutions is done at data preparation time, not at runtime. The data accessor automatically finds the data most appropriate to the current resolution. This approach is very similar to the concept of mipmaps. Use the new /lowreslayers=yes option with generate_map_data_type1 to create CTM1 files with low-resolution layers. This change is compatible with earlier versions of the CTM1 format because it adds a new table that is ignored by older versions of CartoType.