Files
openlayers/tests/Format/EncodedPolyline.html
Tobias Bieniek aedafc0336 EncodedPolyline: Added geometryType attribute
This makes it possible to read polygons or multipoints too. Since the
encoded format is just a list of points the reader needs to be told what
Feature to create from the encoded list.

The example code is edited to reflect that API extension.
2012-12-27 23:09:08 +01:00

71 lines
2.2 KiB
HTML

<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var points = [
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 linestring = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LineString(points)
);
var multipoint = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.MultiPoint(points)
);
var linearring = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LinearRing(points)
);
var polygon = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing(points)
])
);
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(4);
var format = new OpenLayers.Format.EncodedPolyline();
t.ok(linestring.geometry.equals(format.read(encoded).geometry),
"format correctly reads encoded polyline");
format = new OpenLayers.Format.EncodedPolyline({
geometryType: "multipoint"
});
t.ok(multipoint.geometry.equals(format.read(encoded).geometry),
"format correctly reads encoded multipoint");
format.geometryType = "linearring";
t.ok(linearring.geometry.equals(format.read(encoded).geometry),
"format correctly reads encoded linearring");
format.geometryType = "polygon";
t.ok(polygon.geometry.equals(format.read(encoded).geometry),
"format correctly reads encoded polygon");
}
</script>
</head>
<body>
</body>
</html>