Fixed hdmap tiling and LocationToLatLng

This commit is contained in:
FrozenCow 2011-07-18 03:40:24 +02:00
parent 674b92003c
commit 8b40a9761b
6 changed files with 136 additions and 152 deletions

View File

@ -31,7 +31,7 @@
<script type="text/javascript" src="js/jquery.mousewheel.js"></script> <script type="text/javascript" src="js/jquery.mousewheel.js"></script>
<script type="text/javascript" src="js/minecraft.js"></script> <script type="text/javascript" src="js/minecraft.js"></script>
<script type="text/javascript" src="js/map.js"></script> <script type="text/javascript" src="js/map.js"></script>
<!--<script type="text/javascript" src="js/hdmap.js"></script>--> <script type="text/javascript" src="js/hdmap.js"></script>
<script type="text/javascript" src="js/kzedmaps.js"></script> <script type="text/javascript" src="js/kzedmaps.js"></script>
<script type="text/javascript" src="js/flatmap.js"></script> <script type="text/javascript" src="js/flatmap.js"></script>
<script type="text/javascript" src="config.js"></script> <script type="text/javascript" src="config.js"></script>

View File

@ -20,10 +20,7 @@ L.CustomMarker = L.Class.extend({
if (!this._element && this.options.elementCreator) { if (!this._element && this.options.elementCreator) {
this._element = this.options.elementCreator(); this._element = this.options.elementCreator();
this._element.className += ' leaflet-marker-icon';
// TODO: Pass this fix to Leaflet-dev(s), it may be a bug in Leaflet.
this._element.style.position = 'absolute';
this._initInteraction(); this._initInteraction();
} }

View File

@ -1,4 +1,7 @@
var DynmapProjection = L.Class.extend({ var DynmapProjection = L.Class.extend({
initialize: function(options) {
L.Util.setOptions(this, options);
},
fromLocationToLatLng: function(location) { fromLocationToLatLng: function(location) {
throw "fromLocationToLatLng not implemented"; throw "fromLocationToLatLng not implemented";
} }

View File

@ -5,13 +5,14 @@ var FlatProjection = DynmapProjection.extend({
}); });
var FlatMapType = DynmapTileLayer.extend({ var FlatMapType = DynmapTileLayer.extend({
projection: new FlatProjection({}),
options: { options: {
minZoom: 0, minZoom: 0,
maxZoom: 4 maxZoom: 4
}, },
initialize: function(options) { initialize: function(options) {
options.maxZoom = options.mapzoomin + options.world.extrazoomout;
L.Util.setOptions(this, options); L.Util.setOptions(this, options);
this.projection = new FlatProjection({extrazoom: this.options.world.extrazoomout});
}, },
getTileName: function(tilePoint, zoom) { getTileName: function(tilePoint, zoom) {
var tileName; var tileName;
@ -19,13 +20,32 @@ var FlatMapType = DynmapTileLayer.extend({
if(this.options.nightandday && this.dynmap.serverday) { if(this.options.nightandday && this.dynmap.serverday) {
dnprefix = '_day'; dnprefix = '_day';
} }
tileName = this.options.prefix + dnprefix + '_128_' + tilePoint.x + '_' + tilePoint.y + '.png'; var extrazoom = this.options.world.extrazoomout;
if(zoom < extrazoom) {
var scale = 1 << (extrazoom-zoom);
var zprefix = "zzzzzzzzzzzz".substring(0, extrazoom-zoom);
if(this.options.bigmap) {
tileName = this.options.prefix + dnprefix + '_128/' + ((scale*tilePoint.x) >> 5) + '_' + ((scale*tilePoint.y) >> 5) + '/' + zprefix + "_" + (scale*tilePoint.x) + '_' + (scale*tilePoint.y) + '.png';
} else {
tileName = zprefix + this.options.prefix + dnprefix + '_128_' + (scale*tilePoint.x) + '_' + (scale*tilePoint.y) + '.png';
}
}
else {
if(this.options.bigmap) {
tileName = this.options.prefix + dnprefix + '_128/' + (tilePoint.x >> 5) + '_' + (tilePoint.y >> 5) + '/' + tilePoint.x + '_' + tilePoint.y + '.png';
} else {
tileName = this.options.prefix + dnprefix + '_128_' + tilePoint.x + '_' + tilePoint.y + '.png';
}
}
return tileName; return tileName;
}, },
calculateTileSize: function(zoom) { calculateTileSize: function(zoom) {
return Math.pow(2, 7+zoom); var extrazoom = this.options.world.extrazoomout;
return (zoom < extrazoom)
? 128
: Math.pow(2, 7+zoom-extrazoom);
} }
}) });
/* /*
function FlatMapType(configuration) { function FlatMapType(configuration) {

View File

@ -1,22 +1,54 @@
function HDProjection() {} var HDProjection = DynmapProjection.extend({
HDProjection.prototype = { fromLocationToLatLng: function(location) {
extrazoom: 0, var wtp = this.options.worldtomap;
worldtomap: null, console.log(wtp);
fromLatLngToPoint: function(latLng) { var xx = wtp[0]*location.x + wtp[1]*location.y + wtp[2]*location.z;
return new google.maps.Point(latLng.lng()*config.tileWidth, latLng.lat()*config.tileHeight); var yy = wtp[3]*location.x + wtp[4]*location.y + wtp[5]*location.z;
}, var lat = xx / (8 << this.options.extrazoom);
fromPointToLatLng: function(point) { var lng = (128-yy) / (8 << this.options.extrazoom);
return new google.maps.LatLng( point.y/config.tileHeight, point.x/config.tileWidth); return new L.LatLng(lat, lng, true);
}, }
fromWorldToLatLng: function(x, y, z) { });
var wtp = this.worldtomap;
var xx = wtp[0]*x + wtp[1]*y + wtp[2]*z;
var yy = wtp[3]*x + wtp[4]*y + wtp[5]*z;
return new google.maps.LatLng( (1 - (yy / config.tileHeight)) / (1 << this.extrazoom), xx / config.tileWidth / (1 << this.extrazoom));
}
};
var HDMapType = DynmapTileLayer.extend({
projection: undefined,
options: {
minZoom: 0,
maxZoom: 3
},
initialize: function(options) {
options.maxZoom = options.mapzoomin + options.world.extrazoomout;
L.Util.setOptions(this, options);
this.projection = new HDProjection({worldtomap: options.worldtomap})
},
getTileName: function(tilePoint, zoom) {
var tileName;
var dnprefix = '';
if(this.options.nightandday && this.options.dynmap.serverday)
dnprefix = '_day';
var extrazoom = this.options.mapzoomout;
if(zoom < extrazoom) {
var scale = 1 << (extrazoom-zoom);
var zprefix = "zzzzzzzzzzzzzzzzzzzzzz".substring(0, extrazoom-zoom);
tileName = this.options.prefix + dnprefix + '/' + ((scale*tilePoint.x) >> 5) + '_' + ((-scale*tilePoint.y) >> 5) + '/' + zprefix + "_" + (scale*tilePoint.x) + '_' + (-scale*tilePoint.y) + '.png';
} else {
tileName = this.options.prefix + dnprefix + '/' + (tilePoint.x >> 5) + '_' + ((-tilePoint.y) >> 5) + '/' + tilePoint.x + '_' + (-tilePoint.y) + '.png';
}
return tileName;
},
calculateTileSize: function(zoom) {
var extrazoom = this.options.mapzoomout;
console.log(zoom <= extrazoom, zoom, extrazoom);
return (zoom <= extrazoom)
? 128
: Math.pow(2, 7+zoom-extrazoom);
//128;
}
});
/*
function HDMapType(configuration) { function HDMapType(configuration) {
$.extend(this, configuration); } $.extend(this, configuration); }
HDMapType.prototype = $.extend(new DynMapType(), { HDMapType.prototype = $.extend(new DynMapType(), {
@ -86,5 +118,5 @@ HDMapType.prototype = $.extend(new DynMapType(), {
this.tileSize = new google.maps.Size(size, size); this.tileSize = new google.maps.Size(size, size);
} }
}); });
*/
maptypes.HDMapType = function(configuration) { return new HDMapType(configuration); }; maptypes.HDMapType = function(options) { return new HDMapType(options); };

View File

@ -1,130 +1,62 @@
function KzedProjection() {} var KzedProjection = DynmapProjection.extend({
KzedProjection.prototype = { fromLocationToLatLng: function(location) {
extrazoom: 0, var dx = location.x;
fromLatLngToPoint: function(latLng) { var dy = location.y - 127;
var x = latLng.lng() * config.tileWidth; var dz = location.z;
var y = latLng.lat() * config.tileHeight; var px = dx + dz;
var py = dx - dz - dy;
return new google.maps.Point(x, y); var scale = 2 << this.options.extrazoom;
},
fromPointToLatLng: function(point) { var lat = px / scale - 64;
var lng = point.x / config.tileWidth; var lng = py / scale;
var lat = point.y / config.tileHeight; return new L.LatLng(-lat, lng, true);
return new google.maps.LatLng(lat, lng); }
}, });
fromWorldToLatLng: function(x, y, z)
{ var KzedMapType = DynmapTileLayer.extend({
var dx = +x; options: {
var dy = +y - 127; minZoom: 0,
var dz = +z; maxZoom: 4
var px = dx + dz; },
var py = dx - dz - dy; initialize: function(options) {
var scale = 2 << this.extrazoom; options.maxZoom = options.mapzoomin + options.world.extrazoomout;
L.Util.setOptions(this, options);
var lng = -px / config.tileWidth / scale + (1.0 / scale); this.projection = new KzedProjection({extrazoom: this.options.world.extrazoomout});
var lat = py / config.tileHeight / scale; },
getTileName: function(tilePoint, zoom) {
return new google.maps.LatLng(lat, lng); var tileSize = 128;
} var tileName = '';
};
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;
var debugred;
var debugblue;
var dnprefix = ''; var dnprefix = '';
if(this.dynmap.map.mapTypes[this.dynmap.map.mapTypeId].nightandday && this.dynmap.serverday)
dnprefix = '_day'; if(this.options.nightandday && this.options.dynmap.serverday) {
var extrazoom = this.dynmap.world.extrazoomout; dnprefix = '_day';
if (zoom <= extrazoom) { }
var zpre = 'zzzzzzzzzzzzzzzz'.substring(0, extrazoom-zoom); var extrazoom = this.options.world.extrazoomout;
// Most zoomed out tiles. if (zoom <= extrazoom) {
tileSize = 128; var zpre = 'zzzzzzzzzzzzzzzz'.substring(0, extrazoom-zoom);
imgSize = tileSize; // Most zoomed out tiles.
var tilescale = 2 << (extrazoom-zoom); var tilescale = 2 << (extrazoom-zoom);
if (this.dynmap.map.mapTypes[this.dynmap.map.mapTypeId].bigmap) { if (this.options.bigmap) {
if(zoom < extrazoom) zpre = zpre + '_'; if(zoom < extrazoom) zpre = zpre + '_';
tileName = 'z' + this.prefix + dnprefix + '/' + ((-coord.x * tileSize*tilescale)>>12) + tileName = 'z' + this.options.prefix + dnprefix + '/' + ((-tilePoint.x * tileSize*tilescale)>>12) + '_' + ((tilePoint.y * tileSize*tilescale) >> 12) + '/' + zpre + (-tilePoint.x * tileSize*tilescale) + '_' + (tilePoint.y * tileSize*tilescale) + '.png';
'_' + ((coord.y * tileSize*tilescale) >> 12) + '/' + zpre + } else {
(-coord.x * tileSize*tilescale) + '_' + (coord.y * tileSize*tilescale) + '.png'; tileName = zpre + 'z' + this.options.prefix + dnprefix + '_' + (-tilePoint.x * tileSize*tilescale) + '_' + (tilePoint.y * tileSize*tilescale) + '.png';
} }
else { } else {
tileName = zpre + 'z' + this.prefix + dnprefix + '_' + (-coord.x * tileSize*tilescale) + '_' + (coord.y * tileSize*tilescale) + '.png'; if(this.options.bigmap) {
} tileName = this.options.prefix + dnprefix + '/' + ((-tilePoint.x*tileSize) >> 12) + '_' + ((tilePoint.y*tileSize)>>12) + '/' + (-tilePoint.x*tileSize) + '_' + (tilePoint.y*tileSize) + '.png';
} else { } else {
// Other zoom levels. tileName = this.options.prefix + dnprefix + '_' + (-tilePoint.x*tileSize) + '_' + (tilePoint.y*tileSize) + '.png';
tileSize = 128;
imgSize = Math.pow(2, 6+zoom-extrazoom);
if(this.dynmap.map.mapTypes[this.dynmap.map.mapTypeId].bigmap) {
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'; return tileName;
} },
} calculateTileSize: function(zoom) {
var img; var extrazoomout = this.options.dynmap.world.extrazoomout;
var tile = $('<div/>') return (zoom <= extrazoom)
.addClass('tile') ? 128
.css({ : Math.pow(2, 6+zoom-extrazoomout);
width: tileSize + 'px', }
height: tileSize + 'px' });
});
if (tileDebugText) {
$('<span/>')
.text(tileDebugText)
.css({
position: 'absolute',
color: 'red'
})
.appendTo(tile);
}
if (tileName) {
img = $('<img/>')
.attr('src', this.dynmap.getTileUrl(tileName))
.error(function() { img.hide(); })
.bind('load', function() { img.show(); })
.css({
width: imgSize + 'px',
height: imgSize + 'px',
borderStyle: 'none'
})
.hide()
.appendTo(tile);
this.dynmap.registerTile(this, tileName, img);
} else {
this.dynmap.unregisterTile(this, tileName);
}
return tile.get(0);
},
updateTileSize: function(zoom) {
var size;
var extrazoom = this.dynmap.world.extrazoomout;
var mapzoomin = this.mapzoomin;
this.projection.extrazoom = extrazoom;
this.maxZoom = mapzoomin + extrazoom;
if (zoom <= extrazoom) {
size = 128;
} else {
size = Math.pow(2, 6+zoom-extrazoom);
}
this.tileSize = new google.maps.Size(size, size);
}
});
maptypes.KzedMapType = function(configuration) { return new KzedMapType(configuration); }; maptypes.KzedMapType = function(configuration) { return new KzedMapType(configuration); };