EncodedPolyline: Allow setting geometryType to "point
This commit is contained in:
@@ -21,7 +21,8 @@ OpenLayers.Format.EncodedPolyline = OpenLayers.Class(OpenLayers.Format, {
|
|||||||
/**
|
/**
|
||||||
* APIProperty: geometryType
|
* APIProperty: geometryType
|
||||||
* {String} Geometry type to output. One of: linestring (default),
|
* {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",
|
geometryType: "linestring",
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ OpenLayers.Format.EncodedPolyline = OpenLayers.Class(OpenLayers.Format, {
|
|||||||
geomType = OpenLayers.Geometry.LinearRing;
|
geomType = OpenLayers.Geometry.LinearRing;
|
||||||
else if (this.geometryType == "multipoint")
|
else if (this.geometryType == "multipoint")
|
||||||
geomType = OpenLayers.Geometry.MultiPoint;
|
geomType = OpenLayers.Geometry.MultiPoint;
|
||||||
else if (this.geometryType != "polygon")
|
else if (this.geometryType != "point" && this.geometryType != "polygon")
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var points = this.decode(encoded, 2);
|
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")
|
if (this.geometryType == "polygon")
|
||||||
return new OpenLayers.Feature.Vector(
|
return new OpenLayers.Feature.Vector(
|
||||||
new OpenLayers.Geometry.Polygon([
|
new OpenLayers.Geometry.Polygon([
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Format_EncodedPolyline_read(t) {
|
function test_Format_EncodedPolyline_read(t) {
|
||||||
t.plan(4);
|
t.plan(5);
|
||||||
|
|
||||||
var format = new OpenLayers.Format.EncodedPolyline();
|
var format = new OpenLayers.Format.EncodedPolyline();
|
||||||
|
|
||||||
@@ -71,6 +71,10 @@
|
|||||||
format.geometryType = "polygon";
|
format.geometryType = "polygon";
|
||||||
t.ok(polygon.geometry.equals(format.read(encoded).geometry),
|
t.ok(polygon.geometry.equals(format.read(encoded).geometry),
|
||||||
"format correctly reads encoded polygon");
|
"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) {
|
function test_Format_EncodedPolyline_decode(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user