[Commits] r1349 - in sandbox/camptocamp/geobretagne: lib lib/GeoExt/data tests tests/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Tue Sep 1 16:42:30 CEST 2009
Author: bbinet
Date: 2009-09-01 16:42:30 +0200 (Tue, 01 Sep 2009)
New Revision: 1349
Added:
sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMCReader.js
sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.html
Modified:
sandbox/camptocamp/geobretagne/lib/GeoExt.js
sandbox/camptocamp/geobretagne/tests/list-tests.html
Log:
apply patch patch_156-r1347-A0.diff from ticket http://trac.geoext.org/ticket/156
Added: sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMCReader.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMCReader.js (rev 0)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMCReader.js 2009-09-01 14:42:30 UTC (rev 1349)
@@ -0,0 +1,106 @@
+/**
+ * Copyright (c) 2008-2009 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/LayerRecord.js
+ */
+
+/** api: (define)
+ * module = GeoExt.data
+ * class = WMCReader
+ * base_link = `Ext.data.DataReader <http://extjs.com/deploy/dev/docs/?class=Ext.data.DataReader>`_
+ */
+Ext.namespace("GeoExt.data");
+
+/** api: constructor
+ * .. class:: WMCReader(meta, recordType)
+ *
+ * :param meta: ``Object`` Reader configuration.
+ * :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:`GeoExt.data.LayerRecord` objects from a WMS GetCapabilities
+ * response.
+ */
+GeoExt.data.WMCReader = function(meta, recordType) {
+ meta = meta || {};
+ if(!meta.format) {
+ meta.format = new OpenLayers.Format.WMC();
+ }
+ if(!(typeof recordType === "function")) {
+ 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"},
+ {name: "formats"}, // array
+ {name: "styles"} // array
+ ]
+ );
+ }
+ GeoExt.data.WMCReader.superclass.constructor.call(
+ this, meta, recordType
+ );
+};
+
+Ext.extend(GeoExt.data.WMCReader, 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) {
+ var format = this.meta.format;
+ if(typeof data === "string" || data.nodeType) {
+ data = format.read(data);
+ }
+ var records = [], layer, layerContext;
+
+ 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));
+ }
+
+ return {
+ totalRecords: records.length,
+ success: true,
+ records: records
+ };
+
+ }
+
+});
+
Modified: sandbox/camptocamp/geobretagne/lib/GeoExt.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt.js 2009-09-01 13:42:42 UTC (rev 1348)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt.js 2009-09-01 14:42:30 UTC (rev 1349)
@@ -80,6 +80,7 @@
"GeoExt/data/WMSDescribeLayerReader.js",
"GeoExt/data/WMSDescribeLayerStore.js",
"GeoExt/data/CSWRecordsReader.js",
+ "GeoExt/data/WMCReader.js",
"GeoExt/widgets/Action.js",
"GeoExt/data/ProtocolProxy.js",
"GeoExt/widgets/MapPanel.js",
Added: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.html (rev 0)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMCReader.html 2009-09-01 14:42:30 UTC (rev 1349)
@@ -0,0 +1,22 @@
+<!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>
+
+ <script type="text/javascript">
+
+ function test_constructor(t) {
+ t.plan(0);
+ }
+ function test_read(t) {
+ t.plan(0);
+ }
+ </script>
+ <body>
+ <div id="map"></div>
+ </body>
+</html>
Modified: sandbox/camptocamp/geobretagne/tests/list-tests.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/list-tests.html 2009-09-01 13:42:42 UTC (rev 1348)
+++ sandbox/camptocamp/geobretagne/tests/list-tests.html 2009-09-01 14:42:30 UTC (rev 1349)
@@ -13,6 +13,7 @@
<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>
<li>lib/GeoExt/widgets/MapPanel.html</li>
More information about the Commits
mailing list