OpenLayers OpenLayers

Changeset 7416

Show
Ignore:
Timestamp:
06/21/08 10:23:33 (3 months ago)
Author:
crschmidt
Message:

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)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Tile/WFS.js

    r7339 r7416  
    134134            var doc = request.responseXML; 
    135135            if (!doc || !doc.documentElement) { 
    136                 doc = OpenLayers.Format.XML.prototype.read(request.responseText); 
     136                doc = request.responseText;  
    137137            } 
    138138            if (this.layer.vectorMode) { 
    139139                this.layer.addFeatures(this.layer.formatObject.read(doc)); 
    140140            } else { 
    141                 var resultFeatures = OpenLayers.Ajax.getElementsByTagNameNS( 
    142                     doc, "http://www.opengis.net/gml", "gml", "featureMember" 
     141                var xml = new OpenLayers.Format.XML(); 
     142                if (typeof doc == "string") { 
     143                    doc = xml.read(doc); 
     144                } 
     145                var resultFeatures = xml.getElementsByTagNameNS( 
     146                    doc, "http://www.opengis.net/gml", "featureMember" 
    143147                ); 
    144148                this.addResults(resultFeatures); 
  • trunk/openlayers/tests/Tile/WFS.html

    r7335 r7416  
    129129        t.ok(true, "Didn't fail after calling requestSuccess on destroyed tile."); 
    130130    } 
    131  
     131    function test_nonxml_format(t) { 
     132        t.plan(1); 
     133        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"}}}' 
     134        var position = new OpenLayers.Pixel(10,20); 
     135        var bounds = new OpenLayers.Bounds(1,2,3,4); 
     136        var url = "bobob"; 
     137        var size = new OpenLayers.Size(5,6); 
     138         
     139        var tile = new OpenLayers.Tile.WFS({ 
     140            vectorMode: true,  
     141            formatObject: new OpenLayers.Format.GeoJSON(),  
     142            addFeatures: function(features) {  
     143                t.eq(features.length, 1, "GeoJSON format returned a single feature which was added.") 
     144            } 
     145        }, position, bounds, url, size); 
     146        tile.requestSuccess({responseText: data}); 
     147    }   
     148      
     149    function test_xml_string_and_dom(t) { 
     150        t.plan(2); 
     151        var data = '<?xml version="1.0" encoding="ISO-8859-1" ?><wfs:FeatureCollection   xmlns:bsc="http://www.bsc-eoc.org/bsc"   xmlns:wfs="http://www.opengis.net/wfs"   xmlns:gml="http://www.opengis.net/gml"   xmlns:ogc="http://www.opengis.net/ogc"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengeospatial.net//wfs/1.0.0/WFS-basic.xsd                        http://www.bsc-eoc.org/bsc http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=OWLS&amp;OUTPUTFORMAT=XMLSCHEMA">      <gml:boundedBy>        <gml:Box srsName="EPSG:4326">            <gml:coordinates>-94.989723,43.285833 -74.755001,51.709520</gml:coordinates>        </gml:Box>      </gml:boundedBy>    <gml:featureMember>      <bsc:OWLS>        <gml:boundedBy>            <gml:Box srsName="EPSG:4326">                <gml:coordinates>-94.142500,50.992777 -94.142500,50.992777</gml:coordinates>            </gml:Box>        </gml:boundedBy>        <bsc:msGeometry>        <gml:Point srsName="EPSG:4326">          <gml:coordinates>-94.142500,50.992777</gml:coordinates>        </gml:Point>        </bsc:msGeometry>        <bsc:ROUTEID>ON_2</bsc:ROUTEID>        <bsc:ROUTE_NAME>Suffel Road</bsc:ROUTE_NAME>        <bsc:LATITUDE>50.9927770</bsc:LATITUDE>        <bsc:LONGITUDE>-94.1425000</bsc:LONGITUDE>      </bsc:OWLS>    </gml:featureMember></wfs:FeatureCollection>'; 
     152        var position = new OpenLayers.Pixel(10,20); 
     153        var bounds = new OpenLayers.Bounds(1,2,3,4); 
     154        var url = "bobob"; 
     155        var size = new OpenLayers.Size(5,6); 
     156        var tile = new OpenLayers.Tile.WFS({ 
     157        }, position, bounds, url, size); 
     158        tile.addResults = function(results) { 
     159            t.eq(results.length, 1, "results count is correct when passing in XML as a string into non-vectormode"); 
     160        }  
     161        tile.requestSuccess({responseText: data}); 
     162         
     163        tile.addResults = function(results) { 
     164            t.eq(results.length, 1, "results count is correct when passing in XML as DOM into non-vectormode"); 
     165        }  
     166        tile.requestSuccess({responseXML: OpenLayers.Format.XML.prototype.read(data)});  
     167    }          
    132168  </script> 
    133169</head>