The answer to this question is actually a little more difficult than
it would seem because a polyline is a two-dimensional object. In
other words, the distance between the two lines will depend on which
two points along each respective line you want to measure from and
to. For instance, if I have two lines that run parallel to each other
at a staggered interval, if I measure from the far end of one to the
far end of the other, I will end up with a significantly greater
distance than if I measure from the near one of the one to the near
end of the other. That said, here's how you measure distance from one
arbitrary vertex of the first polyline to another arbitrary vertex of
a second polyline (the code can be looped over to measure the distance
to additional polylines.
var
distInMeters=polylineA.getVertex(VERTEXA_INDEX).getDistance(polylineB.getVertex(VERTEXB_INDEX));
Or, in a function format (i.e., for repeated use):
function getDistBetweenPolylines(polylineA,vertexA,polylineB,vertexB){
return
polylineA.getVertex(vertexA).getDistance(polylineB.getVertex(vertexB);
}
var
distInMeters=getDistBetweenPolylines(polylineA,vertexA,polylineB,vertexB);
Please note that this will return the distance in meters. From there,
you will have to divide by the appropriate denominator to get the unit
you want. For instance, to measure in kilometers, you would divide by
1000; in miles, you would divide by 1609.344.
Jeremy R. Geerdes
Effective website design & development
Des Moines, IA
For more information or a project quote:
http://jgeerdes.home.mchsi.com
jgee...@mchsi.com
If you're in the Des Moines, IA, area, check out Debra Heights
Wesleyan Church!