mirror of
https://github.com/xivapi/ffxiv-datamining.git
synced 2026-07-29 21:19:10 +00:00
Update map_coordinates.md
This commit is contained in:
+43
-15
@@ -28,14 +28,26 @@ private double ToMapCoordinate(double val) {
|
|||||||
You can translate the `levels.exd` values to Long/Lat using the `x`, `y` and **scale** would be the maps [size_factor](https://github.com/viion/XIV-Datamining/blob/master/offsets/3.1_list.txt#L679)
|
You can translate the `levels.exd` values to Long/Lat using the `x`, `y` and **scale** would be the maps [size_factor](https://github.com/viion/XIV-Datamining/blob/master/offsets/3.1_list.txt#L679)
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
//
|
||||||
|
// Used due to spherical maps, world is round irl :P
|
||||||
|
//
|
||||||
function mapsRadiansToDegrees($rad)
|
function mapsRadiansToDegrees($rad)
|
||||||
{
|
{
|
||||||
return $rad / (pi() / 180);
|
return $rad / (pi() / 180);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapsTranslateXYZtoLatLong($x, $y, $scale = 100)
|
//
|
||||||
|
// This code will take the X, Y and map scale from the levels CSV and convert it into a LAT/LONG
|
||||||
|
// which can be used on leaflet or Google maps or just about any map tool
|
||||||
|
//
|
||||||
|
public function mapsTranslateXYZtoLatLong($x, $y, $scale = 100)
|
||||||
{
|
{
|
||||||
|
if ($x == 0 || $y == 0 || $scale == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$scale = $scale / 100;
|
$scale = $scale / 100;
|
||||||
|
|
||||||
$tilesize = 2048 / $scale;
|
$tilesize = 2048 / $scale;
|
||||||
|
|
||||||
$pixelsPerLonDegree = $tilesize / 360;
|
$pixelsPerLonDegree = $tilesize / 360;
|
||||||
@@ -43,26 +55,38 @@ function mapsTranslateXYZtoLatLong($x, $y, $scale = 100)
|
|||||||
|
|
||||||
$lng = $x / $pixelsPerLonDegree;
|
$lng = $x / $pixelsPerLonDegree;
|
||||||
$latRadians = $y / -$pixelsPerLonRadian;
|
$latRadians = $y / -$pixelsPerLonRadian;
|
||||||
$lat = mapsRadiansToDegrees(2 * atan(exp($latRadians)) - pi() / 2);
|
$lat = $this->mapsRadiansToDegrees(2 * atan(exp($latRadians)) - pi() / 2);
|
||||||
|
|
||||||
return [
|
$coords = [
|
||||||
'x' => $lng,
|
'x' => $lng,
|
||||||
'y' => $lat,
|
'y' => $lat,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return $coords;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
To translate a `levels.exd` position to an in-game X/Y:
|
To translate a `levels.exd` position to an in-game X/Y:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
function mapsTranslateXYZToGame($x, $y, $scale, $tilescale = 50)
|
//
|
||||||
|
// This takes the X/Y, scale and tilescale from levels and converts it to
|
||||||
|
// and in-game X/Y position, I have not found tile scale in the files
|
||||||
|
// and it's never not been 50 (50px per tile), its not 100% accurate,
|
||||||
|
// tilescale is actually something like 49.951219... (2048/41)
|
||||||
|
//
|
||||||
|
public function mapsTranslateXYZToGame($x, $y, $scale, $tilescale = 50)
|
||||||
{
|
{
|
||||||
|
if ($x == 0 || $y == 0 || $scale == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$map = 2048 / ($scale / 100);
|
$map = 2048 / ($scale / 100);
|
||||||
|
|
||||||
$TileCount = $map / $tilescale;
|
$tilecount = $map / $tilescale;
|
||||||
|
|
||||||
$x = ceil(round(($x / $tilescale) + ($TileCount / 2),1));
|
$x = ceil(round(($x / $tilescale) + ($tilecount / 2),1));
|
||||||
$y = ceil(round(($y / $tilescale) + ($TileCount / 2),1));
|
$y = ceil(round(($y / $tilescale) + ($tilecount / 2),1));
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'x' => $x,
|
'x' => $x,
|
||||||
@@ -74,16 +98,20 @@ function mapsTranslateXYZToGame($x, $y, $scale, $tilescale = 50)
|
|||||||
And finally, to translate an in game X/Y to a `levels.exd` position which can then be converted to a 2D or Long/Lat:
|
And finally, to translate an in game X/Y to a `levels.exd` position which can then be converted to a 2D or Long/Lat:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
function mapsTranslateGameToXYZ($x, $y, $scale)
|
//
|
||||||
|
// Translates a X/Y from in-game to a levels output (which can then be translate dto lat/long
|
||||||
|
// this is quite accurate, not found it to be off at all. Requires map scale
|
||||||
|
//
|
||||||
|
public function mapsTranslateGameToXYZ($x, $y, $scale)
|
||||||
{
|
{
|
||||||
$scale = $scale / 100;
|
$scale = $scale / 100;
|
||||||
|
|
||||||
$x = ($x*50)-25-(1024 / $scale);
|
$x = ($x*50)-25-(1024 / $scale);
|
||||||
$y = ($y*50)-25-(1024 / $scale);
|
$y = ($y*50)-25-(1024 / $scale);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'x' => $x,
|
'x' => $x,
|
||||||
'y' => $y,
|
'y' => $y,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user