[OpenLayers-Users] OpenLayers.Projection and proj4js.js

Arnd Wippermann arnd.wippermann at web.de
Sun Jun 29 11:26:59 EDT 2008


Hi Matt,
 
you must load the proj4js library and if you use IE also the other
projection declarations. Otherwise is the OpenLayers.Projection only an
empty function.
 
I use this to work with proj4js and it's wonderful to see how it works.
 
<script type="text/javascript" src="proj4js/proj4js-compressed.js"></script>

<SCRIPT type="text/javascript" src="proj4js/projCode/tmerc.js"></SCRIPT>
<SCRIPT type="text/javascript" src="proj4js/projCode/merc.js"></SCRIPT>
<SCRIPT type="text/javascript" src="proj4js/defs/EPSG31466.js"></SCRIPT>
<SCRIPT type="text/javascript" src="proj4js/defs/EPSG31467.js"></SCRIPT>
<SCRIPT type="text/javascript" src="proj4js/defs/EPSG900913.js"></SCRIPT>


Mit freundlichen Grüssen

Arnd Wippermann
 <http://gis.ibbeck.de/ginfo/> http://gis.ibbeck.de/ginfo/




  _____  

Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von Matthew Pettis
Gesendet: Samstag, 28. Juni 2008 23:20
An: users at openlayers.org
Betreff: [OpenLayers-Users] OpenLayers.Projection and proj4js.js


Hi,

I'm trying to cast a point in one projection into another, and I think I
have some issues with OpenLayers.Projection.  Below is html/javascript code
I'm using and the rendered browser ouput.  In this example, I'm trying to
cast the point (184056.505, 4809728.250) in epsg:26915 to epgs:4326.  My
expectation is that point p, which is this point in epsg:26915, should
display as something on the order of (-100,43), or something close to that
range.  However, as the output shows, the point is not changed.  Can someone
explain why?

Thanks,
matt

P.S. - Is there an error in the documentation for the constructor of
OpenLayers.Projection (at:
http://dev.openlayers.org/releases/OpenLayers-2.6/doc/apidocs/files/OpenLaye
rs/Projection-js.html#OpenLayers.Projection.OpenLayers.Projection)?  It says
that the constructor takes an object to set parameters, but every example I
see of the constructor is passing a string in the way I am setting it here.
Am I not understanding the documentation conventions correctly, or is this
not correctly or completely documented?


=== html/javascript code ===
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>OpenLayers Example</title>
<!--    <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
-->
    <script
src="http://localhost/_common//OpenLayers-2.6/OpenLayers.js"></script>
  </head>

  <body>

    <pre>
    <script type="text/javascript">
        var p = new OpenLayers.Geometry.Point(184056.505, 4809728.250);
        var proj_src = new OpenLayers.Projection("EPSG:26915");
        var proj_tgt = new OpenLayers.Projection("EPSG:4326");

        document.writeln();
        document.writeln("Point p [before OpenLayers.Projection.transform]
is: " + p);
        OpenLayers.Projection.transform(p,proj_src,proj_tgt);
        document.writeln("Point p [after OpenLayers.Projection.transform]
is: " + p);
        document.writeln("proj_src is: " + proj_src);
        document.writeln();
        
        document.writeln("prj_src walk of properties is:");
        document.writeln("------------------------------");
        for (prop in proj_src) {
            document.writeln(prop + " => " + proj_src[prop]);
        };
        document.writeln("------------------------------");
    </script>
    </pre>
  </body>

</html>
========================================================================

=== browser rendered output ===

    
Point p [before OpenLayers.Projection.transform] is: POINT(184056.505
4809728.25)
Point p [after OpenLayers.Projection.transform] is: POINT(184056.505
4809728.25)
proj_src is: EPSG:26915

prj_src walk of properties is:


------------------------------
projCode => EPSG:26915
proj => null
initialize => function (projCode, options) {
    OpenLayers.Util.extend(this, options);
    this.projCode = projCode;
    if (window.Proj4js) {


        this.proj = new Proj4js.Proj(projCode);
    }
}
getCode => function () {
    return this.proj ? this.proj.srsCode : this.projCode;
}
getUnits => function () {
    return this.proj ? this.proj.units : null;


}
toString => function () {
    return this.getCode();
}
equals => function (projection) {
    if (projection && projection.getCode) {
        return this.getCode() == projection.getCode();


    } else {
        return false;
    }
}
destroy => function () {
    delete this.proj;
    delete this.projCode;
}
CLASS_NAME => OpenLayers.Projection
------------------------------

========================================================================


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080629/d8761acf/attachment.html


More information about the Users mailing list