2011-02-01 15:16:54 +01:00
|
|
|
function KzedProjection() {}
|
|
|
|
KzedProjection.prototype = {
|
2011-06-23 07:53:56 +02:00
|
|
|
extrazoom: 0,
|
2011-02-01 15:16:54 +01:00
|
|
|
fromLatLngToPoint: function(latLng) {
|
2011-05-14 14:32:18 +02:00
|
|
|
var x = latLng.lng() * config.tileWidth;
|
|
|
|
var y = latLng.lat() * config.tileHeight;
|
2011-02-01 15:16:54 +01:00
|
|
|
|
|
|
|
return new google.maps.Point(x, y);
|
|
|
|
},
|
|
|
|
fromPointToLatLng: function(point) {
|
|
|
|
var lng = point.x / config.tileWidth;
|
|
|
|
var lat = point.y / config.tileHeight;
|
|
|
|
return new google.maps.LatLng(lat, lng);
|
|
|
|
},
|
|
|
|
fromWorldToLatLng: function(x, y, z)
|
|
|
|
{
|
|
|
|
var dx = +x;
|
|
|
|
var dy = +y - 127;
|
|
|
|
var dz = +z;
|
|
|
|
var px = dx + dz;
|
|
|
|
var py = dx - dz - dy;
|
2011-06-23 07:53:56 +02:00
|
|
|
var scale = 2 << this.extrazoom;
|
2011-02-01 15:16:54 +01:00
|
|
|
|
2011-06-23 07:53:56 +02:00
|
|
|
var lng = -px / config.tileWidth / scale + (1.0 / scale);
|
|
|
|
var lat = py / config.tileHeight / scale;
|
2011-02-01 15:16:54 +01:00
|
|
|
|
|
|
|
return new google.maps.LatLng(lat, lng);
|
2011-01-10 23:58:39 +01:00
|
|
|
}
|
2011-02-01 15:16:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function KzedMapType(configuration) { $.extend(this, configuration); }
|
|
|
|
KzedMapType.prototype = $.extend(new DynMapType(), {
|
|
|
|
constructor: KzedMapType,
|
|
|
|
projection: new KzedProjection(),
|
|
|
|
tileSize: new google.maps.Size(128, 128),
|
|
|
|
minZoom: 0,
|
|
|
|
maxZoom: 3,
|
|
|
|
prefix: null,
|
|
|
|
getTile: function(coord, zoom, doc) {
|
|
|
|
var tileDebugText = null;
|
|
|
|
var tileSize = 128;
|
|
|
|
var tileName;
|
|
|
|
var imgSize;
|
2011-01-10 23:58:39 +01:00
|
|
|
|
2011-02-01 15:16:54 +01:00
|
|
|
var debugred;
|
|
|
|
var debugblue;
|
2011-05-30 00:24:46 +02:00
|
|
|
|
|
|
|
var dnprefix = '';
|
|
|
|
if(this.dynmap.map.mapTypes[this.dynmap.map.mapTypeId].nightandday && this.dynmap.serverday)
|
2011-06-22 23:43:41 +02:00
|
|
|
dnprefix = '_day';
|
|
|
|
var extrazoom = this.dynmap.world.extrazoomout;
|
|
|
|
if (zoom <= extrazoom) {
|
2011-06-24 09:46:16 +02:00
|
|
|
var zpre = 'zzzzzzzzzzzzzzzz'.substring(0, extrazoom-zoom);
|
2011-02-01 15:16:54 +01:00
|
|
|
// Most zoomed out tiles.
|
|
|
|
tileSize = 128;
|
2011-06-22 23:43:41 +02:00
|
|
|
imgSize = tileSize;
|
|
|
|
var tilescale = 2 << (extrazoom-zoom);
|
2011-07-09 22:51:32 +02:00
|
|
|
if (this.dynmap.map.mapTypes[this.dynmap.map.mapTypeId].bigmap) {
|
2011-06-24 09:46:16 +02:00
|
|
|
if(zoom < extrazoom) zpre = zpre + '_';
|
|
|
|
tileName = 'z' + this.prefix + dnprefix + '/' + ((-coord.x * tileSize*tilescale)>>12) +
|
|
|
|
'_' + ((coord.y * tileSize*tilescale) >> 12) + '/' + zpre +
|
2011-06-22 23:43:41 +02:00
|
|
|
(-coord.x * tileSize*tilescale) + '_' + (coord.y * tileSize*tilescale) + '.png';
|
2011-06-14 04:43:02 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-06-24 09:46:16 +02:00
|
|
|
tileName = zpre + 'z' + this.prefix + dnprefix + '_' + (-coord.x * tileSize*tilescale) + '_' + (coord.y * tileSize*tilescale) + '.png';
|
2011-06-14 04:43:02 +02:00
|
|
|
}
|
2011-02-01 15:16:54 +01:00
|
|
|
} else {
|
|
|
|
// Other zoom levels.
|
|
|
|
tileSize = 128;
|
|
|
|
|
2011-06-22 23:43:41 +02:00
|
|
|
imgSize = Math.pow(2, 6+zoom-extrazoom);
|
2011-07-09 22:51:32 +02:00
|
|
|
if(this.dynmap.map.mapTypes[this.dynmap.map.mapTypeId].bigmap) {
|
2011-06-14 04:43:02 +02:00
|
|
|
tileName = this.prefix + dnprefix + '/' + ((-coord.x*tileSize) >> 12) + '_' +
|
|
|
|
((coord.y*tileSize)>>12) + '/' +
|
|
|
|
(-coord.x*tileSize) + '_' + (coord.y*tileSize) + '.png';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tileName = this.prefix + dnprefix + '_' + (-coord.x*tileSize) + '_' + (coord.y*tileSize) + '.png';
|
|
|
|
}
|
2011-02-01 14:17:08 +01:00
|
|
|
}
|
2011-02-01 15:16:54 +01:00
|
|
|
var img;
|
|
|
|
var tile = $('<div/>')
|
|
|
|
.addClass('tile')
|
|
|
|
.css({
|
|
|
|
width: tileSize + 'px',
|
|
|
|
height: tileSize + 'px'
|
|
|
|
});
|
|
|
|
if (tileDebugText) {
|
|
|
|
$('<span/>')
|
|
|
|
.text(tileDebugText)
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
color: 'red'
|
|
|
|
})
|
|
|
|
.appendTo(tile);
|
2011-02-01 14:17:08 +01:00
|
|
|
}
|
2011-02-01 15:16:54 +01:00
|
|
|
if (tileName) {
|
|
|
|
img = $('<img/>')
|
|
|
|
.attr('src', this.dynmap.getTileUrl(tileName))
|
|
|
|
.error(function() { img.hide(); })
|
2011-02-23 14:06:13 +01:00
|
|
|
.bind('load', function() { img.show(); })
|
2011-02-01 15:16:54 +01:00
|
|
|
.css({
|
|
|
|
width: imgSize + 'px',
|
|
|
|
height: imgSize + 'px',
|
2011-02-24 00:16:10 +01:00
|
|
|
borderStyle: 'none'
|
2011-02-01 15:16:54 +01:00
|
|
|
})
|
2011-02-23 14:06:13 +01:00
|
|
|
.hide()
|
2011-02-01 15:16:54 +01:00
|
|
|
.appendTo(tile);
|
|
|
|
this.dynmap.registerTile(this, tileName, img);
|
|
|
|
} else {
|
|
|
|
this.dynmap.unregisterTile(this, tileName);
|
2011-02-01 14:17:08 +01:00
|
|
|
}
|
2011-02-01 15:16:54 +01:00
|
|
|
return tile.get(0);
|
2011-02-17 20:08:50 +01:00
|
|
|
},
|
|
|
|
updateTileSize: function(zoom) {
|
2011-02-23 14:06:13 +01:00
|
|
|
var size;
|
2011-06-22 23:43:41 +02:00
|
|
|
var extrazoom = this.dynmap.world.extrazoomout;
|
2011-07-22 08:42:10 +02:00
|
|
|
var mapzoomin = this.mapzoomin;
|
2011-06-23 07:53:56 +02:00
|
|
|
this.projection.extrazoom = extrazoom;
|
2011-07-22 06:25:59 +02:00
|
|
|
this.maxZoom = mapzoomin + extrazoom;
|
2011-06-22 23:43:41 +02:00
|
|
|
if (zoom <= extrazoom) {
|
2011-02-23 14:06:13 +01:00
|
|
|
size = 128;
|
|
|
|
} else {
|
2011-06-22 23:43:41 +02:00
|
|
|
size = Math.pow(2, 6+zoom-extrazoom);
|
2011-02-23 14:06:13 +01:00
|
|
|
}
|
|
|
|
this.tileSize = new google.maps.Size(size, size);
|
2011-02-01 14:17:08 +01:00
|
|
|
}
|
2011-02-06 15:09:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
maptypes.KzedMapType = function(configuration) { return new KzedMapType(configuration); };
|