From 8651e05e75468db6f36a3810da23ef2ef18951e1 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 27 Dec 2012 23:19:44 +0100 Subject: [PATCH] EncodedPolyline: Allow setting geometryType to "point --- lib/OpenLayers/Format/EncodedPolyline.js | 10 ++++++++-- tests/Format/EncodedPolyline.html | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Format/EncodedPolyline.js b/lib/OpenLayers/Format/EncodedPolyline.js index 5c7b68c221..289c2aa8ef 100644 --- a/lib/OpenLayers/Format/EncodedPolyline.js +++ b/lib/OpenLayers/Format/EncodedPolyline.js @@ -21,7 +21,8 @@ OpenLayers.Format.EncodedPolyline = OpenLayers.Class(OpenLayers.Format, { /** * APIProperty: geometryType * {String} Geometry type to output. One of: linestring (default), - * linearring, multipoint or polygon + * linearring, point, multipoint or polygon. If the geometryType is + * point, only the first point of the string is returned. */ geometryType: "linestring", @@ -58,7 +59,7 @@ OpenLayers.Format.EncodedPolyline = OpenLayers.Class(OpenLayers.Format, { geomType = OpenLayers.Geometry.LinearRing; else if (this.geometryType == "multipoint") geomType = OpenLayers.Geometry.MultiPoint; - else if (this.geometryType != "polygon") + else if (this.geometryType != "point" && this.geometryType != "polygon") return null; var points = this.decode(encoded, 2); @@ -70,6 +71,11 @@ OpenLayers.Format.EncodedPolyline = OpenLayers.Class(OpenLayers.Format, { ); } + if (this.geometryType == "point") + return new OpenLayers.Feature.Vector( + pointGeometries[0] + ); + if (this.geometryType == "polygon") return new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Polygon([ diff --git a/tests/Format/EncodedPolyline.html b/tests/Format/EncodedPolyline.html index 9ad7dbd726..b1692ba848 100644 --- a/tests/Format/EncodedPolyline.html +++ b/tests/Format/EncodedPolyline.html @@ -51,7 +51,7 @@ } function test_Format_EncodedPolyline_read(t) { - t.plan(4); + t.plan(5); var format = new OpenLayers.Format.EncodedPolyline(); @@ -71,6 +71,10 @@ format.geometryType = "polygon"; t.ok(polygon.geometry.equals(format.read(encoded).geometry), "format correctly reads encoded polygon"); + + format.geometryType = "point"; + t.ok(points[0].equals(format.read(encoded).geometry), + "format correctly reads encoded point"); } function test_Format_EncodedPolyline_decode(t) {