gpt4 book ai didi

javascript proj4js问题

转载 作者:行者123 更新时间:2023-11-29 20:20:47 25 4
gpt4 key购买 nike

您好,我在使用 proj4js 库时遇到问题。这是我的来源:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="lib/proj4js-combined.js"></script>
</head>

<script type="text/javascript">
function go()
{
var lon = document.getElementById("xOrg").value;
var lat = document.getElementById("yOrg").value;
var reprojected = reproject(Number(lon),Number(lat));

document.getElementById("xNew").value = reprojected.x;
document.getElementById("yNew").value = reprojected.y;
}

function reproject(lon,lat)
{
var sourceSys = new Proj4js.Proj('WGS84');
var destSys = new Proj4js.Proj('EPSG:32187');

var pointSource = new Proj4js.Point(lon,lat);
var pointDest = Proj4js.transform(sourceSys, destSys, pointSource);

return pointDest;
}
</script>

<body>
<div>
<input id="xOrg" type="text" value="-73.56"/>
<input id="yOrg" type="text" value="45.49"/>
</div>
<div>
<input id="xNew" type="text" value=""/>
<input id="yNew" type="text" value=""/>
</div>
<div>
<input type="button" value="go" onclick="go()"/>
</div>
</body>
</html>

我不明白为什么只有当我点击按钮两次时重投影才有效,当我第一次点击它时,返回相同的值。它似乎只有在我点击按钮两次或更多时才有效。这是在线页面: click

最佳答案

var sourceSys = new Proj4js.Proj('WGS84'); 
var destSys = new Proj4js.Proj('EPSG:32187');

到这里:

...

<script type="text/javascript">
var sourceSys = new Proj4js.Proj('WGS84');
var destSys = new Proj4js.Proj('EPSG:32187');

function go()
{
...

无论出于何种原因,它现在都有效...

关于javascript proj4js问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4037054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com