Changes between Version 2 and Version 3 of Documentation/Dev/proj4js

Show
Ignore:
Timestamp:
03/03/09 11:42:01 (4 years ago)
Author:
openlayers
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Dev/proj4js

    v2 v3  
    107107}}} 
    108108 
     109== Measure control == 
     110If you add a measure control to your map (or both of them: length and area), the results are given in the map's projection, I think. So, if you have a different DisplayProjection that will lead to strange results. You will have to transform the event's geometry and call getArea and getLength on the transformed geometry. Then the units may not match the answers (m vs km, for instance), so you need to modify the values yourself (code adapted from the OpenLayers example): 
     111{{{ 
     112  function handleMeasurements(event) { 
     113    var geometry = event.geometry.transform(new OpenLayers.Projection('EPSG:900913'), new OpenLayers.Projection('EPSG:28993')); 
     114    var units = event.units; 
     115    var order = event.order; 
     116    var element = document.getElementById('measurement'); 
     117    var out = ""; 
     118    // because of the transformation units no longer matches the outcome of getArea and getLength, those are in layer units. 
     119    if(order == 1) { 
     120      if (units=='km'){ 
     121        out += "Distance: " + (geometry.getLength()/1000).toFixed(0) + " km"; 
     122      }else{ 
     123        out += "Distance: " + geometry.getLength().toFixed(0) + " m"; 
     124      } 
     125    } else { 
     126      if (units=='km'){ 
     127         out += "Area: " + (geometry.getArea()/1000000).toFixed(0) + " km<sup>2</sup>"; 
     128      }else{ 
     129         out += "Area: " + geometry.getArea().toFixed(0) + " m<sup>2</sup>"; 
     130      } 
     131    } 
     132    element.innerHTML = out; 
     133  } 
     134}}} 
     135  
     136