-
Notifications
You must be signed in to change notification settings - Fork 0
/
unmined.js
128 lines (101 loc) · 3.44 KB
/
unmined.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Functions for Google Maps
uNmINeD (C) 2012 Balázs Farkas
http://unmined.intro.hu
*/
var minMapX = minRegionX * 512;
var minMapY = minRegionZ * 512;
var mapWidth = (maxRegionX + 1 - minRegionX) * 512;
var mapHeight = (maxRegionZ + 1 - minRegionZ) * 512;
/*
Lat/long ranges:
lat: -90 .. +90
long: -180 .. +180
*/
var lattitudeRange = 9;
var longitudeRange = 9;
var transformFactor = Math.pow(2, standardZoom - minZoom);
function UnminedProjection() {};
UnminedProjection.prototype.fromLatLngToPoint = function(latLng, opt_point)
{
var point = opt_point || new google.maps.Point(0, 0);
point.x = (latLng.lng() / longitudeRange) + 0.5;
point.y = (latLng.lat() / lattitudeRange) + 0.5;
point.x = (point.x * mapWidth + minMapX) / transformFactor;
point.y = (point.y * mapHeight + minMapY) / transformFactor;
return point;
};
UnminedProjection.prototype.fromPointToLatLng = function(point)
{
point.x = (point.x * transformFactor - minMapX) / mapWidth;
point.y = (point.y * transformFactor - minMapY) / mapHeight;
point.x = (point.x - 0.5) * longitudeRange;
point.y = (point.y - 0.5) * lattitudeRange;
return new google.maps.LatLng(point.y, point.x, true);
};
UnminedProjection.prototype.fromPointToMinecraft = function(point)
{
return new google.maps.Point(point.x * transformFactor, point.y * transformFactor);
};
UnminedProjection.prototype.fromMinecraftToPoint = function(point)
{
return new google.maps.Point(point.x / transformFactor, point.y / transformFactor);
};
function getQueryParams()
{
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = pair[1];
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]], pair[1] ];
query_string[pair[0]] = arr;
} else {
query_string[pair[0]].push(pair[1]);
}
}
return query_string;
}
var unminedTypeOptions = {
getTileUrl: function(coord, zoom) {
zoomFactor = Math.pow(2, zoom - standardZoom);
var minTileX = Math.floor(minMapX * zoomFactor / 256);
var minTileY = Math.floor(minMapY * zoomFactor / 256);
var maxTileX = Math.ceil((minMapX + mapWidth) * zoomFactor / 256) - 1;
var maxTileY = Math.ceil((minMapY + mapHeight) * zoomFactor / 256) - 1;
if (coord.x >= minTileX
&& coord.y >= minTileY
&& coord.x <= maxTileX
&& coord.y <= maxTileY)
return "tiles"
+ "/zoom." + (zoom - standardZoom)
+ "/" + Math.floor(coord.x / 10)
+ "/" + Math.floor(coord.y / 10)
+ "/tile"
+ "." + coord.x
+ "." + coord.y
+ "." + tileImageFormat;
else
return "tiles/empty." + tileImageFormat;
},
tileSize: new google.maps.Size(256, 256),
maxZoom: maxZoom,
minZoom: minZoom,
name: "unmined"
};
var unminedMapType = new google.maps.ImageMapType(unminedTypeOptions);
unminedMapType.projection = new UnminedProjection();
var unminedDefaultOptions = {
zoom: defaultZoom,
center: unminedMapType.projection.fromPointToLatLng(new google.maps.Point(0, 0)),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
mapTypeControlOptions:
{
mapTypeIds: ["unmined"]
}
};