地图的 SA-MP(游戏)坐标的纬度转换不正确(而经度是正确的)
Incorrect Latitude Conversion from SA-MP(game) coordinates for map (while Longitude is correct)
简介
我正在将游戏坐标转换为地图坐标,我设置了自定义图块并且地图有效。
我在传单地图上显示玩家车辆(与 mapbox 相同的问题),x 轴的坐标转换是正确的(视觉上)但 y 轴(纬度)不正确。
我试过的
我正在尝试将 3000 到 -3000 在 X 和 3000 上的游戏坐标转换为 - 3000 在 Y
我认为地图坐标在 X - Longitude 上从 180 到 -180
85 到 -85 在 Y - Latitude
Currently I am using this formula to calculate its coordinates on map, But I cant figure out what I'm doing wrong here.
I put u
dynamic so i can easily test it..
Notice that return value has x and y inverted because that is just how leaflet is...
function getLatLngFromPos(x, y, u = 85) {
height = 3000; // of the game map
width = 3000; // of the game map
return [(y / height) * u, (x / width) * 180];
}
结果(~表示不是计算而是目测):
getLatLngFromPos(1482.47 , -1731.9)
-> [-49.0705, 88.9482]
应该是:~[-71.519235, 88.813477]
getLatLngFromPos(1378.4,-1876.25)
-> [-53.16041666666666,82.70400000000001]
应该是:~[-73.758964, 81.958008]
如果你需要瓷砖,这里是代码
http://145.239.116.170/app-assets/images/maptiles/sanandreas.{z}.{x}.{y}.png
Note: MaxZoom is '4'
结果
不正确的结果:
地图上的汽车图标应该去箭头方向,还有地图中心等额外信息。 (它还在我想删除的 X 轴上重复)
截图:
(https://i.ibb.co/HNHgRLC/Shared-Screenshot.jpg)
假设
我认为这些地图上的 Y 轴有某种朝向边缘的加速度...这是由于 Leaflet 的默认投影
Google Maps API 在 (https://github.com/ikkentim/SanMap/blob/master/js_src/js/SanMap.js) 也有一个实现,但是 Google Maps 正在通过收费来冲洗...
我现在假设我必须像在 SanMap 实现中那样创建某种投影,我如何为 Mapbox 或 Leaflet 创建我自己的投影?
我正在处理同样的问题,这还不是解决方案,但它可能会让您走上正轨。我尝试的是使用 CRS 而不是传单类地球投影。只需更改 tileLayer 中的 w、h 和 tileSize 即可。 0,0 也将在左上角。
好的,我已经用我的方法找到了解决方案。由于图块大小为 256,因此我们的地图大小为 256x256。游戏中的坐标从 -3000,-3000 到 3000,3000,这使它成为一个 6000x6000 坐标系。您可以通过将地图的大小除以我们拥有的图块大小来获得比例,然后将 x 除以比例。我们通过对 x 加 128 并从 y 减去 -128 来校正坐标。之后我们在 return 时切换坐标。
function fixCoords(x,y) {
x=x/(6000/256);
y=y/(6000/256);
x = x+128;
y = y-128;
return [y,x];
}
var w = 32768;
var h = 32768;
var mapMinZoom = 1;
var mapMaxZoom = 4;
var _map = L.map('mapid', {
maxZoom: mapMaxZoom,
minZoom: mapMinZoom,
crs: L.CRS.Simple,
zoomControl: false,
attributionControl: false,
detectRetina: true,
});
var _mapCenter = _map.unproject([w/2, h/2], mapMaxZoom);
_map.setView(_mapCenter, 2);
var _tileLayer = L.tileLayer(
'http://145.239.116.170/app-assets/images/maptiles/sanandreas.{z}.{x}.{y}.png', {
minZoom: mapMinZoom, maxZoom: mapMaxZoom,
bounds: _mapBounds,
continuousWorld: true,
noWrap:true,
tileSize:256,
crs: L.CRS.Simple,
detectRetina:false,
}).addTo(_map);
var marker = L.marker([0, 0]).addTo(_map);
简介
我正在将游戏坐标转换为地图坐标,我设置了自定义图块并且地图有效。
我在传单地图上显示玩家车辆(与 mapbox 相同的问题),x 轴的坐标转换是正确的(视觉上)但 y 轴(纬度)不正确。
我试过的
我正在尝试将 3000 到 -3000 在 X 和 3000 上的游戏坐标转换为 - 3000 在 Y 我认为地图坐标在 X - Longitude 上从 180 到 -180 85 到 -85 在 Y - Latitude
Currently I am using this formula to calculate its coordinates on map, But I cant figure out what I'm doing wrong here.
I put
u
dynamic so i can easily test it..Notice that return value has x and y inverted because that is just how leaflet is...
function getLatLngFromPos(x, y, u = 85) {
height = 3000; // of the game map
width = 3000; // of the game map
return [(y / height) * u, (x / width) * 180];
}
结果(~表示不是计算而是目测):
getLatLngFromPos(1482.47 , -1731.9)
-> [-49.0705, 88.9482] 应该是:~[-71.519235, 88.813477]
getLatLngFromPos(1378.4,-1876.25)
-> [-53.16041666666666,82.70400000000001] 应该是:~[-73.758964, 81.958008]
如果你需要瓷砖,这里是代码
http://145.239.116.170/app-assets/images/maptiles/sanandreas.{z}.{x}.{y}.png
Note: MaxZoom is '4'
结果
不正确的结果:
地图上的汽车图标应该去箭头方向,还有地图中心等额外信息。 (它还在我想删除的 X 轴上重复)
截图: (https://i.ibb.co/HNHgRLC/Shared-Screenshot.jpg)
假设
我认为这些地图上的 Y 轴有某种朝向边缘的加速度...这是由于 Leaflet 的默认投影 Google Maps API 在 (https://github.com/ikkentim/SanMap/blob/master/js_src/js/SanMap.js) 也有一个实现,但是 Google Maps 正在通过收费来冲洗...
我现在假设我必须像在 SanMap 实现中那样创建某种投影,我如何为 Mapbox 或 Leaflet 创建我自己的投影?
我正在处理同样的问题,这还不是解决方案,但它可能会让您走上正轨。我尝试的是使用 CRS 而不是传单类地球投影。只需更改 tileLayer 中的 w、h 和 tileSize 即可。 0,0 也将在左上角。
好的,我已经用我的方法找到了解决方案。由于图块大小为 256,因此我们的地图大小为 256x256。游戏中的坐标从 -3000,-3000 到 3000,3000,这使它成为一个 6000x6000 坐标系。您可以通过将地图的大小除以我们拥有的图块大小来获得比例,然后将 x 除以比例。我们通过对 x 加 128 并从 y 减去 -128 来校正坐标。之后我们在 return 时切换坐标。
function fixCoords(x,y) {
x=x/(6000/256);
y=y/(6000/256);
x = x+128;
y = y-128;
return [y,x];
}
var w = 32768;
var h = 32768;
var mapMinZoom = 1;
var mapMaxZoom = 4;
var _map = L.map('mapid', {
maxZoom: mapMaxZoom,
minZoom: mapMinZoom,
crs: L.CRS.Simple,
zoomControl: false,
attributionControl: false,
detectRetina: true,
});
var _mapCenter = _map.unproject([w/2, h/2], mapMaxZoom);
_map.setView(_mapCenter, 2);
var _tileLayer = L.tileLayer(
'http://145.239.116.170/app-assets/images/maptiles/sanandreas.{z}.{x}.{y}.png', {
minZoom: mapMinZoom, maxZoom: mapMaxZoom,
bounds: _mapBounds,
continuousWorld: true,
noWrap:true,
tileSize:256,
crs: L.CRS.Simple,
detectRetina:false,
}).addTo(_map);
var marker = L.marker([0, 0]).addTo(_map);