From 43a9df351ac3c69bcd19e8dbb84583181f59ee22 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 2 Feb 2015 18:39:44 +0100 Subject: viewer: center on spawn --- viewer/MinedMap.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'viewer') diff --git a/viewer/MinedMap.js b/viewer/MinedMap.js index 17a31cb..959e3ed 100644 --- a/viewer/MinedMap.js +++ b/viewer/MinedMap.js @@ -1,7 +1,7 @@ var MinedMapLayer = L.GridLayer.extend({ - initialize: function (info) { - this._info = info.info; - this._regions = info.regions; + initialize: function (info, regions) { + this._info = info; + this._regions = regions; this.options.attribution = 'Generated by MinedMap'; @@ -68,21 +68,24 @@ var MinedMapLayer = L.GridLayer.extend({ window.createMap = function () { var xhr = new XMLHttpRequest(); xhr.onload = function () { - var info = JSON.parse(this.responseText); + var res = JSON.parse(this.responseText), + info = res.info, + regions = res.regions, + spawn = res.spawn; var map = L.map('map', { - center: [0, 0], + center: [-spawn.z, spawn.x], zoom: 0, minZoom: 0, maxZoom: 3, crs: L.CRS.Simple, maxBounds: [ - [-512*(info.info.maxZ+1), 512*info.info.minX], - [-512*info.info.minZ, 512*(info.info.maxX+1)], + [-512*(info.maxZ+1), 512*info.minX], + [-512*info.minZ, 512*(info.maxX+1)], ], }); - (new MinedMapLayer(info)).addTo(map); + (new MinedMapLayer(info, regions)).addTo(map); }; xhr.open('GET', 'data/info.json', true); -- cgit v1.2.3