Created
December 14, 2015 18:49
-
-
Save oberhamsi/3fb0d3ae4c06c1565ecd to your computer and use it in GitHub Desktop.
viewer for webmap generated by alloc's server fixes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | |
</head> | |
<body> | |
<div id="7map" style="height: 100%"></div> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css"/> | |
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script> | |
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script> | |
(function() { | |
var initTime = Date.now(); | |
var mapinfo = { | |
regionsize: 512, | |
chunksize: 16, | |
tilesize: 128, | |
maxzoom: 4 | |
}; | |
/** | |
* create tile layer | |
*/ | |
function getSdtdTileLayer (mapinfo, initTime) { | |
var tileLayer = L.tileLayer('./map/{z}/{x}/{y}.png?t={time}', { | |
maxZoom: mapinfo.maxzoom + 1, | |
minZoom: Math.max(0, mapinfo.maxzoom - 5), | |
maxNativeZoom: mapinfo.maxzoom, | |
tileSize: mapinfo.tilesize, | |
continuousWorld: true, | |
tms: true, | |
time: initTime | |
}); | |
// TileLayer w/ TMS=true fix for zoomlevel >= 8 | |
tileLayer._getWrapTileNum = function () { | |
return L.point(0, 0); | |
}; | |
return tileLayer; | |
} | |
/** | |
* show map | |
*/ | |
function initMap() { | |
var SDTD_Projection = { | |
project: function (latlng) { | |
return new L.Point( | |
(latlng.lat) / Math.pow(2, mapinfo.maxzoom), | |
(latlng.lng) / Math.pow(2, mapinfo.maxzoom) ); | |
}, | |
unproject: function (point) { | |
return new L.LatLng( | |
point.x * Math.pow(2, mapinfo.maxzoom), | |
point.y * Math.pow(2, mapinfo.maxzoom) ); | |
} | |
}; | |
var SDTD_CRS = L.extend({}, L.CRS.Simple, { | |
projection: SDTD_Projection, | |
transformation: new L.Transformation(1, 0, -1, 0), | |
scale: function (zoom) { | |
return Math.pow(2, zoom); | |
} | |
}); | |
var map = L.map('7map', { | |
zoomControl: false, // Added by Zoomslider | |
zoomsliderControl: true, | |
attributionControl: false, | |
crs: SDTD_CRS | |
}).setView([0, 0], Math.max(0, mapinfo.maxzoom - 5)); | |
getSdtdTileLayer(mapinfo, initTime) | |
.addTo(map); | |
} | |
// start | |
$.getJSON( "./map/mapinfo.json") | |
.done(function(data) { | |
mapinfo.tilesize = data.blockSize; | |
mapinfo.maxzoom = data.maxZoom; | |
initMap(); | |
}) | |
.fail(function(jqxhr, textStatus, error) { | |
console.log ("Error fetching map information"); | |
}); | |
})(); | |
</script | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment