传单上的标记坐标不正确



我正在使用名为Exile的mod创建一个名为ArmA3的游戏的管理员/用户控制面板。Exile在数据库中放置X、Y(Z(坐标。我使用PHP来获取这些坐标,并使用leaflet.js在玩家所在的位置放置标记。我使用的是自定义图像(15360x15360(。

问题:假设我在位置(63407801((x,y(。标记将离开我实际所在的位置(见下面的imgurs(

(ingame位置(https://i.stack.imgur.com/3FWyD.jpg

(传单标记(https://i.stack.imgur.com/Zf4SL.jpg

PHP代码+leaflet.js:

<?php
require_once "application.php";
?>
<html lang="en">
<head>
<title>Search</title>
<link rel="stylesheet" href="leaflet.css">
<meta charset="UTF-8">
</head>
<body>
<?php
if(isset($_GET["q"])) {
$uid = $_GET["q"];
$UCP = new UCP("localhost", "root", "root", "testdb", "3306");
$r = $UCP->getPlayer($uid);
if($r) {
$coords = $UCP->getPlayerCoords($uid);
}
}
?>
<div id="map" style="height: 100%"></div>
<script src="js/leaflet.js"></script>
<script>
var mapMinZoom = 0;
var mapMaxZoom = 4;
var map = L.map('map', {
minZoom: mapMinZoom,
maxZoom: mapMaxZoom,
center: [15360, 15360],
crs: L.CRS.Simple
});
var w = 15360,
h = 15360,
url = 'http://localhost/images/Chernarus_Isles_nogrid.png';
var southWest = map.unproject([0, h], mapMaxZoom);
var northEast = map.unproject([w, 0], mapMaxZoom);
var bounds = new L.LatLngBounds(southWest, northEast);
map.fitBounds(bounds);
L.imageOverlay(url, bounds).addTo(map);
<?php
if(isset($_GET["q"])) {
if($r) { ?>
var pos_x_player = Math.round(<?php echo $coords["pos_x"]; ?>);
var pos_y_player = Math.round(<?php echo $coords["pos_y"]; ?>);
var p_loc = map.unproject([pos_y_player, pos_x_player], mapMaxZoom);
L.marker(p_loc).addTo(map).bindPopup('Player Location');
<?php
}
}
?>
</script>

它成功地连接到数据库并获取坐标,但传单总是离我实际所在的地方不远。

如有任何帮助,我们将不胜感激。如果我错过了什么,请告诉我:(

欢迎来到SO!

传单地图的unproject第一个参数是Point对象,它按照[horizontal, vertical]:的顺序获取坐标

https://leafletjs.com/reference-1.3.4.html#point-工厂

需要形式为[x, y]的数组

因此,标记的错误位置很可能只是因为您以错误的顺序通过了坐标:

map.unproject([pos_y_player, pos_x_player], mapMaxZoom)

应该是:

map.unproject([pos_x_player, pos_y_player], mapMaxZoom)

点对象是以像素为单位测量的,所以是的,在这种情况下,源图像和您的图像必须相同才能获得精确的坐标,而无需修改。一旦确定了大小的差异,就可以制作一个函数,将原始坐标转换为地图的坐标。

最新更新