[Commits] r227 - in sandbox/opengeo/alachua/lib: . GeoExt GeoExt/layer

commits at geoext.org commits at geoext.org
Mon Mar 16 21:57:07 CET 2009


Author: tcoulter
Date: 2009-03-16 21:57:07 +0100 (Mon, 16 Mar 2009)
New Revision: 227

Added:
   sandbox/opengeo/alachua/lib/GeoExt/layer/
   sandbox/opengeo/alachua/lib/GeoExt/layer/Vector.js
Modified:
   sandbox/opengeo/alachua/lib/GeoExt.js
Log:
Hook up highlighting with the feature store using GeoExt.layer.Vector. This require changes to Highlighter.js to remove adding/removing duties.

Added: sandbox/opengeo/alachua/lib/GeoExt/layer/Vector.js
===================================================================
--- sandbox/opengeo/alachua/lib/GeoExt/layer/Vector.js	                        (rev 0)
+++ sandbox/opengeo/alachua/lib/GeoExt/layer/Vector.js	2009-03-16 20:57:07 UTC (rev 227)
@@ -0,0 +1,75 @@
+Ext.namespace("GeoExt.layer");
+
+GeoExt.layer.Vector = new OpenLayers.Class(OpenLayers.Layer.Vector, {
+
+    /** 
+     * API Property: store
+     * A feature store that will be used to populate the features
+     * on this layer.
+     */
+    store: null,
+    
+    initialize: function() {
+        OpenLayers.Layer.Vector.prototype.initialize.apply(this, arguments);
+        
+        this.bindStore(this.store, true);
+    },
+    
+    /**
+     * 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.
+     */
+     bindStore : function(store, initial){
+        if(this.store && !initial){
+            this.store.un("clear", this.onClear, this);
+            this.store.un("load", this.onLoad, this);
+            this.store.un("loadexception", this.onLoadException, this);
+            this.store.un("add", this.onAdd, this);
+            this.store.un("remove", this.onRemove, this);
+        }
+        if(store){
+            this.store = Ext.StoreMgr.lookup(store);
+            this.store.on("clear", this.onClear, this);
+            this.store.on("load", this.onLoad, this);
+            this.store.on("loadexception", this.onLoadException, this);
+            this.store.on("add", this.onAdd, this);
+            this.store.on("remove", this.onRemove, this);
+        }
+    },
+    
+    onClear: function(store) {
+        alert('asdfads');
+        
+    },
+    
+    onLoad: function(store, options) {
+        //if (options.add == false) {
+            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, records, index) {
+        for (var index = 0; index < records.length; index++) {
+            this.removeFeatures(this.getFeatureFromRecord(records[index]));
+        }
+    },
+    
+    getFeatureFromRecord: function(record) {
+        return record.data.feature;
+    }
+});

Modified: sandbox/opengeo/alachua/lib/GeoExt.js
===================================================================
--- sandbox/opengeo/alachua/lib/GeoExt.js	2009-03-16 18:48:51 UTC (rev 226)
+++ sandbox/opengeo/alachua/lib/GeoExt.js	2009-03-16 20:57:07 UTC (rev 227)
@@ -79,6 +79,7 @@
             "GeoExt/data/LayerStoreMediator.js",
             "GeoExt/data/LayerStore.js",
             "GeoExt/data/ProtocolProxy.js",
+            "GeoExt/layer/Vector.js",
             "GeoExt/widgets/MapPanel.js"
         );
 



More information about the Commits mailing list