Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.

Commit 096e84e

Browse files
committed
refactor: update utils to new map
This should accuratly calculate the coords from in game to the map coords
1 parent 9a3cfd8 commit 096e84e

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

js/src/utils.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,34 @@
1919
function isNumeric(n) {
2020
return !isNaN(parseFloat(n)) && isFinite(n)
2121
}
22-
var game_1_x = 1972.606;
23-
var game_1_y = 3817.044;
24-
var map_1_lng = -60.8258056640625;
25-
var map_1_lat = 72.06379257078102;
26-
var game_2_x = -1154.11;
27-
var game_2_y = -2715.203;
28-
var map_2_lng = -72.1417236328125;
29-
var map_2_lat = 48.41572128171852;
22+
var game_min_x = -4000;
23+
var game_max_x = 6000;
24+
25+
var game_min_y = 8000;
26+
var game_max_y = -4000;
27+
28+
var map_min_x = 0;
29+
var map_max_x = 2048*2 + 1024;
30+
31+
var map_min_y = 0;
32+
var map_max_y = 2048*3 - 256;
33+
34+
function normalize(value, min, max){
35+
return Math.abs((value - min) / (max - min));
36+
}
37+
38+
function convertToMap(x, y){
39+
var xPercent = normalize(x, game_min_x, game_max_x);
40+
var destX = xPercent * (Math.abs(map_max_x - map_min_x)) + map_min_x;
41+
42+
var yPercent = normalize(y, game_min_y, game_max_y);
43+
var destY = yPercent * (Math.abs(map_max_y - map_min_y)) + map_min_y;
44+
45+
console.log(x + ", " + y + " == " + destX + ", " + destY);
46+
console.log(_MAP_map.unproject([destX, destY], _MAP_map.getMaxZoom()));
47+
48+
return _MAP_map.unproject([destX, destY], _MAP_map.getMaxZoom());
49+
}
3050

3151
function convertToGame(lat, lng) {
3252
var rX = game_1_x + (lng - map_1_lng) * (game_1_x - game_2_x) / (map_1_lng - map_2_lng);
@@ -47,7 +67,7 @@ function convertToGameCoord(lat, lng) {
4767
};
4868
}
4969

50-
function convertToMap(x, y) {
70+
function convertToMap_OLD(x, y) {
5171
var rLng = map_1_lng + (x - game_1_x) * (map_1_lng - map_2_lng) / (game_1_x - game_2_x);
5272
var rLat = map_1_lat + (y - game_1_y) * (map_1_lat - map_2_lat) / (game_1_y - game_2_y);
5373
return result = {
@@ -56,18 +76,6 @@ function convertToMap(x, y) {
5676
};
5777
}
5878

59-
function convertToMapGMAP(x, y) {
60-
var rLng = map_1_lng + (x - game_1_x) * (map_1_lng - map_2_lng) / (game_1_x - game_2_x);
61-
var rLat = map_1_lat + (y - game_1_y) * (map_1_lat - map_2_lat) / (game_1_y - game_2_y);
62-
return new google.maps.LatLng(rLat, rLng);
63-
}
64-
65-
function convertToMapGMAPcoord(coord) {
66-
var rLng = map_1_lng + (coord.x - game_1_x) * (map_1_lng - map_2_lng) / (game_1_x - game_2_x);
67-
var rLat = map_1_lat + (coord.y - game_1_y) * (map_1_lat - map_2_lat) / (game_1_y - game_2_y);
68-
return new google.maps.LatLng(rLat, rLng);
69-
}
70-
7179
function stringCoordToFloat(coord) {
7280
return result = {
7381
x: parseFloat(coord.x),

0 commit comments

Comments
 (0)