[proj4js] problem converting from openlayers lon/lat values

2 messages Options
Embed this post
Permalink
piko

[proj4js] problem converting from openlayers lon/lat values

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
                }
            });
               
support.mn

Re: [proj4js] problem converting from openlayers lon/lat values

Reply Threaded More More options
Print post
Permalink
piko [[hidden email]] kirjoitti:

>
> It seems very strange to me and i cannot solve as my javascript
> skills are quiet limited.
>
> Nick bozon
>
> if (evt.feature.attributes._index == 1) {
> // here i get the not expected EPSG:4326 values in my alert
> }
> else{
> //here i get the right EPSG:27563 values
> }

The reason must be that the if-expression you have is controlling
the flow of the program? It is not 1 when you get expected values
and 1 when it does not happen. Check your coding.

Janne. / MNS Support

_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj