[Commits] r1257 - in sandbox/opengeo/editor: . examples examples/data lib lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Tue Jul 14 23:47:21 CEST 2009
Author: tschaub
Date: 2009-07-14 23:47:21 +0200 (Tue, 14 Jul 2009)
New Revision: 1257
Added:
sandbox/opengeo/editor/examples/attributes.html
sandbox/opengeo/editor/examples/attributes.js
sandbox/opengeo/editor/examples/data/describe_feature_type.xml
sandbox/opengeo/editor/lib/GeoExt/data/AttributesReader.js
sandbox/opengeo/editor/lib/GeoExt/data/AttributesStore.js
sandbox/opengeo/editor/modifications.txt
Modified:
sandbox/opengeo/editor/lib/GeoExt.js
Log:
Adding attributes reader and store (#17).
Added: sandbox/opengeo/editor/examples/attributes.html
===================================================================
--- sandbox/opengeo/editor/examples/attributes.html (rev 0)
+++ sandbox/opengeo/editor/examples/attributes.html 2009-07-14 21:47:21 UTC (rev 1257)
@@ -0,0 +1,23 @@
+<html>
+ <head>
+ <title>GeoExt AttributesReader and AttributesStore</title>
+
+ <script type="text/javascript" src="http://extjs.cachefly.net/builds/ext-cdn-771.js"></script>
+ <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
+ <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/examples/shared/examples.css" />
+ <script src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
+ <script type="text/javascript" src="../lib/GeoExt.js"></script>
+
+ <script type="text/javascript" src="attributes.js"></script>
+
+ </head>
+ <body>
+ <h1>AttributesReader and AttributesStore</h1>
+ <p>This is example that shows how create an AttributesStore with
+ records read from a WFS DescribeFeatureType response.</p>
+
+ <p>Note that the js is not minified so it is readable.
+ See <a href="attributes.js">attributes.js</a>.</p>
+
+ </body>
+</html>
Added: sandbox/opengeo/editor/examples/attributes.js
===================================================================
--- sandbox/opengeo/editor/examples/attributes.js (rev 0)
+++ sandbox/opengeo/editor/examples/attributes.js 2009-07-14 21:47:21 UTC (rev 1257)
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+
+var store;
+Ext.onReady(function() {
+
+ // create a new attributes store
+ store = new GeoExt.data.AttributesStore({
+ url: "data/describe_feature_type.xml"
+ });
+ store.load();
+
+ // create a grid to display records from the store
+ var grid = new Ext.grid.GridPanel({
+ title: "Feature Attributes",
+ store: store,
+ cm: new Ext.grid.ColumnModel([
+ {id: "name", header: "Name", dataIndex: "name", sortable: true},
+ {id: "type", header: "Type", dataIndex: "type", sortable: true}
+ ]),
+ sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
+ autoExpandColumn: "name",
+ renderTo: document.body,
+ height: 300,
+ width: 350
+ });
+
+});
Added: sandbox/opengeo/editor/examples/data/describe_feature_type.xml
===================================================================
--- sandbox/opengeo/editor/examples/data/describe_feature_type.xml (rev 0)
+++ sandbox/opengeo/editor/examples/data/describe_feature_type.xml 2009-07-14 21:47:21 UTC (rev 1257)
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><xs:schema targetNamespace="http://www.openplans.org/topp" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0"><xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2.1/feature.xsd"/><xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" name="states_Type"><xs:complexContent><xs:extension base="gml:AbstractFeatureType"><xs:sequence><xs:element name="the_geom" minOccurs="0" nillable="true" type="gml:MultiPolygonPropertyType"/><xs:element name="STATE_NAME" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="2147483647"/></xs:restriction></xs:simpleType></xs:element><xs:element name="STATE_FIPS" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="2147483647"/></xs:restriction></xs:simpleType></xs:element><xs:element name="SUB_REGION" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="2147483647"/></xs:restriction></xs:simpleType></xs:element><xs:element name="STATE_ABBR" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="2147483647"/></xs:restriction></xs:simpleType></xs:element><xs:element name="LAND_KM" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="WATER_KM" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="PERSONS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="FAMILIES" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="HOUSHOLD" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="MALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="FEMALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="WORKERS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="DRVALONE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="CARPOOL" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="PUBTRANS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="EMPLOYED" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="UNEMPLOY" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="SERVICE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="MANUAL" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="P_MALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="P_FEMALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="SAMP_POP" minOccurs="0" nillable="true" type="xs:double"/></xs:sequence></xs:extension></xs:complexContent></xs:complexType><xs:element name="states" type="topp:states_Type" substitutionGroup="gml:_Feature"/></xs:schema>
\ No newline at end of file
Added: sandbox/opengeo/editor/lib/GeoExt/data/AttributesReader.js
===================================================================
--- sandbox/opengeo/editor/lib/GeoExt/data/AttributesReader.js (rev 0)
+++ sandbox/opengeo/editor/lib/GeoExt/data/AttributesReader.js 2009-07-14 21:47:21 UTC (rev 1257)
@@ -0,0 +1,135 @@
+/**
+ * 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.
+ */
+
+/** api: (define)
+ * module = GeoExt.data
+ * class = AttributesReader
+ * base_link = `Ext.data.DataReader <http://extjs.com/deploy/dev/docs/?class=Ext.data.DataReader>`_
+ */
+Ext.namespace("GeoExt.data");
+
+/**
+ * Class: GeoExt.data.AttributesReader
+ * Data reader class to provide an array of {Ext.data.Record} objects given
+ * a WFS DescribeFeatureType response for use by an {Ext.data.Store}
+ * object.
+ *
+ * Extends: Ext.data.DataReader
+ */
+
+/**
+ * Constructor: GeoExt.data.AttributesReader
+ * Create a new attributes reader object.
+ *
+ * Parameters:
+ * meta - {Object} Reader configuration.
+ * recordType - {Array | Ext.data.Record} An array of field configuration
+ * objects or a record object.
+ *
+ * Configuration options (meta properties):
+ * format - {OpenLayers.Format} A parser for transforming the XHR response
+ * into an array of objects representing attributes. Defaults to
+ * an {OpenLayers.Format.WFSDescribeFeatureType} parser.
+ * ignore - {Object} Properties of the ignore object should be field names.
+ * Values are either arrays or regular expressions.
+ */
+GeoExt.data.AttributesReader = function(meta, recordType) {
+ meta = meta || {};
+ if(!meta.format) {
+ meta.format = new OpenLayers.Format.WFSDescribeFeatureType();
+ }
+ GeoExt.data.AttributesReader.superclass.constructor.call(
+ this, meta, recordType || meta.fields
+ );
+};
+
+Ext.extend(GeoExt.data.AttributesReader, Ext.data.DataReader, {
+
+ /**
+ * Method: read
+ * This method is only used by a DataProxy which has retrieved data from a
+ * remote server.
+ *
+ * Parameters:
+ * request - {Object} The XHR object which contains the parsed XML
+ * document.
+ *
+ * Returns:
+ * {Object} A data block which is used by an {Ext.data.Store} as a cache
+ * of Ext.data.Records.
+ */
+ read: function(request) {
+ var data = request.responseXML;
+ if(!data || !data.documentElement) {
+ data = request.responseText;
+ }
+ return this.readRecords(data);
+ },
+
+ /**
+ * Method: readRecords
+ * Create a data block containing Ext.data.Records from an XML document.
+ *
+ * Parameters:
+ * data - {DOMElement | String | Array} A document element or XHR response
+ * string. As an alternative to fetching attributes data from a remote
+ * source, an array of attribute objects can be provided given that
+ * the properties of each attribute object map to a provided field name.
+ *
+ * Returns:
+ * {Object} A data block which is used by an {Ext.data.Store} as a cache of
+ * Ext.data.Records.
+ */
+ readRecords: function(data) {
+ var attributes;
+ if(data instanceof Array) {
+ attributes = data;
+ } else {
+ // only works with one featureType in the doc
+ attributes = this.meta.format.read(data).featureTypes[0].properties;
+ }
+ var recordType = this.recordType;
+ var fields = recordType.prototype.fields;
+ var numFields = fields.length;
+ var attr, values, name, record, ignore, matches, value, records = [];
+ for(var i=0, len=attributes.length; i<len; ++i) {
+ ignore = false;
+ attr = attributes[i];
+ values = {};
+ for(var j=0; j<numFields; ++j) {
+ name = fields.items[j].name;
+ value = attr[name];
+ if(this.meta.ignore && this.meta.ignore[name]) {
+ matches = this.meta.ignore[name];
+ if(typeof matches == "string") {
+ ignore = (matches === value);
+ } else if(matches instanceof Array) {
+ ignore = (matches.indexOf(value) > -1);
+ } else if (matches instanceof RegExp) {
+ ignore = (matches.test(value));
+ }
+ if(ignore) {
+ break;
+ }
+ }
+ values[name] = attr[name];
+ }
+ if(!ignore) {
+ records[records.length] = new recordType(values);
+ }
+ }
+
+ return {
+ success: true,
+ records: records,
+ totalRecords: records.length
+ };
+
+ }
+
+});
\ No newline at end of file
Added: sandbox/opengeo/editor/lib/GeoExt/data/AttributesStore.js
===================================================================
--- sandbox/opengeo/editor/lib/GeoExt/data/AttributesStore.js (rev 0)
+++ sandbox/opengeo/editor/lib/GeoExt/data/AttributesStore.js 2009-07-14 21:47:21 UTC (rev 1257)
@@ -0,0 +1,62 @@
+/**
+ * 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/AttributesReader.js
+ */
+
+/** api: (define)
+ * module = GeoExt.data
+ * class = WMSCapabilitiesStore
+ * base_link = `Ext.data.DataStore <http://extjs.com/deploy/dev/docs/?class=Ext.data.DataStore>`_
+ */
+Ext.namespace("GeoExt.data");
+
+/**
+ * Class: GeoExt.data.AttributesStore
+ * Small helper class to make creating stores for remotely-loaded attributes
+ * data easier. AttributesStore is pre-configured with a built-in
+ * {Ext.data.HttpProxy} and {GeoExt.data.AttributesReader}. The HttpProxy
+ * is configured to allow caching (disableCaching: false) and uses GET.
+ * If you require some other proxy/reader combination then you'll have to
+ * configure this with your own proxy or create a basic Ext.data.Store
+ * and configure as needed.
+ *
+ * Extends: Ext.data.Store
+ */
+
+/**
+ * Constructor: GeoExt.data.AttributesStore
+ * Create a new attributes store object.
+ *
+ * Parameters:
+ * config - {Object} Store configuration.
+ *
+ * Configuration options:
+ * format - {OpenLayers.Format} A parser for transforming the XHR response into
+ * an array of objects representing attributes. Defaults to an
+ * {OpenLayers.Format.WFSDescribeFeatureType} parser.
+ * 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.AttributesStore = function(c) {
+ GeoExt.data.AttributesStore.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.AttributesReader(
+ c, c.fields || ["name", "type"]
+ )
+ })
+ );
+};
+Ext.extend(GeoExt.data.AttributesStore, Ext.data.Store);
\ No newline at end of file
Modified: sandbox/opengeo/editor/lib/GeoExt.js
===================================================================
--- sandbox/opengeo/editor/lib/GeoExt.js 2009-07-14 21:25:52 UTC (rev 1256)
+++ sandbox/opengeo/editor/lib/GeoExt.js 2009-07-14 21:47:21 UTC (rev 1257)
@@ -64,6 +64,8 @@
*/
if(!singleFile) {
var jsfiles = new Array(
+ "GeoExt/data/AttributesReader.js",
+ "GeoExt/data/AttributesStore.js",
"GeoExt/data/FeatureRecord.js",
"GeoExt/data/FeatureReader.js",
"GeoExt/data/FeatureStore.js",
Added: sandbox/opengeo/editor/modifications.txt
===================================================================
--- sandbox/opengeo/editor/modifications.txt (rev 0)
+++ sandbox/opengeo/editor/modifications.txt 2009-07-14 21:47:21 UTC (rev 1257)
@@ -0,0 +1,4 @@
+This sandbox is a copy of the trunk. All modifications should be listed with
+ticket number here.
+
+#17: attributes reader and store
More information about the Commits
mailing list