Pregunta

Hola estoy teniendo un problema usando la biblioteca proj4js. Aquí está mi fuente:

<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>

No entiendo por qué la reproyección sólo funciona cuando hago clic en el botón dos veces, cuando hago clic en él por primera vez, se devuelven los mismos valores. Parece que sólo funcionan cuando haga clic en el botón dos veces o más. Aquí es esta página en línea: clic

¿Fue útil?

Solución

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

para aquí:

...

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

    function go()
{
...  

Y por alguna razón ahora funciona ...

Otros consejos

Me Couln't llegar a la página de carga, pero se trata de un problema de actualización? Es decir. Puede que explícitamente causa de las etiquetas de entrada y xNew yNew para refrescarse inmediatamente después se fijan sus valores?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top