Changes between Version 3 and Version 4 of UserGuide


Ignore:
Timestamp:
Jul 10, 2008, 12:52:21 PM (16 years ago)
Author:
madair
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UserGuide

    v3 v4  
    1 === User Guide ===
     1= User Guide =
    22
    3 Using Proj4js is a matter of including the library in your page, creating source and destination Proj objects, transforming point coordinates. 
     3Using Proj4js is a matter of:
     4 1. including the library in your page
     5 1. creating source and destination Proj4js objects
     6 1. transforming point coordinates. 
    47
    58{{{
     9// include the library
     10<script src="lib/proj4js-combined.js"></script>  //adjust the path for your server
     11                                                 //or else use the compressed version
    612
    7 <script src="lib/proj4js-combined.js"></script>  //adjust the path for your server
     13. . .
    814
    9 
    10 //somewhere in your JavaScript code where you need this
    11 
     15// creating source and destination Proj4js objects
     16// once initialized, these may be re-used as often as needed
    1217var source = new Proj4js.Proj(‘EPSG:4236’);    //source coordinates will be in Longitude/Latitude
    1318var dest = new Proj4js.Proj(‘EPSG:27563’);     //destination coordinates in LCC, south of France
    1419
     20. . .
     21
     22// transforming point coordinates
    1523var p = new Proj4js.Point(-76.0,45.0);   //any object will do as long as it has 'x' and 'y' properties
    1624Proj4js.transform(source, dest, p);      //do the transformation.  x and y are modified in place
    1725
    1826//p.x and p.y are now EPSG:27563 easting and northing in meters
    19 
     27. . .
     28}}}
    2029
    21 }}}
     30'''Note:''' Proj4js currently depends on some core [http://openlayers.org/ OpenLayers] classes which are compiled into the file OLprotoype.js.  If you are using Proj4js in a page that already includes the OpenLayers library, there is no need to include this file, otherwise you must also include OLprototype in a <script> tag.  The development plan for Proj4js is to factor out this requirement so that the OpenLayers classes will only be required for dynamic lookup of the CRS definitions (see below).
    2231
    2332== Proj4js.Proj constructor ==
    2433
    25 Every Proj object must be initialized with the parameters of the CRS to be used.  The argument to the constructor is a key in the Proj4js.defs initialization parameters object.
     34Every Proj4js.Proj object must be initialized with the parameters of the CRS to be used.  The argument to the constructor is a key in the Proj4js.defs object.
    2635
    2736
     
    3140}}}
    3241
    33 Proj4js uses the same initialization parameters that PROJ4 uses [link] and these values must be defined before the constructor is called.
     42Proj4js uses the same initialization parameters that [wiki:proj] uses and these values must be defined before the constructor is called.
    3443
    3544== If you know the projections to be used in your application ==
     
    4352== Dynamic lookup of initialization parameters ==
    4453
    45 set libPath
    46 set proxy
    47 spatialreference.org
     54If you don't know the CRS's to be used by the application, Proj4js can dynamically look up the initialization parameters at run-time.  By default, it will use the REST web service at [http://spatialreference.org spatialreference.org] as the lookup service.
     55
     56To use Proj4js in this way, you will need to:
     57 1. include the OLprotoype.js file in a script tag (only if your page doesn't already include OpenLayers)
     58 1. define a proxy script to allow cross domain HTTP requests
     59 1. define the value for the /lib path
     60
     61The way dynamic definition string lookup works is to first check for the definition at the path lib/defs.  If the appropriate file is found there, it will be loaded and used by Proj4js.  If it is not found there ('''note:''' in this case it is normal to see an error in the Firebug console), an HTTP request will be issued to spatialreference.org