[OpenLayers-Commits] r3634 - sandbox/tschaub/geojson/lib/OpenLayers/Tile

commits at openlayers.org commits at openlayers.org
Fri Jul 6 18:43:01 EDT 2007


Author: tschaub
Date: 2007-07-06 18:43:00 -0400 (Fri, 06 Jul 2007)
New Revision: 3634

Modified:
   sandbox/tschaub/geojson/lib/OpenLayers/Tile/WFS.js
Log:
add in ability for a wfs tile to parse GeoJSON instead of GML

Modified: sandbox/tschaub/geojson/lib/OpenLayers/Tile/WFS.js
===================================================================
--- sandbox/tschaub/geojson/lib/OpenLayers/Tile/WFS.js	2007-07-06 22:26:18 UTC (rev 3633)
+++ sandbox/tschaub/geojson/lib/OpenLayers/Tile/WFS.js	2007-07-06 22:43:00 UTC (rev 3634)
@@ -19,17 +19,25 @@
   OpenLayers.Class.inherit( OpenLayers.Tile, {
 
     /** 
-	 * Property: features 
-	 * {Array(<OpenLayers.Feature>)} list of features in this tile 
-	 */
-	features: null,
+     * Property: features 
+     * {Array(<OpenLayers.Feature>)} list of features in this tile 
+     */
+    features: null,
 
     /** 
-	 * Property: url 
-	 * {String} 
-	 */
-	url: null,
+     * Property: url 
+     * {String} 
+     */
+    url: null,
     
+    /**
+     * Property: parser
+     * {<OpenLayers.Format>} If the layer is a vector layer, the layer
+     *     format will be checked to determine which parser to use.
+     *     Valid layer formats are GML and GeoJSON.
+     */
+    parser: null,
+    
     /** TBD 3.0 - reorder the parameters to the init function to put URL 
      *             as last, so we can continue to call tile.initialize() 
      *             without changing the arguments. 
@@ -48,6 +56,15 @@
         OpenLayers.Tile.prototype.initialize.apply(this, arguments);
         this.url = url;        
         this.features = new Array();
+	if(this.layer.vectorMode) {
+	    if(this.layer.format == "GeoJSON") {
+		this.parser = new OpenLayers.Format.GeoJSON();
+	    } else {
+		this.parser = new OpenLayers.Format.GML(
+		    {extractAttributes: this.layer.options.extractAttributes});
+	    }
+	}
+
     },
 
     /** 
@@ -111,8 +128,8 @@
             doc = OpenLayers.parseXMLString(request.responseText);
         }
         if (this.layer.vectorMode) {
-            var gml = new OpenLayers.Format.GML({extractAttributes: this.layer.options.extractAttributes});
-            this.layer.addFeatures(gml.read(doc));
+	    var features = this.parser.read(doc);
+            this.layer.addFeatures(features);
         } else {
             var resultFeatures = OpenLayers.Ajax.getElementsByTagNameNS(doc, "http://www.opengis.net/gml","gml", "featureMember");
             this.addResults(resultFeatures);



More information about the Commits mailing list