Format: Added EncodedPolyline class
This class is able to convert an encoded polyline string into a LineString embedded in a Vector Feature. See https://developers.google.com/maps/documentation/utilities/polylinealgorithm for more information.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../OLLoader.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var linestring = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(-120.2, 38.5),
|
||||
new OpenLayers.Geometry.Point(-120.95, 40.7),
|
||||
new OpenLayers.Geometry.Point(-126.45300000000002, 43.252)
|
||||
])
|
||||
);
|
||||
|
||||
var encoded = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
|
||||
|
||||
function test_Format_EncodedPolyline_constructor(t) {
|
||||
t.plan(4);
|
||||
|
||||
var options = {'foo': 'bar'};
|
||||
var format = new OpenLayers.Format.EncodedPolyline(options);
|
||||
t.ok(format instanceof OpenLayers.Format.EncodedPolyline,
|
||||
"new OpenLayers.Format.EncodedPolyline returns object" );
|
||||
t.eq(format.foo, "bar", "constructor sets options correctly");
|
||||
t.eq(typeof format.read, "function", "format has a read function");
|
||||
t.eq(typeof format.write, "function", "format has a write function");
|
||||
}
|
||||
|
||||
function test_Format_EncodedPolyline_read(t) {
|
||||
t.plan(1);
|
||||
|
||||
var format = new OpenLayers.Format.EncodedPolyline();
|
||||
|
||||
t.ok(linestring.geometry.equals(format.read(encoded).geometry),
|
||||
"format correctly reads encoded polyline");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user