Web whack.thechajoneri.se
Whack!
My world of hacks

Eniro maps

Once I released the Eniro images hack, I got a question from a user at the Google Earth community site if it was possible to add the maps from Eniro as well. I was first reluctant, because I felt the maps would cover all the imagery and also the default "Roads" layer in Google Earth was good enough. Still, he claimed it would be useful because the maps from Eniro were more detailed. I decided to give it a shot.

I took a quick look at the site, but they had added more features since I looked at it last time. Now they used a much more "AJAXy" approach and loaded tiles on demand to make panning and other things possible. However, the same user who requested the maps had documented the older style ULR interface and it turned out it was still functioning.


The maps URL

This is the format of the maps url:

maps.eniro.se/servlets/se_MapImageLocator
?zoomlevel=[zoom]&size=[x-size]x[y-size]&center=[x];[y]


The zoomlevel is of course the zoom of the map, more about this later.
The x-size and y-size parameters controls the size of the image you request. Experiments showed that 1000x1000 was the limit in size.
Finally, x and y is the center of the map given in RT90 coordinates. If you don't know what RT90 coordinates are, you can read up on the page about Eniro images.

All of these were straight forward, except for the zoomlevel. This was a discrete integer parameter, I found the possible values to be 0-9. The problem was to relate these zoomlevels to an actual physical scale of the resulting map. The Eniro images were a lot simpler, since I could ask for a certain area defined by an upper left and lower right corner, and the server would figure out the best scale it had available to cover exactly that. I ended up requesting maps at the different zoomlevels and manually comparing them to corresponding images from Eniro of known areas and thereby calculate a reasonable approximation of the scale for each level. The result is OK, but far from perfect. Also I could not get a decent fit at lower zoomlevels so I choose to ignore them. The user will have to zoom in a bit to get a map.



Code

To figure out which zoomlevel to use, I take the bounding box from Google Earth and check for each zoomlevel, using my approximate scale, which would give me the largest image but still below 1000x1000. I then calculate the mid point, and the image size based on the selected scale and generate the image URL.

As a final twist I had the generated KML make the image semi transparent so it would not cover the imagery totally. I also nudged up the z-level a step so it would render on top of the other Eniro images if someone was using both network links.

The whole thing is implemented in C# in an ASP.NET page. You can download the code in the form of a zip-file below:

Result

As mentioned before, the geometric fit is OK but far from perfect and also differs a bit between zoomlevels. Another issue is that there is a bug in Google Earth v. 4.0.1693 which causes the images, which are in GIF format, to be displayed with wrong colors. The red and blue channels are switched. This makes for really ugly maps, with orange-pinkish water for instance...

To use it, grab the file above and install it on a web server that supports ASP.NET. The zip-file also contains an example of a KML file that points to an instance of the service on this server. If you install the ASP.NET page on your own server, remember to change the link in the KML file as well.

Happy Hacking!