Proj4js - Problem to convert point values from OpenLayers

1 message Options
Embed this post
Permalink
piko

Proj4js - Problem to convert point values from OpenLayers

Reply Threaded More More options
Print post
Permalink
Hi list
I'm new to this list and hope that some one can help me solve the following problem:

In a OpenLayers code, i developed a specific control to draw 2 points, get lon/lat values from these points and then send them to different input forms as EPSG:4326 values.

Then, for another need i have to convert those values into metric values using proj4js.js and EPSG27563.js.

It works well but the problem is that on the first created point i only get 4326 values, and then 27563 values for the second point. It seems very strange to me and i cannot solve as my javascript skills are quiet limited.

Many thanks by advance for any hits on this problem

Nick bozon

code:

var onTrigPt = function() {
  if (!this.control) {
        driftxControl.events.register('featureadded',
            pointLayer,
            function(evt){
              var geometry = evt.feature.geometry;
                var lonlat = map.getLonLatFromViewPortPx(geometry);
                var arrondzXPt = Math.round(lonlat.lon*1000) / 1000;
                var arrondzYPt = Math.round(lonlat.lat*1000) / 1000;
                var point = new Proj4js.Point(arrondzXPt,arrondzYPt);
                var source = new Proj4js.Proj('EPSG:4236');    
                var dest = new Proj4js.Proj('EPSG:27563');
                var lambv= Proj4js.transform(source, dest, point);  
               
                if (evt.feature.attributes._index == 1) {
                document.forms["defineParams"].Pt1X.value = arrondzXPt;
                document.forms["defineParams"].Pt1Y.value = arrondzYPt;    
                alert(lambv);
// here i get the not expected EPSG:4326 values in my alert

                }
                else{
                document.forms["defineParams"].Pt2X.value = arrondzXPt;
                document.forms["defineParams"].Pt2Y.value = arrondzYPt;
                alert(lambv);

//here i get the right EPSG:27563 values
                }
            });