Skip to content

Create WCSCapabilitiesReader and WCSCapabilitiesStore #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/GeoExt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
121 changes: 121 additions & 0 deletions lib/GeoExt/data/WCSCapabilitiesReader.js
Original file line number Diff line number Diff line change
@@ -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 <http://dev.sencha.com/deploy/dev/docs/?class=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<lenI; i++) {
coverageSummary = contents[i];
var name = coverageSummary.identifier;

if(name) {
values = {};

for(var j=0, lenJ=fields.length; j<lenJ; j++) {
field = fields.items[j];
v = coverageSummary[field.mapping || field.name] ||
field.defaultValue;
v = field.convert(v);
values[field.name] = v;
}

records.push(new this.recordType(values, name));
}
}
return {
totalRecords: records.length,
success: true,
records: records
};
}
});
58 changes: 58 additions & 0 deletions lib/GeoExt/data/WCSCapabilitiesStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2008-2012 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.
*/

/**
* @include GeoExt/data/WCSCapabilitiesReader.js
*/

/** api: (define)
* module = GeoExt.data
* class = WCSCapabilitiesStore
* base_link = `Ext.data.Store <http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Store>`_
*/
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);
1 change: 1 addition & 0 deletions lib/GeoExt/data/WFSCapabilitiesReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
77 changes: 77 additions & 0 deletions tests/lib/GeoExt/data/WCSCapabilitiesReader.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html debug="true">
<head>
<script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>

<script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
<script type="text/javascript" src="../../../../lib/GeoExt.js"></script>

<!-- Define doc100 and doc110 that we will be testing below... here: -->
<script type="text/javascript" src="WCSCapabilitiesReader.js"></script>

<script type="text/javascript">

function test_constructor(t) {
t.plan(2);

var reader = new GeoExt.data.WCSCapabilitiesReader();

var fields = reader.recordType.prototype.fields;
// 1 test
// Test the default items enumerated in GeoExt.data.WCSCapabilitiesReader constructor
t.eq(fields.items.length, 3, 'number of default items is correct');

var reader = new GeoExt.data.WCSCapabilitiesReader({},[
{name: 'foo'},
{name: 'bar'}
]);

var fields = reader.recordType.prototype.fields;

//1 test
t.ok(fields.items[0].name == 'foo' &&
fields.items[1].name == 'bar',
'field values set from configuration are correct');
}

function test_read_1_0_0(t) {
t.plan(3);

var reader = new GeoExt.data.WCSCapabilitiesReader();

var records = reader.read({responseXML : doc100});

//1 test -- total number of records
t.eq(records.totalRecords, 4, 'readRecords returns correct number of records');

//2 tests -- testing the fields of a record
var record = records.records[0];

t.eq(record.get("name"), "ro_dsm", "correct layer name");
t.eq(record.get("title"), "Rotterdam DSM", "correct layer title");
}

function test_read_1_1_0(t) {
t.plan(4);

var reader = new GeoExt.data.WCSCapabilitiesReader();

var records = reader.read({responseXML : doc110});
//1 test -- total number of records
t.eq(records.totalRecords, 4, 'readRecords returns correct number of records');

//3 tests -- testing the fields of a record
var record = records.records[0];
t.eq(record.get("name"), "ro_dsm", "correct layer name");
t.eq(record.get("title"), "Rotterdam DSM", "correct layer title");
t.eq(record.get("abstract"),
"Digital Surface Model (DSM) raster data set of inner city Rotterdam",
"correct layer abstract"
);
}
</script>
<body>
<div id="map"></div>
</body>
</html>
Loading