[Commits] r1334 - in sandbox/camptocamp/geobretagne: lib/GeoExt/data tests/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Mon Aug 24 13:02:13 CEST 2009
Author: elemoine
Date: 2009-08-24 13:02:13 +0200 (Mon, 24 Aug 2009)
New Revision: 1334
Modified:
sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMSCapabilitiesReader.js
sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.html
sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.js
Log:
apply patch_geoext_ticket126_r1332_A2.diff from #126
Modified: sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMSCapabilitiesReader.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMSCapabilitiesReader.js 2009-08-24 10:59:36 UTC (rev 1333)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMSCapabilitiesReader.js 2009-08-24 11:02:13 UTC (rev 1334)
@@ -40,15 +40,25 @@
{name: "name", type: "string"},
{name: "abstract", type: "string"},
{name: "queryable", type: "boolean"},
- {name: "formats"},
- {name: "styles"},
- {name: "llbbox"},
- {name: "minScale"},
- {name: "maxScale"},
- {name: "prefix"},
- {name: "attribution"},
- {name: "keywords"},
- {name: "metadataURLs"}
+ {name: "opaque", type: "boolean"},
+ {name: "noSubsets", type: "boolean"},
+ {name: "cascaded", type: "int"},
+ {name: "fixedWidth", type: "int"},
+ {name: "fixedHeight", type: "int"},
+ {name: "minScale", type: "float"},
+ {name: "maxScale", type: "float"},
+ {name: "prefix", type: "string"},
+ {name: "formats"}, // array
+ {name: "styles"}, // array
+ {name: "srs"}, // object
+ {name: "dimensions"}, // object
+ {name: "bbox"}, // object
+ {name: "llbbox"}, // array
+ {name: "attribution"}, // object
+ {name: "keywords"}, // array
+ {name: "identifiers"}, // object
+ {name: "authorityURLs"}, // object
+ {name: "metadataURLs"} // array
]
);
}
@@ -80,9 +90,56 @@
}
return this.readRecords(data);
},
+
+ /** private: method[serviceExceptionFormat]
+ * :param formats: ``Array`` An array of service exception format strings.
+ * :return: ``String`` The (supposedly) best service exception format.
+ */
+ serviceExceptionFormat: function(formats) {
+ if (OpenLayers.Util.indexOf(formats,
+ "application/vnd.ogc.se_inimage")>-1) {
+ return "application/vnd.ogc.se_inimage";
+ }
+ if (OpenLayers.Util.indexOf(formats,
+ "application/vnd.ogc.se_xml")>-1) {
+ return "application/vnd.ogc.se_xml";
+ }
+ return formats[0];
+ },
+ /** private: method[imageFormat]
+ * :param layer: ``Object`` The layer's capabilities object.
+ * :return: ``String`` The (supposedly) best mime type for requesting
+ * tiles.
+ */
+ imageFormat: function(layer) {
+ var formats = layer.formats;
+ if (layer.opaque &&
+ OpenLayers.Util.indexOf(formats, "image/jpeg")>-1) {
+ return "image/jpeg";
+ }
+ if (OpenLayers.Util.indexOf(formats, "image/png")>-1) {
+ return "image/png";
+ }
+ if (OpenLayers.Util.indexOf(formats, "image/png; mode=24bit")>-1) {
+ return "image/png; mode=24bit";
+ }
+ if (OpenLayers.Util.indexOf(formats, "image/gif")>-1) {
+ return "image/gif";
+ }
+ return formats[0];
+ },
+
+ /** private: method[imageTransparent]
+ * :param layer: ``Object`` The layer's capabilities object.
+ * :return: ``Boolean`` The TRANSPARENT param.
+ */
+ imageTransparent: function(layer) {
+ return layer.opaque == undefined || !layer.opaque;
+ },
+
/** private: method[readRecords]
- * :param data: ``DOMElement | Strint | Object`` A document element or XHR
+ * :param data: ``DOMElement | String | Object`` A document element or XHR
* response string. As an alternative to fetching capabilities data
* from a remote source, an object representing the capabilities can
* be provided given that the structure mirrors that returned from the
@@ -93,22 +150,32 @@
* Create a data block containing Ext.data.Records from an XML document.
*/
readRecords: function(data) {
-
if(typeof data === "string" || data.nodeType) {
data = this.meta.format.read(data);
}
- var url = data.capability.request.getmap.href;
+ var capability = data.capability;
+ var url = capability.request.getmap.href;
var records = [], layer;
- for(var i=0, len=data.capability.layers.length; i<len; i++){
- layer = data.capability.layers[i];
-
+ for(var i=0, len=capability.layers.length; i<len; i++){
+ layer = capability.layers[i];
if(layer.name) {
records.push(new this.recordType(Ext.apply(layer, {
layer: new OpenLayers.Layer.WMS(
layer.title || layer.name,
- url,
- {layers: layer.name}, {
+ url, {
+ layers: layer.name,
+ exceptions: this.serviceExceptionFormat(
+ capability.exception.formats
+ ),
+ format: this.imageFormat(layer),
+ transparent: this.imageTransparent(layer),
+ version: data.version
+ }, {
+ minScale: layer.minScale != undefined ?
+ layer.minScale : undefined,
+ maxScale: layer.maxScale != undefined ?
+ layer.maxScale : undefined,
attribution: layer.attribution ?
this.attributionMarkup(layer.attribution) :
undefined
Modified: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.html 2009-08-24 10:59:36 UTC (rev 1333)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.html 2009-08-24 11:02:13 UTC (rev 1334)
@@ -17,7 +17,7 @@
var fields = reader.recordType.prototype.fields;
// 1 test
- t.eq(fields.items.length, 14, 'number of default items is correct');
+ t.eq(fields.items.length, 24, 'number of default items is correct');
var reader = new GeoExt.data.WMSCapabilitiesReader({},[
@@ -33,18 +33,19 @@
'field values set from configuration are correct');
}
function test_read(t) {
- t.plan(16);
+ t.plan(34);
var reader = new GeoExt.data.WMSCapabilitiesReader();
- var records = reader.read({responseXML : doc});
+ var records = reader.read({responseXML: doc});
//1 test
t.eq(records.totalRecords, 22, 'readRecords returns correct number of records');
- var record = records.records[2];
+ var record, layer;
- //8 tests -- testing the fields of a record
+ //22 tests -- testing the fields of a record
+ record = records.records[2];
t.eq(record.get("name"), "tiger:tiger_roads", "[2] correct layer name");
t.eq(record.get("title"), "Manhattan (NY) roads", "[2] correct layer title");
t.eq(
@@ -65,20 +66,56 @@
"[2] correct legend url"
);
t.eq(record.get("queryable"), true, "[2] correct queryable attribute");
+ t.eq(record.get("opaque"), true, "[2] correct opaque attribute");
+ t.eq(record.get("cascaded"), 3, "[2] correct cascaded attribute");
+ t.eq(record.get("noSubsets"), true, "[2] correct noSubsets attribute");
+ t.eq(record.get("fixedWidth"), 400, "[2] correct fixedWidth attribute");
+ t.eq(record.get("fixedHeight"), 200, "[2] correct fixedHeight attribute");
+ t.eq(record.get("formats")[0], "image/png", "[2] correct image/png formats attribute");
+ t.eq(record.get("formats")[14], "image/geotiff", "[2] correct image/geotiff formats attribute");
+ t.eq(record.get("formats")[27], "rss", "[2] correct rss formats attribute");
+ t.eq(record.get("srs")[0], "EPSG:WGS84(DD)", "[2] correct srs[0] attribute");
+ t.eq(record.get("srs")[record.get("srs").length-1], "EPSG:42303", "[2] correct srs[nb_srs-1] attribute");
+ t.eq(record.get("prefix"), "tiger", "[2] correct prefix attribute");
+ t.eq(
+ record.get("bbox")["EPSG:4326"].bbox,
+ [-74.02722,40.684221,-73.907005,40.878178],
+ "[2] correct bbox"
+ );
+ t.eq(record.get("authorityURLs").gcmd, "http://www.authority.com", "[2] correct authorityURLs attribute");
+ t.eq(record.get("identifiers").gcmd, "id_value", "[2] correct identifiers attribute");
+ // cannot test "dimensions" until we have nested layers: see http://trac.openlayers.org/ticket/2144
- //4 tests -- Testing the layer field
- var layer = record.get("layer");
+ //6 tests -- Testing the layer field
+ record = records.records[2];
+ layer = record.get("layer");
t.eq(layer.CLASS_NAME, "OpenLayers.Layer.WMS", "[2] layer field is of type OpenLayers.Layer.WMS");
t.eq(layer.url, "http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&", "[2] layer field has correct URL");
t.eq(layer.params.LAYERS, "tiger:tiger_roads","[2] layer field has correct LAYERS parameter");
t.eq(layer.name, "Manhattan (NY) roads","[2] layer field has correct name");
+ t.eq(typeof(layer.minScale), "number","[2] layer minScale has been set");
+ t.eq(typeof(layer.maxScale), "number","[2] layer maxScale has been set");
// 3 tests -- attribution markup
+ record = records.records[2];
+ layer = record.get("layer");
var attribution = layer.attribution;
t.ok(attribution.indexOf("http://foo/logo.png") !== -1, "attribution markup has a logo");
t.ok(attribution.indexOf("Foo Authority") !== -1, "attribution markup has a title");
t.ok(attribution.indexOf("http://foo/about/") !== -1, "attribution has a link");
+ // 2 tests - transparent param
+ var transparent;
+ record = records.records[2];
+ layer = record.get("layer");
+ transparent = layer.params.TRANSPARENT;
+ t.eq(transparent, false,
+ "TRANSPARENT param is false if opacity set to 1");
+ record = records.records[1];
+ layer = record.get("layer");
+ transparent = layer.params.TRANSPARENT;
+ t.eq(transparent, true,
+ "TRANSPARENT param is true if no opacity set");
}
</script>
<body>
Modified: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.js
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.js 2009-08-24 10:59:36 UTC (rev 1333)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.js 2009-08-24 11:02:13 UTC (rev 1334)
@@ -4110,10 +4110,12 @@
'</LegendURL>' +
'</Style>' +
'</Layer>' +
- '<Layer queryable="1">' +
+ '<Layer queryable="1" opaque="1" cascaded="3" noSubsets="1" fixedWidth="400" fixedHeight="200">' +
'<Name>tiger:tiger_roads</Name>' +
'<Title>Manhattan (NY) roads</Title>' +
'<Abstract>Highly simplified road layout of Manhattan in New York..</Abstract>' +
+ '<AuthorityURL name="gcmd"><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.authority.com" /></AuthorityURL>' +
+ '<Identifier authority="gcmd">id_value</Identifier>' +
'<KeywordList>' +
'<Keyword>DS_tiger_roads</Keyword>' +
'<Keyword>tiger_roads</Keyword>' +
@@ -4149,6 +4151,7 @@
'<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://publicus.opengeo.org:80/geoserver/wms/GetLegendGraphic?VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=tiger:tiger_roads"/>' +
'</LegendURL>' +
'</Style>' +
+ '<ScaleHint min="37.4177136322228" max="299.341709057782" />' +
'</Layer>' +
'<Layer queryable="1">' +
'<Name>sf:archsites</Name>' +
More information about the Commits
mailing list