Changed map tiling script to emit lower quality JPGs instead of PNGs.
Changed tiler to emit 1:2 scale maps and 1:4 scale maps instead of 1:1 scale and 1:4 scale. Added location debugging on-click to the gmap.
This commit is contained in:
parent
0792d6ec39
commit
0a6f8bda0f
2 changed files with 36 additions and 21 deletions
|
@ -1,22 +1,18 @@
|
|||
import os,sys
|
||||
import Image
|
||||
|
||||
TILEWIDTH=256
|
||||
|
||||
def multiple_256(n):
|
||||
return n + (256 - (n%256))
|
||||
|
||||
def multiple_1024(n):
|
||||
return n + (1024 - (n%1024))
|
||||
#return closest multiple of k greater than n
|
||||
def multiple_k(n,k):
|
||||
return n + (k - (n%k));
|
||||
|
||||
for infile in sys.argv[1:]:
|
||||
try:
|
||||
im = Image.open(infile)
|
||||
#generate 1:2 scale tiles
|
||||
img_width = im.size[0]
|
||||
img_height = im.size[1]
|
||||
#pad width and height to the nearest multiples of 256
|
||||
img_width_r = multiple_256(img_width)
|
||||
img_height_r = multiple_256(img_height)
|
||||
img_width_r = multiple_k(img_width,512)
|
||||
img_height_r = multiple_k(img_height,512)
|
||||
|
||||
im_resized = Image.new(im.mode,(img_width_r,img_height_r))
|
||||
im_resized.paste(im,(0,0,img_width,img_height))
|
||||
|
@ -25,17 +21,18 @@ for infile in sys.argv[1:]:
|
|||
width = im.size[0]
|
||||
height = im.size[1]
|
||||
filename_base = infile[0:len(infile)-3]
|
||||
#generate fine zoom level, level 4
|
||||
for i in range(0,width/256):
|
||||
for j in range(0,height/256):
|
||||
tile_src = im.crop((i*256,j*256,(i+1)*256,(j+1)*256))
|
||||
tile_src.save("%s%d_%d_4.png" % (filename_base,i,j),"PNG")
|
||||
for i in range(0,width/512):
|
||||
for j in range(0,height/512):
|
||||
tile_src = im.crop((i*512,j*512,(i+1)*512,(j+1)*512))
|
||||
tile_src = tile_src.resize((256,256))
|
||||
tile_src.MAXBLOCK = 1000000 #workaround for jpg output bug in PIL (see: http://mail.python.org/pipermail/image-sig/1999-August/000816.html)...
|
||||
tile_src.save("%s%d_%d_4.jpg" % (filename_base,i,j),quality=70,optimize=True)
|
||||
|
||||
#pad width and height to the nearest multiples of 1024
|
||||
#generate 1:4 scale tiles
|
||||
img_width = im.size[0]
|
||||
img_height = im.size[1]
|
||||
img_width_r = multiple_1024(img_width)
|
||||
img_height_r = multiple_1024(img_height)
|
||||
img_width_r = multiple_k(img_width,1024)
|
||||
img_height_r = multiple_k(img_height,1024)
|
||||
im_resized = Image.new(im.mode,(img_width_r,img_height_r))
|
||||
im_resized.paste(im,(0,0,img_width,img_height))
|
||||
im = im_resized
|
||||
|
@ -47,6 +44,7 @@ for infile in sys.argv[1:]:
|
|||
for j in range(0,height/1024):
|
||||
tile_src = im.crop((i*1024,j*1024,(i+1)*1024,(j+1)*1024))
|
||||
tile_src = tile_src.resize((256,256))
|
||||
tile_src.save("%s%d_%d_3.png" % (filename_base,i,j),"PNG")
|
||||
tile_src.MAXBLOCK = 1000000 #workaround for jpg output bug in PIL (see: http://mail.python.org/pipermail/image-sig/1999-August/000816.html)...
|
||||
tile_src.save("%s%d_%d_3.jpg" % (filename_base,i,j),quality=70,optimize=True)
|
||||
except IOError:
|
||||
print IOError
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
var minscale = 3;
|
||||
var maxscale = 4;
|
||||
var tilelayer = new GTileLayer(copyright,minscale,maxscale);
|
||||
tilelayer.getTileUrl = function(tile,zoom) { return "/wesstats/images/test_map."+tile.x+"_"+tile.y+"_"+zoom+".png"; };
|
||||
tilelayer.isPng = function() { return true; };
|
||||
tilelayer.getTileUrl = function(tile,zoom) { return "/wesstats/images/test_map."+tile.x+"_"+tile.y+"_"+zoom+".jpg"; };
|
||||
tilelayer.isPng = function() { return false; };
|
||||
tilelayer.getOpacity = function() { return 1.0; };
|
||||
|
||||
var wmap_type = new GMapType( [tilelayer], new GMercatorProjection(18), "KillMap", {errorMessage:"No data"});
|
||||
|
@ -37,6 +37,23 @@
|
|||
var map = new GMap2(document.getElementById("map_canvas"),{mapTypes:[wmap_type],backgroundColor:"#000000"});
|
||||
map.setCenter(new GLatLng(80, -135), 3, wmap_type);
|
||||
map.addControl(new GLargeMapControl());
|
||||
GEvent.addListener(map,"click", function(overlay,latlng) {
|
||||
if (overlay) {
|
||||
// ignore if we click on the info window
|
||||
return;
|
||||
}
|
||||
var tileCoordinate = new GPoint();
|
||||
var tilePoint = new GPoint();
|
||||
var currentProjection = G_NORMAL_MAP.getProjection();
|
||||
tilePoint = currentProjection.fromLatLngToPixel(latlng, map.getZoom());
|
||||
tileCoordinate.x = Math.floor(tilePoint.x / 256);
|
||||
tileCoordinate.y = Math.floor(tilePoint.y / 256);
|
||||
var myHtml = "Latitude: " + latlng.lat() + "<br/>Longitude: " + latlng.lng() +
|
||||
"<br/>The Tile Coordinate is:<br/> x: " + tileCoordinate.x +
|
||||
"<br/> y: " + tileCoordinate.y + "<br/> at zoom level " + map.getZoom();
|
||||
map.openInfoWindow(latlng, myHtml);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue