OpenLayers OpenLayers

Changeset 7970

Show
Ignore:
Timestamp:
09/06/08 12:09:13 (3 months ago)
Author:
crschmidt
Message:

Measure includes a great circle distance, to emonstrate the ability to use
the geometry attached to the event to generate your own length measurement.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/measure.html

    r7965 r7970  
    9393            document.getElementById('noneToggle').checked = true; 
    9494        } 
     95 
     96        function calcVincenty(geometry) { 
     97            var dist = 0; 
     98            for (var i = 1; i < geometry.components.length; i++) { 
     99                var first = geometry.components[i-1]; 
     100                var second = geometry.components[i]; 
     101                dist += OpenLayers.Util.distVincenty( 
     102                   new OpenLayers.LonLat(first.x, first.y),  
     103                   new OpenLayers.LonLat(second.x, second.y) 
     104                ); 
     105            } 
     106            return dist; 
     107        }     
    95108         
    96109        function handleMeasurements(event) { 
     
    103116            if(order == 1) { 
    104117                out += "measure: " + measure.toFixed(3) + " " + units; 
     118                if (map.getProjection() == "EPSG:4326") { 
     119                    out += "<br /> Great Circle Distance: " +  
     120                        calcVincenty(geometry).toFixed(3) + " km";  
     121                }         
    105122            } else { 
    106123                out += "measure: " + measure.toFixed(3) + " " + units + "<sup>2</" + "sup>";