准确的JS库将lat-lon转换为像素(离线)

时间:2015-04-04 01:53:03

标签: javascript gis

我尝试将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>

但我没有得到准确的价值;如果我测试一下:

enter image description here

我明白了:

enter image description here

正如你所看到的那样,标记(我用一个简单的数字)就出来了。

更新:顺便说一下,我使用MOBAC来获得更多的极端点(图像只是说明性的,因为这一点,我得到了最高变焦以获得良好的精度)

enter image description here

0 个答案:

没有答案