Blog Image



Creating code, mostly for the fun of seeing it work.

png files

OSM Posted on Thu, October 02, 2008 21:30:29

I’ve now just bitten off much more than I think I chew. The tiles that make up a map are .png files. If I’m going to create a tile, I need to draw a .png file. I searched t’interweb and came up with libpng. It seems to be the definitive way to read and write png files, but it is pretty long-winded. I dug about a bit more and found pngwriter. This library seems much easier (I wrote a .png file with an image on it in a few minutes), but when I looked at the documentation a bit more there’s some stuff missing – line thickness, dotted lines etc.

It looks like I might have to get into libpng and it might take a while …


OSM Posted on Thu, October 02, 2008 21:12:56

I checked out how to do some simple tile handling for OSM. The map can be displayed using OpenLayers. This JavaScript stuff uses AJAX to get and display tiles that can be dragged around, zoomed in or zoomed out. The basis of the map are the tiles. They are 256px square. Each zoom level is twice the linear detail of the previous one, so a tile at zoom level 12 expands to 4 tiles (2×2) on zoom 13. All of this fits over a world mapped with longitude and latitude.

So one useful idea is that for any given tile, what is the long & lat of the edges of the tile. I was working on this when I tripped over the code on the OSM wiki, in any (code) language you want, so I copied it into a simple class and it worked well.