diff --git a/lib/GeoExt.js b/lib/GeoExt.js index 64ff68f2..f883fe39 100644 --- a/lib/GeoExt.js +++ b/lib/GeoExt.js @@ -79,6 +79,8 @@ "GeoExt/data/WFSCapabilitiesReader.js", "GeoExt/data/WFSCapabilitiesStore.js", "GeoExt/data/WMSDescribeLayerReader.js", + "GeoExt/data/WCSCapabilitiesReader.js", + "GeoExt/data/WCSCapabilitiesStore.js", "GeoExt/data/WMSDescribeLayerStore.js", "GeoExt/data/WMCReader.js", "GeoExt/data/CSWRecordsReader.js", diff --git a/lib/GeoExt/data/WCSCapabilitiesReader.js b/lib/GeoExt/data/WCSCapabilitiesReader.js new file mode 100644 index 00000000..c8b1ce43 --- /dev/null +++ b/lib/GeoExt/data/WCSCapabilitiesReader.js @@ -0,0 +1,121 @@ +/** + * Copyright (c) 2008-2011 The Open Source Geospatial Foundation + * + * Published under the BSD license. + * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text + * of the license. + */ + +/** + * @require OpenLayers/Format/WCSCapabilities.js + * @require OpenLayers/Format/WCSCapabilities/v1_0_0.js + * @require OpenLayers/Format/WCSCapabilities/v1_1_0.js + */ + +/** api: (define) + * module = GeoExt.data + * class = WCSCapabilitiesReader + * base_link = `Ext.data.DataReader `_ + */ +Ext.namespace("GeoExt.data"); + +/** api: constructor + * .. class:: WCSCapabilitiesReader(meta, recordType) + * + * :param meta: ``Object`` Reader configuration from which: + * ``fields`` is a list of fields to be extracted from the WCS GetCapabilities request. + * :param recordType: ``Array | Ext.data.Record`` An array of field + * configuration objects or a record object. Default is + * :class:`GeoExt.data.LayerRecord`. + * + * Data reader class to create an array of + * :class:`Ext.data.Record` objects from a WCS GetCapabilities + * response. + */ +GeoExt.data.WCSCapabilitiesReader = function(meta, recordType) { + meta = meta || {}; + if(!meta.format) { + meta.format = new OpenLayers.Format.WCSCapabilities(); + } + // Create some default items if recordType is not specified + if(!(typeof recordType === "function")) { + fields = recordType || meta.fields || [ + {name: "title", type: "string"}, + {name: "abstract", type: "string"} + ]; + + // Make sure we always have an name attribute; + // this will be needed by readRecords. + fields.push({name: "name", type: "string", mapping: "identifier"}); + recordType = Ext.data.Record.create(fields); + } + + GeoExt.data.WCSCapabilitiesReader.superclass.constructor.call( + this, meta, recordType + ); +}; + +Ext.extend(GeoExt.data.WCSCapabilitiesReader, Ext.data.DataReader, { + + /** private: method[read] + * :param request: ``Object`` The XHR object which contains the parsed XML + * document. + * :return: ``Object`` A data block which is used by an ``Ext.data.Store`` + * as a cache of ``Ext.data.Record`` objects. + */ + read: function(request) { + var data = request.responseXML; + if(!data || !data.documentElement) { + data = request.responseText; + } + return this.readRecords(data); + }, + + /** private: method[readRecords] + * :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 + * capabilities parser. + * :return: ``Object`` A data block which is used by an ``Ext.data.Store`` + * as a cache of ``Ext.data.Record`` objects. + * + * 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 contents = data.contentMetadata; + var fields = this.recordType.prototype.fields; + + var coverageSummary, values, field, v; + + var records = []; + + for(var i=0, lenI=contents.length; i`_ + */ +Ext.namespace("GeoExt.data"); + +/** api: constructor + * .. class:: WCSCapabilitiesStore + * + * Small helper class to make creating stores for remote WCS metadata + * easier. The store is pre-configured with a built-in + * ``Ext.data.HttpProxy`` and :class:`GeoExt.data.WCSCapabilitiesReader`. + * The proxy is configured to allow caching and issues requests via GET. + */ + +/** api: config[format] + * ``OpenLayers.Format`` + * A parser for transforming the XHR response into an array of objects + * representing attributes. Defaults to an ``OpenLayers.Format.WCSCapabilities`` + * parser. + */ + +/** api: config[fields] + * ``Array | Function`` + * Either an Array of field definition objects as passed to + * ``Ext.data.Record.create``, or a record constructor created using + * ``Ext.data.Record.create``. Defaults to ``["name", "type"]``. + */ + +GeoExt.data.WCSCapabilitiesStore = function(c) { + c = c || {}; + GeoExt.data.WCSCapabilitiesStore.superclass.constructor.call( + this, + Ext.apply(c, { + proxy: c.proxy || (!c.data ? + new Ext.data.HttpProxy({url: c.url, disableCaching: false, method: "GET"}) : + undefined + ), + reader: new GeoExt.data.WCSCapabilitiesReader( + c, c.fields + ) + }) + ); +}; +Ext.extend(GeoExt.data.WCSCapabilitiesStore, Ext.data.Store); diff --git a/lib/GeoExt/data/WFSCapabilitiesReader.js b/lib/GeoExt/data/WFSCapabilitiesReader.js index 3fc829ff..f883f099 100644 --- a/lib/GeoExt/data/WFSCapabilitiesReader.js +++ b/lib/GeoExt/data/WFSCapabilitiesReader.js @@ -98,6 +98,7 @@ Ext.extend(GeoExt.data.WFSCapabilitiesReader, Ext.data.DataReader, { var featureType, values, field, v, parts, layer; var layerOptions, protocolOptions; +// Will fail with WFS 1.1.0 var protocolDefaults = { url: data.capability.request.getfeature.href.post }; diff --git a/tests/lib/GeoExt/data/WCSCapabilitiesReader.html b/tests/lib/GeoExt/data/WCSCapabilitiesReader.html new file mode 100644 index 00000000..6b919717 --- /dev/null +++ b/tests/lib/GeoExt/data/WCSCapabilitiesReader.html @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + +
+ + diff --git a/tests/lib/GeoExt/data/WCSCapabilitiesReader.js b/tests/lib/GeoExt/data/WCSCapabilitiesReader.js new file mode 100644 index 00000000..b60c719c --- /dev/null +++ b/tests/lib/GeoExt/data/WCSCapabilitiesReader.js @@ -0,0 +1,323 @@ +var doc100 = (new OpenLayers.Format.XML).read( +'' + +'' + + '' + + 'MapServer WCS' + + '' + + '' + + 'Geospatial WebServices' + + 'Luxembourg!' + + '' + + '' + + 'Franko Lemmer' + + 'CRP Henri Tudor' + + 'R+D engineer' + + '' + + '' + + '6463320' + + '6465955' + + '' + + '
' + + '66, rue de Luxembourg' + + 'Esch-sur-Alzette' + + '' + + '97202' + + 'Luxembourg' + + 'franko.lemmer@flensburger.de' + + '
' + + '' + + '
' + + '
' + + 'mucho dinero' + + 'Open to the public' + + '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + 'application/vnd.ogc.se_xml' + + '' + + '' + + '' + + '' + + 'ro_dsm' + + '' + + '' + + '4.44444 51.515151' + + '5.55555 52.525252' + + '' + + '' + + '' + + 'ro_dsm_mini' + + '' + + '' + + '4.47489346945755 51.9159453786927' + + '4.47687824892444 51.9170706688033' + + '' + + '' + + '' + + 'ro_irra' + + '' + + '' + + '4.471333734139 51.912813427383' + + '4.4808508475645 51.9248713705576' + + '' + + '' + + '' + + 'ro_irra_ext' + + '' + + '' + + '4.10024171314823 51.9359764992844' + + '4.21909054278063 52.001415228243' + + '' + + '' + + '' + +'
' ); + + +var doc110 = (new OpenLayers.Format.XML).read( +'' + +'' + + '' + + 'Web-Service Demo with data stored at TUDOR site' + + 'This installation serves different Web-Service types (WMS, WFS) for testing' + + '' + + 'Geospatial WebServices' + + 'Keyword One' + + 'Keyword Two!!' + + '' + + 'OGC WCS' + + '1.1.0' + + 'No fee!' + + 'Unconstrained!' + + '' + + '' + + 'CRP Henri Tudor' + + '' + + '' + + 'Roy Dumerde' + + 'R+D engineer' + + '' + + '' + + '6463320' + + '6465955' + + '' + + '' + + '66, rue de Luxembourg' + + 'Esch-sur-Alzette' + + '' + + '97202' + + 'Luxembourg' + + 'flappy@tutones.com' + + '' + + '' + + '24/7' + + 'by phone' + + '' + + 'GIS-Analyst' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + 'WCS' + + '' + + '' + + '' + + '' + + '1.1.0' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + 'WCS' + + '' + + '' + + '' + + '' + + '1.1.0' + + '' + + '' + + '' + + '' + + 'ro_dsm' + + 'ro_dsm_mini' + + 'ro_irra' + + 'ro_irra_ext' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + 'WCS' + + '' + + '' + + '' + + '' + + '1.1.0' + + '' + + '' + + '' + + '' + + 'ro_dsm' + + 'ro_dsm_mini' + + 'ro_irra' + + 'ro_irra_ext' + + '' + + '' + + '' + + '' + + 'NEAREST_NEIGHBOUR' + + 'BILINEAR' + + '' + + '' + + '' + + '' + + 'image/tiff' + + 'image/png' + + 'image/jpeg' + + 'image/gif' + + 'image/png; mode=8bit' + + '' + + '' + + '' + + '' + + 'false' + + '' + + '' + + '' + + '' + + 'urn:ogc:def:crs:epsg::4326' + + '' + + '' + + '' + + '' + + '' + + '' + + 'Rotterdam DSM' + + 'Digital Surface Model (DSM) raster data set of inner city Rotterdam' + + '' + + '4.471333734139 51.912813427383' + + '4.4808508475645 51.9248713705576' + + '' + + 'urn:ogc:def:crs:EPSG::28992' + + 'urn:ogc:def:crs:EPSG::900913' + + 'urn:ogc:def:crs:EPSG::3857' + + 'urn:ogc:def:crs:EPSG::4326' + + 'image/tiff' + + 'ro_dsm' + + '' + + '' + + 'Rotterdam sample DSM subset' + + 'This a test data set of Rotterdams DSM subset' + + '' + + '4.47489346945755 51.9159453786927' + + '4.47687824892444 51.9170706688033' + + '' + + 'urn:ogc:def:crs:EPSG::28992' + + 'urn:ogc:def:crs:EPSG::900913' + + 'urn:ogc:def:crs:EPSG::3857' + + 'urn:ogc:def:crs:EPSG::4326' + + 'image/tiff' + + 'ro_dsm_mini' + + '' + + '' + + 'Rotterdam (Ljinbaan) solar irradiation data 2010' + + 'This a result data set of a solar computation of Ljinbaan area. It shows the sum of kWh/a per sqmeter for 2010' + + '' + + '4.471333734139 51.912813427383' + + '4.4808508475645 51.9248713705576' + + '' + + 'urn:ogc:def:crs:EPSG::28992' + + 'urn:ogc:def:crs:EPSG::900913' + + 'urn:ogc:def:crs:EPSG::3857' + + 'urn:ogc:def:crs:EPSG::4326' + + 'image/tiff' + + 'ro_irra' + + '' + + '' + + 'Rotterdam (extended) solar irradiation data 2010' + + 'This a result data set of a solar computation of extended Rotterdam area. It shows the sum of kWh/a per sqmeter for 2010' + + '' + + '4.10024171314823 51.9359764992844' + + '4.21909054278063 52.001415228243' + + '' + + 'urn:ogc:def:crs:EPSG::28992' + + 'urn:ogc:def:crs:EPSG::900913' + + 'urn:ogc:def:crs:EPSG::3857' + + 'urn:ogc:def:crs:EPSG::4326' + + 'image/tiff' + + 'ro_irra_ext' + + '' + + '' + +'' ); diff --git a/tests/lib/GeoExt/data/WFSCapabilitiesReader.html b/tests/lib/GeoExt/data/WFSCapabilitiesReader.html index def550e2..63e6809b 100644 --- a/tests/lib/GeoExt/data/WFSCapabilitiesReader.html +++ b/tests/lib/GeoExt/data/WFSCapabilitiesReader.html @@ -54,7 +54,7 @@ "[0] correct layer abstract" ); - //3 tests -- Testing the layer field (and its default protocol) + // 4 tests -- Testing the layer field (and its default protocol) var layer = record.getLayer(); t.eq(layer.CLASS_NAME, "OpenLayers.Layer.Vector", "[0] layer field is of type OpenLayers.Layer.Vector"); t.eq(layer.protocol.CLASS_NAME, "OpenLayers.Protocol.WFS.v1_0_0", "[0] protocol is of type OpenLayers.Protocol.WFS.v1_0_0"); diff --git a/tests/list-tests.html b/tests/list-tests.html index 721ab85a..aca397c4 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -14,6 +14,7 @@
  • lib/GeoExt/data/ProtocolProxy.html
  • lib/GeoExt/data/StyleReader.html
  • lib/GeoExt/data/WFSCapabilitiesReader.html
  • +
  • lib/GeoExt/data/WCSCapabilitiesReader.html
  • lib/GeoExt/data/WMSCapabilitiesReader.html
  • lib/GeoExt/data/WMSDescribeLayerReader.html
  • lib/GeoExt/data/WMCReader.html