Map Cruncher
From Google Mapki
All those of you wanting to make custom map sets from a single source image can do it very well and easily using http://research.microsoft.com/mapcruncher/
Microsoft use the same tiling scheme and projection for their map tiles, just a different tile naming convention.
The Mapcruncher tool lets you register several corresponding points on
a Virtual Earth Map and an image of your own. Having done that, it will
then generate a tile set (at lots of zoom levels) for you to use with
the VE map control. The really good new is that you can use the same
tile set with the Google Maps API.
The following code generates a tile file name for your custom tiles
using the x,y and z tile parameters that get passed to
GTileLayer.getTileUrl
TileToQuadKey ( tx, ty, zl) {
var quad;
quad = "";
for (var i = zl; i > 0; i--){
var mask = 1 << (i - 1);
var cell = 0;
if ((tx & mask) != 0)
cell++;
if ((ty & mask) != 0)
cell += 2;
quad += cell;
}
return quad;
}
MapCruncher stores its correspondence points in a .YUM file (XML). If you know some pixel to WGS84 Lat/Lon equivalences for your image, e.g. the corners, you can edit these in by hand.
Beware Map cruncher stores temporary map tiles in C:\Documents and Settings\User\Local Settings\Temp\mapcache You will need to empty this from time to time especially if MapCruncher fails to update images if you rerun a crunch with an updated input image.
[edit] How to replace Microsoft Virtual Earth's maps by Google maps
On many places Microsoft Virtual Earth maps are not as as Google maps. You may want to display Google maps instead. For this, doing a workaround is required, which is not exactly in accord with terms of use of Google maps, so if you follow this advices, you do it on your own risk.
Add these lines to hosts file (on Windows XP C:\WINDOWS\system32\drivers\etc\):
127.0.0.1 a0.ortho.tiles.virtualearth.net 127.0.0.1 a1.ortho.tiles.virtualearth.net 127.0.0.1 a2.ortho.tiles.virtualearth.net 127.0.0.1 a3.ortho.tiles.virtualearth.net 127.0.0.1 r0.ortho.tiles.virtualearth.net 127.0.0.1 r1.ortho.tiles.virtualearth.net 127.0.0.1 r2.ortho.tiles.virtualearth.net 127.0.0.1 r3.ortho.tiles.virtualearth.net 127.0.0.1 h0.ortho.tiles.virtualearth.net 127.0.0.1 h1.ortho.tiles.virtualearth.net 127.0.0.1 h2.ortho.tiles.virtualearth.net 127.0.0.1 h3.ortho.tiles.virtualearth.net
This will redirect all the requests for Virtual Earth maps to localhost. You must have installed some server software (eg Apache with PHP) to create following .htaccess file placed in the root of web server:
RewriteEngine On RewriteRule ^tiles/h(.*)\.jpeg$ /redirect.php?url=$1
Create blank image, that will be displayed if no data is accessible (you can create a similar one that is used in Google maps - gray background with text that the tile was not found). Save it as blank.jpg in the root of web server.
Create file redirect.php with following contents:
<?php
header("Content-Type: image/jpg");
// log redirect errors if some
$log = fopen("redirectlog", "a");
$url = $_GET["url"];
$zoom = abs(strlen($url) + 1 - 18);
if(strlen($zoom > 17)) {
$zoom = 1;
}
$x = 0;
$y = 0;
for($i = 0; $i < strlen($url); $i++) {
$part = $url[$i];
$x *= 2;
$y *= 2;
switch($part) {
case "1":
$x += 1;
break;
case "2":
$y += 1;
break;
case "3":
$x += 1;
$y += 1;
break;
}
}
$addr = "http://mt1.google.com/mt?n=404&v=ap.75&hl=en&x=$x&y=$y&zoom=$zoom&s=G";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $addr);
// these headers must be sent in order not to get error from google servers
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.51",
"Host: mt1.google.com",
"Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-bitmap, */*;q=0.1",
"Accept-Language: en",
"Accept-Charset: windows-1252, utf-8, utf-16, iso-8859-1;q=0.6, *;q=0.1",
"Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0",
"Connection: Keep-Alive, TE",
"TE: deflate, gyip, chunked, identity, trailers"
));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$loaded = curl_exec($ch);
fwrite($log, curl_error($ch). "\t" . $url . "\n");
fclose($log);
curl_close($ch);
if(!$loaded) {
readfile("blank.jpg");
}
?>
If some error occurs, it is logged into file redirectlog
Beware also that this workaround also changes maps on every single web page using Microsoft Virtual Earth API. To restore the state before, just remove added lines in hosts file.
(Please edit to do some language corrections)
