| 1 | SDTD_Projection = {
|
|---|
| 2 | project: function (latlng) {
|
|---|
| 3 | return new L.Point(latlng.lng / 16, latlng.lat / 16);
|
|---|
| 4 | },
|
|---|
| 5 |
|
|---|
| 6 | unproject: function (point) {
|
|---|
| 7 | return new L.LatLng(point.y * 16, point.x * 16);
|
|---|
| 8 | }
|
|---|
| 9 | };
|
|---|
| 10 |
|
|---|
| 11 | SDTD_CRS = L.extend({}, L.CRS.Simple, {
|
|---|
| 12 | projection: SDTD_Projection,
|
|---|
| 13 | transformation: new L.Transformation(1, 0, -1, 0),
|
|---|
| 14 |
|
|---|
| 15 | scale: function (zoom) {
|
|---|
| 16 | return Math.pow(2, zoom);
|
|---|
| 17 | }
|
|---|
| 18 | });
|
|---|
| 19 |
|
|---|
| 20 | var CoordToChunk = function(latlng) {
|
|---|
| 21 | var x = Math.floor(((latlng.lng + 16777216) / 16) - (16777216 / 16));
|
|---|
| 22 | var y = Math.floor(((latlng.lat + 16777216) / 16) - (16777216 / 16));
|
|---|
| 23 | return L.latLng(y, x);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | var CoordToRegion = function(latlng) {
|
|---|
| 27 | var x = Math.floor(((latlng.lng + 16777216) / 512) - (16777216 / 512));
|
|---|
| 28 | var y = Math.floor(((latlng.lat + 16777216) / 512) - (16777216 / 512));
|
|---|
| 29 | return L.latLng(y, x);
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | var FormatCoord = function(latlng) {
|
|---|
| 33 | return Math.abs(latlng.lat)+ (latlng.lat>=0 ? " N" : " S") + " / " + Math.abs(latlng.lng) + (latlng.lng>=0 ? " E" : " W");
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | var map = L.map('map', {
|
|---|
| 37 | zoomControl: true,
|
|---|
| 38 | attributionControl: false,
|
|---|
| 39 | crs: SDTD_CRS
|
|---|
| 40 | }).setView([0, 0], 0);
|
|---|
| 41 |
|
|---|
| 42 | L.tileLayer('../../map/{z}/{x}/{y}.png?t={time}', {
|
|---|
| 43 | maxZoom: 5,
|
|---|
| 44 | minZoom: 0,
|
|---|
| 45 | maxNativeZoom: 4,
|
|---|
| 46 | tileSize: 128,
|
|---|
| 47 | continuousWorld: true,
|
|---|
| 48 | tms: true,
|
|---|
| 49 | unloadInvisibleTiles: true,
|
|---|
| 50 | time: function() { return new Date().getTime(); }
|
|---|
| 51 | }).addTo(map);
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 | map.on('mousemove', function(e) {
|
|---|
| 55 | var rf = CoordToRegion(e.latlng);
|
|---|
| 56 | L.DomUtil.get('pos').textContent = FormatCoord(e.latlng);
|
|---|
| 57 | L.DomUtil.get('regfile').textContent = "r." + rf.lng + "." + rf.lat + ".7rg";
|
|---|
| 58 | });
|
|---|