[Commits] r168 - sandbox/opengeo/drake/trunk/core/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Fri Feb 13 23:54:58 CET 2009
Author: sbenthall
Date: 2009-02-13 23:54:58 +0100 (Fri, 13 Feb 2009)
New Revision: 168
Added:
sandbox/opengeo/drake/trunk/core/lib/GeoExt/data/FeatureStore.js
Log:
FeatureStore with layer factory first hacky draft
Added: sandbox/opengeo/drake/trunk/core/lib/GeoExt/data/FeatureStore.js
===================================================================
--- sandbox/opengeo/drake/trunk/core/lib/GeoExt/data/FeatureStore.js (rev 0)
+++ sandbox/opengeo/drake/trunk/core/lib/GeoExt/data/FeatureStore.js 2009-02-13 22:54:58 UTC (rev 168)
@@ -0,0 +1,115 @@
+Ext.namespace("GeoExt.data");
+
+GeoExt.data.FeatureStore = function(c) {
+ GeoExt.data.FeatureStore.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.FeatureReader(
+ c, c.fields || []
+ )
+ })
+ );
+};
+Ext.extend(GeoExt.data.FeatureStore, Ext.data.Store, {
+
+ //the constructor used by the createLayer method
+ layerConstructor : OpenLayers.Layer.Vector,
+
+ //a factory for creating a vector layer from this store
+ createLayer : function(name, layerConfig, options){
+
+ var layerConstructor = (options && options.layerConstructor) || this.layerConstructor;
+
+ var layer = new layerConstructor(name, layerConfig);
+
+ layer.store = this;
+
+ //should probably be in constructor
+ this.featureStoreMediator = new GeoExt.data.FeatureStoreMediator({
+ store: this
+ });
+
+ this.bindLayer(layer);
+
+
+
+ }
+
+ /**
+ * API Method: bindStore
+ * In the parlance of Ext, this function takes a store, removes listeners
+ * on the store that it already has (if any), then ads the appropriate
+ * listeners to the new store while replacing the old with the new.
+ */
+ bindLayer : function(layer, initial){
+ if(layer.store && !initial){
+ this.un("load", this.layerHandlers.onLoad, layer);
+ this.un("loadexception", this.layerHandlers.onLoadException, layer);
+ this.un("add", this.layerHandlers.onAdd, layer);
+ this.un("remove", this.layerHandlers.onRemove, layer);
+ }
+
+ this.store.on("load", this.layerHandlers.onLoad, layer);
+ this.store.on("loadexception", this.layerHandlers.onLoadException, layer);
+ this.store.on("add", this.layerHandlers.onAdd, layer);
+ this.store.on("remove", this.layerHandlers.onRemove, layer);
+
+ var updateStore = function(){
+ this.update(layer);
+ }
+
+ layer.events.on({
+ featuresadded: updateStore,
+ featuresremoved: updateStore,
+ featuremodified: updateStore,
+ scope: this
+ });
+
+ },
+
+ //contains handlers to be called in scope of created OpenLayers layer
+ layerHandlers : {
+ onLoad: function(store, options) {
+ this.removeFeatures(this.features);
+ store.each(function(record) {
+ this.addFeatures(this.getFeatureFromRecord(record));
+ }, this)
+ },
+
+ onLoadException: function() {
+ // To be overridden by subclasses.
+ },
+
+ onAdd: function(store, records, index) {
+ for (var index = 0; index < records.length; index++) {
+ this.addFeatures(this.getFeatureFromRecord(records[index]));
+ }
+ },
+
+ onRemove: function(store, record, index) {
+ this.removeFeatures(this.getFeatureFromRecord(record));
+ },
+
+ getFeatureFromRecord: function(record) {
+ return record.data.feature;
+ }
+ },
+
+ /**
+ * Method: update
+ * Called when features are added, removed or modified. This
+ * function empties the store, loops over the features in
+ * the layer, and for each feature calls the user-defined
+ * filter function, if the return value of the filter function
+ * evaluates to true the feature is added to the store.
+ */
+ update: function(layer) {
+ this.featureStoreMediator.addFeatures(
+ layer.features,
+ {append: false, filter: this.filter});
+ }
+});
More information about the Commits
mailing list