[Commits] r1359 - in sandbox/camptocamp/geobretagne: lib lib/GeoExt/data tests tests/lib/GeoExt/data

commits at geoext.org commits at geoext.org
Fri Sep 11 17:08:26 CEST 2009


Author: bbinet
Date: 2009-09-11 17:08:26 +0200 (Fri, 11 Sep 2009)
New Revision: 1359

Added:
   sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.js
Modified:
   sandbox/camptocamp/geobretagne/lib/GeoExt.js
   sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMCReader.js
   sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.html
   sandbox/camptocamp/geobretagne/tests/list-tests.html
Log:
update WMCReader to patch patch_156-r1358-A1.diff from geoext ticket 156

Modified: sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMCReader.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMCReader.js	2009-09-10 15:24:20 UTC (rev 1358)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMCReader.js	2009-09-11 15:08:26 UTC (rev 1359)
@@ -38,7 +38,6 @@
         recordType = GeoExt.data.LayerRecord.create(
             recordType || meta.fields || [
                 // give only non-OpenLayers fields as default recordType
-                {name: "name", type: "string"},
                 {name: "abstract", type: "string"},
                 {name: "metadataURL", type: "string"},
                 {name: "queryable", type: "boolean"},
@@ -84,14 +83,25 @@
         if(typeof data === "string" || data.nodeType) {
             data = format.read(data);
         }
-        var records = [], layer, layerContext;        
+        var layersContext = data ? data.layersContext : undefined;
+        var records = [];        
 
-        for (var i=0, len=data.layersContext.length; i<len; i++) {
-            layerContext = data.layersContext[i];
-            layer = format.getLayerFromContext(layerContext);
-            records.push(new this.recordType(Ext.apply(layerContext, {
-                layer: layer
-            }), layer.id));
+        if(layersContext) {
+            var recordType = this.recordType, fields = recordType.prototype.fields;
+            var i, lenI, j, lenJ, layerContext, values, field, v;
+            for (i = 0, lenI = layersContext.length; i < lenI; i++) {
+                layerContext = layersContext[i];
+                values = {};
+                for(j = 0, lenJ = fields.length; j < lenJ; j++){
+                    field = fields.items[j];
+                    v = layerContext[field.mapping || field.name] ||
+                        field.defaultValue;
+                    v = field.convert(v);
+                    values[field.name] = v;
+                }
+                values.layer = format.getLayerFromContext(layerContext);
+                records.push(new this.recordType(values, values.layer.id));
+            }
         }
         
         return {

Modified: sandbox/camptocamp/geobretagne/lib/GeoExt.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt.js	2009-09-10 15:24:20 UTC (rev 1358)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt.js	2009-09-11 15:08:26 UTC (rev 1359)
@@ -75,11 +75,8 @@
             "GeoExt/data/ScaleStore.js",
             "GeoExt/data/WMSCapabilitiesReader.js",
             "GeoExt/data/WMSCapabilitiesStore.js",
-            "GeoExt/data/WFSCapabilitiesReader.js",
-            "GeoExt/data/WFSCapabilitiesStore.js",
             "GeoExt/data/WMSDescribeLayerReader.js",
             "GeoExt/data/WMSDescribeLayerStore.js",
-            "GeoExt/data/CSWRecordsReader.js",
             "GeoExt/data/WMCReader.js",
             "GeoExt/widgets/Action.js",
             "GeoExt/data/ProtocolProxy.js",

Modified: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.html	2009-09-10 15:24:20 UTC (rev 1358)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.html	2009-09-11 15:08:26 UTC (rev 1359)
@@ -6,14 +6,78 @@
 
     <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
     <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+    <script type="text/javascript" src="WMCReader.js"></script>
 
     <script type="text/javascript">
       
         function test_constructor(t) {
-            t.plan(0);
+            t.plan(2);
+            var reader = new GeoExt.data.WMCReader();
+
+            var fields = reader.recordType.prototype.fields;
+
+            // 1 test
+            t.eq(fields.items.length, 7, 'number of default items is correct');
+
+            reader = new GeoExt.data.WMCReader({},[
+                {name: "foo"},
+                {name: "bar"}
+            ]);
+
+            fields = reader.recordType.prototype.fields;
+
+            //1 test
+            t.ok(fields.items[2].name == 'foo' &&
+                 fields.items[3].name == 'bar',
+                 'field values set from configuration are correct');
         }
         function test_read(t) {
-            t.plan(0);
+            t.plan(19);
+
+            // test a reader with the only two default LayerRecord fields
+
+            var reader = new GeoExt.data.WMCReader({},{});
+            var records = reader.read({responseXML : doc});
+
+            //1 test
+            t.eq(records.totalRecords, 3, 'readRecords returns correct number of records');
+
+            var record = records.records[1];
+            //2 tests -- testing the fields of a record
+            t.eq(record.get("title"), "geob:communes_geofla", "correct title record field");
+            t.eq(record.get("abstract"), undefined, "correct undefined abstract which is not part of fields");
+
+
+            // test a reader with all default fields
+
+            var reader = new GeoExt.data.WMCReader();
+            var records = reader.read({responseXML : doc});
+
+            //1 test
+            t.eq(records.totalRecords, 3, 'readRecords returns correct number of records');
+
+            var record = records.records[1];
+            //10 tests -- testing the fields of a record
+            t.eq(record.get("title"), "geob:communes_geofla", "correct title record field");
+            t.eq(record.get("abstract"), "Communes abstract", "correct abstract record field");
+            t.eq(record.get("metadataURL"), "", "correct metadataURL record field");
+            t.eq(record.get("queryable"), true, "correct queryable record field");
+            t.eq(record.get("formats").length, 28, "correct length for formats record field");
+            t.eq(record.get("formats")[0].value, "image/png", "correct value for formats record field");
+            t.eq(record.get("styles").length, 2, "correct length for styles record field");
+            t.eq(record.get("styles")[0].abstract, "Default line style, 1 pixel wide blue", "correct abstract for styles record field");
+            t.eq(record.get("styles")[0].name, "line", "correct name for styles record field");
+            t.eq(record.get("styles")[0].title, "1 px blue line", "correct title for styles record field");
+
+            //4 tests -- Testing the layer field
+            var layer = record.get("layer");
+            t.eq(layer.CLASS_NAME, "OpenLayers.Layer.WMS", "layer record field is of type OpenLayers.Layer.WMS");
+            t.eq(layer.url, "../geoserver/wms?SERVICE=WMS&", "layer record field has correct URL");
+            t.eq(layer.params.LAYERS, "geob:communes_geofla","layer record field has correct LAYERS parameter");
+            t.eq(layer.name, "Communes","layer record field has correct name");
+
+            //1 test
+            t.eq(record.id, layer.id, 'record id is the same as layer id');
         }
     </script>
   <body>

Added: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.js
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.js	                        (rev 0)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.js	2009-09-11 15:08:26 UTC (rev 1359)
@@ -0,0 +1,133 @@
+var doc = (new OpenLayers.Format.XML).read(
+    '<ViewContext xmlns="http://www.opengis.net/context" version="1.1.0" id="default.wmc" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.1.0/context.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
+      '<General>' +
+        '<Window width="1031" height="389"/>' +
+        '<BoundingBox minx="-37179.8441128839986" miny="6691080.05881679989" maxx="540179.844112879946" maxy="6908919.94118320011" SRS="EPSG:2154"/>' +
+        '<Title/>' +
+        '<Extension>' +
+          '<ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="83000.0000000000000" miny="6700000.00000000000" maxx="420000.000000000000" maxy="6900000.00000000000"/>' +
+        '</Extension>' +
+      '</General>' +
+      '<LayerList>' +
+        '<Layer queryable="0" hidden="0">' +
+          '<Server service="OGC:WMS" version="1.1.1">' +
+            '<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../geoserver/gwc/service/wms"/>' +
+          '</Server>' +
+          '<Name>geob:SC1000_0050_7130_L93</Name>' +
+          '<Title>Scan 1000</Title>' +
+          '<Abstract>Scan 1000 abstract</Abstract>' +
+          '<sld:MinScaleDenominator xmlns:sld="http://www.opengis.net/sld">250000.0000000000</sld:MinScaleDenominator>' +
+          '<sld:MaxScaleDenominator xmlns:sld="http://www.opengis.net/sld">2000000.000000000</sld:MaxScaleDenominator>' +
+          '<FormatList>' +
+            '<Format current="1">image/png</Format>' +
+          '</FormatList>' +
+          '<StyleList>' +
+            '<Style>' +
+              '<Name/>' +
+              '<Title/>' +
+            '</Style>' +
+          '</StyleList>' +
+          '<Extension>' +
+            '<ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="83000.0000000000000" miny="6700000.00000000000" maxx="420000.000000000000" maxy="6900000.00000000000"/>' +
+            '<ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels>' +
+            '<ol:units xmlns:ol="http://openlayers.org/context">m</ol:units>' +
+            '<ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer>' +
+            '<ol:opacity xmlns:ol="http://openlayers.org/context">1</ol:opacity>' +
+            '<ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher>' +
+            '<ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile>' +
+          '</Extension>' +
+        '</Layer>' +
+        '<Layer queryable="1" hidden="0">' +
+          '<Server service="OGC:WMS" version="1.1.1">' +
+            '<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../geoserver/wms?SERVICE=WMS&amp;"/>' +
+          '</Server>' +
+          '<Name>geob:communes_geofla</Name>' +
+          '<Title>Communes</Title>' +
+          '<Abstract>Communes abstract</Abstract>' +
+          '<FormatList>' +
+            '<Format current="1">image/png</Format>' +
+            '<Format>application/atom xml</Format>' +
+            '<Format>application/atom+xml</Format>' +
+            '<Format>application/openlayers</Format>' +
+            '<Format>application/pdf</Format>' +
+            '<Format>application/rss xml</Format>' +
+            '<Format>application/rss+xml</Format>' +
+            '<Format>application/vnd.google-earth.kml</Format>' +
+            '<Format>application/vnd.google-earth.kml xml</Format>' +
+            '<Format>application/vnd.google-earth.kml+xml</Format>' +
+            '<Format>application/vnd.google-earth.kmz</Format>' +
+            '<Format>application/vnd.google-earth.kmz xml</Format>' +
+            '<Format>application/vnd.google-earth.kmz+xml</Format>' +
+            '<Format>atom</Format>' +
+            '<Format>image/geotiff</Format>' +
+            '<Format>image/geotiff8</Format>' +
+            '<Format>image/gif</Format>' +
+            '<Format>image/jpeg</Format>' +
+            '<Format>image/png8</Format>' +
+            '<Format>image/svg</Format>' +
+            '<Format>image/svg xml</Format>' +
+            '<Format>image/svg+xml</Format>' +
+            '<Format>image/tiff</Format>' +
+            '<Format>image/tiff8</Format>' +
+            '<Format>kml</Format>' +
+            '<Format>kmz</Format>' +
+            '<Format>openlayers</Format>' +
+            '<Format>rss</Format>' +
+          '</FormatList>' +
+          '<StyleList>' +
+            '<Style>' +
+              '<Name>line</Name>' +
+              '<Title>1 px blue line</Title>' +
+              '<Abstract>Default line style, 1 pixel wide blue</Abstract>' +
+            '</Style>' +
+            '<Style>' +
+              '<Name>dpt_classif</Name>' +
+              '<Title>Classification par départements</Title>' +
+            '</Style>' +
+          '</StyleList>' +
+          '<Extension>' +
+            '<ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="83000.0000000000000" miny="6700000.00000000000" maxx="420000.000000000000" maxy="6900000.00000000000"/>' +
+            '<ol:transparent xmlns:ol="http://openlayers.org/context">true</ol:transparent>' +
+            '<ol:numZoomLevels xmlns:ol="http://openlayers.org/context">13</ol:numZoomLevels>' +
+            '<ol:units xmlns:ol="http://openlayers.org/context">m</ol:units>' +
+            '<ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer>' +
+            '<ol:opacity xmlns:ol="http://openlayers.org/context">0.5</ol:opacity>' +
+            '<ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher>' +
+            '<ol:singleTile xmlns:ol="http://openlayers.org/context">true</ol:singleTile>' +
+          '</Extension>' +
+        '</Layer>' +
+        '<Layer queryable="1" hidden="0">' +
+          '<Server service="OGC:WMS" version="1.1.1">' +
+            '<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://geolittoral.application.equipement.gouv.fr/map/mapserv?map=/opt/data/carto/applis/geolittoral/map/metropole.www.map&amp;"/>' +
+          '</Server>' +
+          '<Name>Sentiers_littoraux</Name>' +
+          '<Title>Sentiers littoraux</Title>' +
+          '<FormatList>' +
+            '<Format current="1">image/png</Format>' +
+            '<Format>image/gif</Format>' +
+            '<Format>image/png; mode=24bit</Format>' +
+            '<Format>image/jpeg</Format>' +
+            '<Format>image/vnd.wap.wbmp</Format>' +
+            '<Format>image/tiff</Format>' +
+            '<Format>image/svg+xml</Format>' +
+          '</FormatList>' +
+          '<StyleList>' +
+            '<Style>' +
+              '<Name>default</Name>' +
+              '<Title>default</Title>' +
+            '</Style>' +
+          '</StyleList>' +
+          '<Extension>' +
+            '<ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="83000.0000000000000" miny="6700000.00000000000" maxx="420000.000000000000" maxy="6900000.00000000000"/>' +
+            '<ol:transparent xmlns:ol="http://openlayers.org/context">true</ol:transparent>' +
+            '<ol:numZoomLevels xmlns:ol="http://openlayers.org/context">13</ol:numZoomLevels>' +
+            '<ol:units xmlns:ol="http://openlayers.org/context">m</ol:units>' +
+            '<ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer>' +
+            '<ol:opacity xmlns:ol="http://openlayers.org/context">1</ol:opacity>' +
+            '<ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher>' +
+            '<ol:singleTile xmlns:ol="http://openlayers.org/context">true</ol:singleTile>' +
+          '</Extension>' +
+        '</Layer>' +
+      '</LayerList>' +
+    '</ViewContext>'
+);

Modified: sandbox/camptocamp/geobretagne/tests/list-tests.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/list-tests.html	2009-09-10 15:24:20 UTC (rev 1358)
+++ sandbox/camptocamp/geobretagne/tests/list-tests.html	2009-09-11 15:08:26 UTC (rev 1359)
@@ -9,10 +9,8 @@
   <li>lib/GeoExt/data/LayerStore.html</li>
   <li>lib/GeoExt/data/ScaleStore.html</li>
   <li>lib/GeoExt/data/ProtocolProxy.html</li>
-  <li>lib/GeoExt/data/WFSCapabilitiesReader.html</li>
   <li>lib/GeoExt/data/WMSCapabilitiesReader.html</li>
   <li>lib/GeoExt/data/WMSDescribeLayerReader.html</li>
-  <li>lib/GeoExt/data/CSWRecordsReader.html</li>
   <li>lib/GeoExt/data/WMCReader.html</li>
   <li>lib/GeoExt/widgets/Action.html</li>
   <li>lib/GeoExt/widgets/LayerOpacitySlider.html</li>



More information about the Commits mailing list