我尝试将lat-lon值转换为像素I tried this excellent example,此处为解决方案(转换为JS):
<div id="dz" style="background-image: url('algerie.png');height: 558px;width: 571px;background-size: contain;background-repeat: no-repeat;">
<p id="hey">0</p>
</div>
<script>
function placeDiv(x_pos, y_pos) {
var d = document.getElementById('hey');
d.style.position = "absolute";
d.style.left = x_pos+'px';
d.style.top = y_pos+'px';
}
var mapWidth = 571;
var mapHeight = 558;
var mapLonLeft = -8.66884;
var mapLonRight = 11.99733;
var mapLonDelta = mapLonRight - mapLonLeft;
var mapLatBottom = 18.96815;
var mapLatBottomDegree =mapLatBottom * Math.PI / 180;
function convertGeoToPixel(lat, lon)
{
x = (lon - mapLonLeft) * (mapWidth / mapLonDelta);
lat = lat * Math.PI / 180;
worldMapWidth = ((mapWidth / mapLonDelta) * 360) / (2 * Math.PI);
mapOffsetY = (worldMapWidth / 2 * Math.log((1 + Math.sin(mapLatBottomDegree)) / (1 - Math.sin(mapLatBottomDegree))));
y = mapHeight - ((worldMapWidth / 2 * Math.log((1 + Math.sin(lat)) / (1 - Math.sin(lat)))) - mapOffsetY);
return placeDiv(x, y);
}
</script>
但我没有得到准确的价值;如果我测试一下:
我明白了:
正如你所看到的那样,标记(我用一个简单的数字)就出来了。
更新:顺便说一下,我使用MOBAC来获得更多的极端点(图像只是说明性的,因为这一点,我得到了最高变焦以获得良好的精度)