[Commits] r221 - in sandbox/opengeo/alachua: examples examples/data lib lib/GeoExt/data tests tests/data
commits at geoext.org
commits at geoext.org
Fri Mar 13 19:56:37 CET 2009
Author: sbenthall
Date: 2009-03-13 19:56:37 +0100 (Fri, 13 Mar 2009)
New Revision: 221
Added:
sandbox/opengeo/alachua/examples/data/
sandbox/opengeo/alachua/examples/data/summits.json
sandbox/opengeo/alachua/examples/feature-grid.html
sandbox/opengeo/alachua/lib/GeoExt/data/FeatureStore.js
sandbox/opengeo/alachua/tests/data/FeatureStore.html
Modified:
sandbox/opengeo/alachua/lib/GeoExt.js
sandbox/opengeo/alachua/tests/list-tests.html
Log:
Patching with FeatureStore patch from #18
Added: sandbox/opengeo/alachua/examples/data/summits.json
===================================================================
--- sandbox/opengeo/alachua/examples/data/summits.json (rev 0)
+++ sandbox/opengeo/alachua/examples/data/summits.json 2009-03-13 18:56:37 UTC (rev 221)
@@ -0,0 +1 @@
+{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [6.18218, 45.5949]}, "type": "Feature", "properties": {"elevation": 1770, "name": "Col d'Arclusaz"}, "id": 472}, {"geometry": {"type": "Point", "coordinates": [6.27827, 45.6769]}, "type": "Feature", "properties": {"elevation": 1831, "name": "Pointe de C\u00f4te Favre"}, "id": 458}, {"geometry": {"type": "Point", "coordinates": [6.47122, 46.0062]}, "type": "Feature", "properties": {"elevation": 2364, "name": "Pointe du Midi"}, "id": 487}, {"geometry": {"type": "Point", "coordinates": [6.82156068193, 46.3129835428]}, "type": "Feature", "properties": {"elevation": 1856, "name": "Col d'Outanne"}, "id": 5700}, {"geometry": {"type": "Point", "coordinates": [6.84989241629, 46.136626095]}, "type": "Feature", "properties": {"elevation": 2375, "name": "Col de Comba Mornay"}, "id": 5644}, {"geometry": {"type": "Point", "coordinates": [6.62, 46.187778]}, "type": "Feature", "properties": {"elevation": 2000, "name": "La Pointe"}, "id": 5710}, {"geometry": {"type": "Point", "coordinates": [5.9134, 44.93331]}, "type": "Feature", "properties": {"elevation": 2607, "name": "Le Coiro"}, "id": 496}, {"geometry": {"type": "Point", "coordinates": [6.03219, 45.7204]}, "type": "Feature", "properties": {"elevation": 1451, "name": "D\u00f4me de la Cochette"}, "id": 322}, {"geometry": {"type": "Point", "coordinates": [6.23048, 45.6324]}, "type": "Feature", "properties": {"elevation": 2197, "name": "Mont P\u00e9cloz"}, "id": 515}, {"geometry": {"type": "Point", "coordinates": [6.1962, 45.6927]}, "type": "Feature", "properties": {"elevation": 2181, "name": "Tr\u00e9lod"}, "id": 601}]}
\ No newline at end of file
Added: sandbox/opengeo/alachua/examples/feature-grid.html
===================================================================
--- sandbox/opengeo/alachua/examples/feature-grid.html (rev 0)
+++ sandbox/opengeo/alachua/examples/feature-grid.html 2009-03-13 18:56:37 UTC (rev 221)
@@ -0,0 +1,71 @@
+<html>
+<head>
+ <title>Feature Grid</title>
+
+ <link rel="stylesheet" type="text/css" href="../../../ext/2.2/resources/css/ext-all.css"></link>
+
+ <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script>
+
+ <script type="text/javascript" src="../../../ext/2.2/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../ext/2.2/ext-all-debug.js"></script>
+
+ <script type="text/javascript" src="../lib/GeoExt/data/FeatureReader.js"></script>
+ <script type="text/javascript" src="../lib/GeoExt/data/FeatureStore.js"></script>
+ <script type="text/javascript" src="../lib/GeoExt/data/ProtocolProxy.js"></script>
+
+ <script>
+
+ Ext.BLANK_IMAGE_URL = "../../../ext/2.2/resources/images/default/s.gif"
+
+ var store, grid;
+
+ Ext.onReady(function() {
+ store = new GeoExt.data.FeatureStore({
+ fields: [
+ {name: 'name', type: 'string'},
+ {name: 'elevation', type: 'float'}
+ ],
+ proxy: new GeoExt.data.ProtocolProxy({
+ protocol: new OpenLayers.Protocol.HTTP({
+ url: "data/summits.json",
+ format: new OpenLayers.Format.GeoJSON()
+ })
+ }),
+ autoLoad: true
+ });
+ grid = new Ext.grid.GridPanel({
+ store: store,
+ height: 250,
+ width: 320,
+ columns: [{
+ header: "Name",
+ width: 200,
+ dataIndex: "name"
+ }, {
+ header: "Elevation",
+ width: 100,
+ dataIndex: "elevation"
+ }],
+ renderTo: "grid"
+ });
+ });
+ </script>
+</head>
+
+<body>
+ <h2>Feature Grid</h2>
+
+ <div id="grid" style="width:350px; height:260px; margin-top:10px"></div>
+
+ <p>
+
+ This example shows an Ext grid loaded with features read from a GeoJSON
+ document (data/summits.json). The components used in this example are
+ <code>GeoExt.data.FeatureStore</code>,
+ <code>GeoExt.data.FeatureReader</code> and
+ <code>GeoExt.data.ProtocolProxy</code>.
+
+ </p>
+
+</body>
+</html>
Property changes on: sandbox/opengeo/alachua/examples/feature-grid.html
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: sandbox/opengeo/alachua/lib/GeoExt/data/FeatureStore.js
===================================================================
--- sandbox/opengeo/alachua/lib/GeoExt/data/FeatureStore.js (rev 0)
+++ sandbox/opengeo/alachua/lib/GeoExt/data/FeatureStore.js 2009-03-13 18:56:37 UTC (rev 221)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2009 Eric Lemoine, Camptocamp France SAS
+ *
+ * This file is part of GeoExt
+ *
+ * GeoExt is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GeoExt is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GeoExt. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @requires GeoExt/data/FeatureReader.js
+ */
+
+Ext.namespace('GeoExt', 'GeoExt.data');
+
+/**
+ * Class: GeoExt.data.FeatureStore
+ * Helper class to ease creating stores of features. An instance of this
+ * class is pre-configured with a <GeoExt.data.FeatureReader>.
+ *
+ * Typical usage in a store:
+ * (start code)
+ * var store = new Ext.data.FeatureStore({
+ * fields: [
+ * {name: 'name', type: 'string'},
+ * {name: 'elevation', type: 'float'}
+ * ]
+ * });
+ * store.loadData(features);
+ * (end)
+ *
+ * Inherits from:
+ * - {Ext.data.Store}
+ */
+
+/**
+ * Constructor: GeoExt.data.FeatureStore
+ * Create a feature store, the config object can receive any config
+ * options of the parent class, {Ext.data.Store}, in addtion the
+ * the config object must include a "fields" property referencing an Array
+ * of field definition objects as passed to Ext.data.Record.create, or a
+ * Record constructor created using Ext.data.Record.create.
+ *
+ * Parameters:
+ * config {Object} The config object.
+ *
+ * Returns:
+ * {<GeoExt.data.FeatureStore>} The feature store.
+ */
+GeoExt.data.FeatureStore = function(config) {
+ GeoExt.data.FeatureStore.superclass.constructor.call(this,
+ Ext.apply(config, {
+ reader: new GeoExt.data.FeatureReader(
+ config, config.fields
+ )
+ })
+ );
+};
+Ext.extend(GeoExt.data.FeatureStore, Ext.data.Store, {
+ /**
+ * APIProperty: fields
+ * {Object} An Array of field definition objects as passed to
+ * Ext.data.Record.create, or a Record constructor created using
+ * Ext.data.Record.create.
+ */
+ fields: null
+});
Modified: sandbox/opengeo/alachua/lib/GeoExt.js
===================================================================
--- sandbox/opengeo/alachua/lib/GeoExt.js 2009-03-13 18:51:27 UTC (rev 220)
+++ sandbox/opengeo/alachua/lib/GeoExt.js 2009-03-13 18:56:37 UTC (rev 221)
@@ -74,6 +74,7 @@
if(!singleFile) {
var jsfiles = new Array(
"GeoExt/data/FeatureReader.js",
+ "GeoExt/data/FeatureStore.js",
"GeoExt/data/FeatureStoreMediator.js",
"GeoExt/data/LayerStoreMediator.js",
"GeoExt/data/LayerStore.js",
Added: sandbox/opengeo/alachua/tests/data/FeatureStore.html
===================================================================
--- sandbox/opengeo/alachua/tests/data/FeatureStore.html (rev 0)
+++ sandbox/opengeo/alachua/tests/data/FeatureStore.html 2009-03-13 18:56:37 UTC (rev 221)
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html debug="true">
+ <head>
+ <script type="text/javascript" src="../../../../ext/2.2/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../../ext/2.2/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(2);
+ var store = new GeoExt.data.FeatureStore({
+ fields: [
+ {'name': 'foo'},
+ {'name': 'bar'}
+ ]
+ });
+ var fields = store.reader.recordType.prototype.fields;
+ // 2 tests
+ t.eq(fields.items.length, 2, 'number of items is correct');
+ t.ok(fields.items[0].name == 'foo' &&
+ fields.items[1].name == 'bar',
+ 'field values are correct');
+ }
+ function test_manipulateData(t) {
+ t.plan(4);
+ // setup
+ var store, features, records;
+ store = new GeoExt.data.FeatureStore({
+ fields: [
+ {'name': 'foo'},
+ {'name': 'bar'}
+ ]
+ });
+ features = [
+ new OpenLayers.Feature.Vector(null, {
+ 'foo': 'foo_0',
+ 'bar': 'bar_0'
+ }),
+ new OpenLayers.Feature.Vector()
+ ];
+ features[0].fid = 1;
+ features[0].state = OpenLayers.State.INSERT;
+ features[1].fid = 2;
+ features[1].state = OpenLayers.State.DELETE;
+ // 1 test
+ store.loadData(features);
+ t.eq(store.getCount(), 2, 'loadData loads expected number of records');
+ // 1 test
+ store.removeAll();
+ t.eq(store.getCount(), 0, 'removeAll empties store');
+ // 2 tests
+ store.loadData(features);
+ store.filterBy(function(record) {
+ return record.get("fid") == 1;
+ });
+ t.eq(store.getCount(), 1, 'loadData loads expected number of records');
+ t.ok(store.getById(features[0].id) !== undefined,
+ 'loadData loads expected feature when filter is applied');
+ }
+ </script>
+
+ <body>
+ <div id="map"></div>
+ </body>
+</html>
Property changes on: sandbox/opengeo/alachua/tests/data/FeatureStore.html
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: sandbox/opengeo/alachua/tests/list-tests.html
===================================================================
--- sandbox/opengeo/alachua/tests/list-tests.html 2009-03-13 18:51:27 UTC (rev 220)
+++ sandbox/opengeo/alachua/tests/list-tests.html 2009-03-13 18:56:37 UTC (rev 221)
@@ -1,5 +1,6 @@
<ul id="testlist">
<li>data/FeatureReader.html</li>
+ <li>data/FeatureStore.html</li>
<li>data/FeatureStoreMediator.html</li>
<li>data/LayerStore.html</li>
<li>data/LayerStoreMediator.html</li>
More information about the Commits
mailing list