From b8d81e7917d1cdeda2ae2d1cf34b600de9fe9405 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sat, 21 Jun 2008 14:23:33 +0000 Subject: [PATCH] Expand on a patch by Edgemaster to support non-XML vector formats via the current XML layer. This patch rearranges the reading of the document from XML so that it is done later on, building on the work in #1575. It also adds tests for the two cases that aren't currently tested: * Vector Mode with non-XML format * non-vectormode with XML DOM passed in Tests continue to pass, confirmed via manual inspection as well as the tests. (Closes #1575) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7416 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Tile/WFS.js | 10 +++++++--- tests/Tile/WFS.html | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Tile/WFS.js b/lib/OpenLayers/Tile/WFS.js index 217ab3518f..e59e228624 100644 --- a/lib/OpenLayers/Tile/WFS.js +++ b/lib/OpenLayers/Tile/WFS.js @@ -133,13 +133,17 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, { if (this.features) { var doc = request.responseXML; if (!doc || !doc.documentElement) { - doc = OpenLayers.Format.XML.prototype.read(request.responseText); + doc = request.responseText; } if (this.layer.vectorMode) { this.layer.addFeatures(this.layer.formatObject.read(doc)); } else { - var resultFeatures = OpenLayers.Ajax.getElementsByTagNameNS( - doc, "http://www.opengis.net/gml", "gml", "featureMember" + var xml = new OpenLayers.Format.XML(); + if (typeof doc == "string") { + doc = xml.read(doc); + } + var resultFeatures = xml.getElementsByTagNameNS( + doc, "http://www.opengis.net/gml", "featureMember" ); this.addResults(resultFeatures); } diff --git a/tests/Tile/WFS.html b/tests/Tile/WFS.html index f6f7df75c8..c0b57c9fae 100644 --- a/tests/Tile/WFS.html +++ b/tests/Tile/WFS.html @@ -128,7 +128,43 @@ tile.requestSuccess({'requestText': ''}); t.ok(true, "Didn't fail after calling requestSuccess on destroyed tile."); } - + function test_nonxml_format(t) { + t.plan(1); + var data = '{"type":"Feature", "id":"OpenLayers.Feature.Vector_135", "properties":{}, "geometry":{"type":"Point", "coordinates":[118.125, -18.6328125]}, "crs":{"type":"OGC", "properties":{"urn":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}' + var position = new OpenLayers.Pixel(10,20); + var bounds = new OpenLayers.Bounds(1,2,3,4); + var url = "bobob"; + var size = new OpenLayers.Size(5,6); + + var tile = new OpenLayers.Tile.WFS({ + vectorMode: true, + formatObject: new OpenLayers.Format.GeoJSON(), + addFeatures: function(features) { + t.eq(features.length, 1, "GeoJSON format returned a single feature which was added.") + } + }, position, bounds, url, size); + tile.requestSuccess({responseText: data}); + } + + function test_xml_string_and_dom(t) { + t.plan(2); + var data = ' -94.989723,43.285833 -74.755001,51.709520 -94.142500,50.992777 -94.142500,50.992777 -94.142500,50.992777 ON_2 Suffel Road 50.9927770 -94.1425000 '; + var position = new OpenLayers.Pixel(10,20); + var bounds = new OpenLayers.Bounds(1,2,3,4); + var url = "bobob"; + var size = new OpenLayers.Size(5,6); + var tile = new OpenLayers.Tile.WFS({ + }, position, bounds, url, size); + tile.addResults = function(results) { + t.eq(results.length, 1, "results count is correct when passing in XML as a string into non-vectormode"); + } + tile.requestSuccess({responseText: data}); + + tile.addResults = function(results) { + t.eq(results.length, 1, "results count is correct when passing in XML as DOM into non-vectormode"); + } + tile.requestSuccess({responseXML: OpenLayers.Format.XML.prototype.read(data)}); + }