[OpenLayers-Commits] r12098 - in trunk/openlayers:
lib/OpenLayers/Format tests/Format
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Fri Jun 17 13:12:02 EDT 2011
Author: tschaub
Date: 2011-06-17 10:12:01 -0700 (Fri, 17 Jun 2011)
New Revision: 12098
Modified:
trunk/openlayers/lib/OpenLayers/Format/WKT.js
trunk/openlayers/tests/Format/WKT.html
Log:
Enhance WKT parser to parse multi-line strings. r=erilem (closes #3365)
Modified: trunk/openlayers/lib/OpenLayers/Format/WKT.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WKT.js 2011-06-17 13:16:53 UTC (rev 12097)
+++ trunk/openlayers/lib/OpenLayers/Format/WKT.js 2011-06-17 17:12:01 UTC (rev 12098)
@@ -56,6 +56,7 @@
*/
read: function(wkt) {
var features, type, str;
+ wkt = wkt.replace(/[\n\r]/g, " ");
var matches = this.regExes.typeStr.exec(wkt);
if(matches) {
type = matches[1].toLowerCase();
Modified: trunk/openlayers/tests/Format/WKT.html
===================================================================
--- trunk/openlayers/tests/Format/WKT.html 2011-06-17 13:16:53 UTC (rev 12097)
+++ trunk/openlayers/tests/Format/WKT.html 2011-06-17 17:12:01 UTC (rev 12098)
@@ -232,6 +232,16 @@
t.geom_eq(got[1].geometry, linestrings[0].geometry, "second feature's geometry is the correct linestring");
}
+
+ function test_whitespace(t) {
+ t.plan(3);
+ var wkt = "LINESTRING(7.120068\t43.583917,\n7.120154 43.583652,\n7.120385\t43.582716,\r\n7.12039 43.582568, 7.120712 43.581511,7.120873\n43.580718)";
+ var format = new OpenLayers.Format.WKT();
+ var got = format.read(wkt);
+ t.ok(got instanceof OpenLayers.Feature.Vector, "read a feature");
+ t.ok(got.geometry instanceof OpenLayers.Geometry.LineString, "read a linestring");
+ t.ok(got.geometry.components.length, 6, "read a geometry with 6 components");
+ }
function test_Format_WKT_read_projection(t) {
t.plan(1);
More information about the Commits
mailing list