[OpenLayers-Users] How to use Other Projections in a stand alone client side environment

Mike Adair madair at dmsolutions.ca
Tue Jul 20 10:31:09 EDT 2010


OpenLayers is set up to use Proj4js internally which will do the 
coordinate conversion for you on the client side.. Have a look at 
http://trac.osgeo.org/proj4js/

Mike

On 7/20/2010 9:23 AM, Subhani Minhas wrote:
> Hello All, I recently came across, the site 
> http://spatialreference.org/ref/epsg/24378/  which can show 
> coordinates of projection EPSG:24378 once we click on the map, I am 
> interested to put the same functionality on my locally hosted html 
> file and perform the coordinate calculation client side, i.e no server 
> side calculations from http://spatialreference.org   . The code 
> referred was map.js in the HTML file which is as follows:
> function init(code) {
>      m = new OpenLayers.Map('map', {'maxResolution': 360/512});
>      m.addLayer(new OpenLayers.Layer.WMS('', 'http://labs.metacarta.com/wms-c/Basic.py', {'layers':'basic'}));
>
>      m.addLayer(new OpenLayers.Layer.Markers(''));
>      m.zoomToMaxExtent();
>      m.marker = new OpenLayers.Marker(new OpenLayers.LonLat(0,0));
>      m.layers[1].addMarker(m.marker);
>      if (window.bounds) {
>
>      m.addLayer(new OpenLayers.Layer.Boxes());
>      m.layers[2].addMarker(new OpenLayers.Marker.Box(bounds));
>      }
>      m.events.register('moveend', m, function() {
>          var c = this.getCenter();
>          this.marker.moveTo(this.getLayerPxFromLonLat(c));
>
>          document.getElementById("out").innerHTML = "Waiting...";
>          document.getElementById("in").innerHTML = [c.lon,c.lat].join(", ");
>          var json = '{"type":"Feature", "geometry":{"type":"Point", "coordinates":[' + c.lon + ', '+ c.lat + ']},"properties":{}}';
>
>          var s = document.createElement("script");
>          s.src = "/projection/?json=" + escape(json) + "&inref=EPSG:4326&outref="+code+"&callback=project_out"
>          document.body.appendChild(s);
>
>      });
>      if (window.bounds) {
>          m.setCenter(bounds.getCenterLonLat());
>      } else {
>          m.zoomToMaxExtent();
>      }
> }
> function project_out(data) {
>      if (data.coordinates) {
>
>        document.getElementById("out").innerHTML = data.coordinates.join(", ");
>      } else if (data.error) {
>          if (window.console) {
>              console.log(data.error);
>          }
>          document.getElementById('out').innerHTML = 'An error occurred.';
>
>      }
> }
>
> while the html only has following script:
>
> var bounds = new OpenLayers.Bounds(70.329999999999998, 28.0, 97.450000000000003, 35.549999999999997);
>
> defining bounds of this specific projection:
>
>
> How can i use this code locally, i want to place it in e.g examples folder of OL 2.9 source, and make it work, but the projection information is missing which is as follows in WKT:
> PROJCS["Kalianpur 1975 / India zone I",
>
>      GEOGCS["Kalianpur 1975",
>          DATUM["Kalianpur_1975",
>
>              SPHEROID["Everest 1830 (1975 Definition)",6377299.151,300.8017255,
>
>                  AUTHORITY["EPSG","7045"]],
>              TOWGS84[295,736,257,0,0,0,0],
>
>              AUTHORITY["EPSG","6146"]],
>          PRIMEM["Greenwich",0,
>
>              AUTHORITY["EPSG","8901"]],
>          UNIT["degree",0.01745329251994328,
>
>              AUTHORITY["EPSG","9122"]],
>          AUTHORITY["EPSG","4146"]],
>
>      UNIT["metre",1,
>          AUTHORITY["EPSG","9001"]],
>
>      PROJECTION["Lambert_Conformal_Conic_1SP"],
>      PARAMETER["latitude_of_origin",32.5],
>
>      PARAMETER["central_meridian",68],
>      PARAMETER["scale_factor",0.99878641],
>
>      PARAMETER["false_easting",2743195.5],
>      PARAMETER["false_northing",914398.5],
>
>      AUTHORITY["EPSG","24378"],
>      AXIS["Easting",EAST],
>
>      AXIS["Northing",NORTH]]
> .
>
> Any help or source code will be highly appreciated.
>
>
>
>    
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>    

-- 
    Michael Adair
    Senior Software Architect
    DM Solutions Group Inc.

    Office: (613) 565-5056 x26
    madair at dmsolutions.ca
    http://www.dmsolutions.ca
    http://research.dmsolutions.ca


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


More information about the Users mailing list