wiki:UserGuide

Version 3 (modified by madair, 16 years ago) ( diff )

--

User Guide

Using Proj4js is a matter of including the library in your page, creating source and destination Proj objects, transforming point coordinates.

<script src="lib/proj4js-combined.js"></script>  //adjust the path for your server

…
//somewhere in your JavaScript code where you need this

var source = new Proj4js.Proj(‘EPSG:4236’);    //source coordinates will be in Longitude/Latitude
var dest = new Proj4js.Proj(‘EPSG:27563’);     //destination coordinates in LCC, south of France

var p = new Proj4js.Point(-76.0,45.0);   //any object will do as long as it has 'x' and 'y' properties
Proj4js.transform(source, dest, p);      //do the transformation.  x and y are modified in place

//p.x and p.y are now EPSG:27563 easting and northing in meters
…

Proj4js.Proj constructor

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.

Proj4js.defs["EPSG:27563"]="+title=LAMB sud france  +proj=lcc +lat_1=44.1 +lat_0=44.1 +lon_0=0 +k_0=0.999877499 
                            +x_0=600000 +y_0=200000 +a=6378249.2 +b=6356515 +towgs84=-168,-60,320,0,0,0,0 +pm=paris +units=m";

Proj4js uses the same initialization parameters that PROJ4 uses [link] and these values must be defined before the constructor is called.

If you know the projections to be used in your application

You can define these via the script tag (see examples in the lib/defs directory) or anywhere else in your application.

<script src="lib/defs/EPSG27563.js"></script >

Dynamic lookup of initialization parameters

set libPath set proxy spatialreference.org

Note: See TracWiki for help on using the wiki.