[Commits] r2865 - in core/trunk/geoext: lib/GeoExt/widgets tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Wed Nov 2 12:44:45 CET 2011
Author: bartvde
Date: 2011-11-02 12:44:45 +0100 (Wed, 02 Nov 2011)
New Revision: 2865
Modified:
core/trunk/geoext/lib/GeoExt/widgets/LayerLegend.js
core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js
core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html
Log:
Vectrorlegend causes error after removing vector layer, thanks chrismayer for the help, r=ahocevar (closes #451)
Modified: core/trunk/geoext/lib/GeoExt/widgets/LayerLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/LayerLegend.js 2011-10-27 14:34:18 UTC (rev 2864)
+++ core/trunk/geoext/lib/GeoExt/widgets/LayerLegend.js 2011-11-02 11:44:45 UTC (rev 2865)
@@ -65,9 +65,39 @@
if (this.layerRecord && this.layerRecord.store) {
this.layerStore = this.layerRecord.store;
this.layerStore.on("update", this.onStoreUpdate, this);
+ this.layerStore.on("add", this.onStoreAdd, this);
+ this.layerStore.on("remove", this.onStoreRemove, this);
}
},
+ /** private: method[onStoreRemove]
+ * Handler for remove event of the layerStore
+ *
+ * :param store: ``Ext.data.Store`` The store from which the record was
+ * removed.
+ * :param record: ``Ext.data.Record`` The record object corresponding
+ * to the removed layer.
+ * :param index: ``Integer`` The index in the store at which the record
+ * was remvoed.
+ */
+ onStoreRemove: function(store, record, index) {
+ // to be implemented by subclasses if needed
+ },
+
+ /** private: method[onStoreAdd]
+ * Handler for add event of the layerStore
+ *
+ * :param store: ``Ext.data.Store`` The store to which the record was
+ * added.
+ * :param record: ``Ext.data.Record`` The record object corresponding
+ * to the added layer.
+ * :param index: ``Integer`` The index in the store at which the record
+ * was added.
+ */
+ onStoreAdd: function(store, record, index) {
+ // to be implemented by subclasses if needed
+ },
+
/** private: method[onStoreUpdate]
* Update a the legend. Gets called when the store fires the update event.
* This usually means the visibility of the layer, its style or title
@@ -126,8 +156,11 @@
/** private: method[beforeDestroy]
*/
beforeDestroy: function() {
- this.layerStore &&
+ if (this.layerStore) {
this.layerStore.un("update", this.onStoreUpdate, this);
+ this.layerStore.un("remove", this.onStoreRemove, this);
+ this.layerStore.un("add", this.onStoreAdd, this);
+ }
GeoExt.LayerLegend.superclass.beforeDestroy.apply(this, arguments);
},
Modified: core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js 2011-10-27 14:34:18 UTC (rev 2864)
+++ core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js 2011-11-02 11:44:45 UTC (rev 2865)
@@ -141,6 +141,7 @@
if (this.layerRecord) {
this.layer = this.layerRecord.getLayer();
if (this.layer.map) {
+ this.map = this.layer.map;
this.currentScaleDenominator = this.layer.map.getScale();
this.layer.map.events.on({
"zoomend": this.onMapZoom,
@@ -652,12 +653,57 @@
}
}
delete this.layer;
+ delete this.map;
delete this.rules;
GeoExt.VectorLegend.superclass.beforeDestroy.apply(this, arguments);
+ },
+
+ /** private: method[onStoreRemove]
+ * Handler for remove event of the layerStore
+ *
+ * :param store: ``Ext.data.Store`` The store from which the record was
+ * removed.
+ * :param record: ``Ext.data.Record`` The record object corresponding
+ * to the removed layer.
+ * :param index: ``Integer`` The index in the store.
+ */
+ onStoreRemove: function(store, record, index) {
+ if (record.getLayer() === this.layer) {
+ if (this.map && this.map.events) {
+ this.map.events.un({
+ "zoomend": this.onMapZoom,
+ scope: this
+ });
}
+ }
+ },
+ /** private: method[onStoreAdd]
+ * Handler for add event of the layerStore
+ *
+ * :param store: ``Ext.data.Store`` The store to which the record was
+ * added.
+ * :param records: Array(``Ext.data.Record``) The record object(s) corresponding
+ * to the added layer(s).
+ * :param index: ``Integer`` The index in the store at which the record
+ * was added.
+ */
+ onStoreAdd: function(store, records, index) {
+ for (var i=0, len=records.length; i<len; i++) {
+ var record = records[i];
+ if (record.getLayer() === this.layer) {
+ if (this.layer.map && this.layer.map.events) {
+ this.layer.map.events.on({
+ "zoomend": this.onMapZoom,
+ scope: this
});
+ }
+ }
+ }
+ }
+});
+
/** private: method[supports]
* Private override
*/
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html 2011-10-27 14:34:18 UTC (rev 2864)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html 2011-11-02 11:44:45 UTC (rev 2865)
@@ -119,7 +119,44 @@
map.destroy();
}
+ function test_saferemove(t) {
+ t.plan(3);
+
+ var map = new OpenLayers.Map();
+ map.addLayer(new OpenLayers.Layer(null, {isBaseLayer: true}));
+ var layer = new OpenLayers.Layer.Vector("old");
+ map.addLayer(layer);
+ map.zoomToMaxExtent();
+
+ var store = new GeoExt.data.LayerStore({map: map});
+
+ var legend = new GeoExt.VectorLegend({
+ layerRecord: store.getAt(1),
+ renderTo: "legendpanel",
+ symbolType: "Point"
+ });
+
+ // remove vector layer from map
+ map.removeLayer(layer);
+
+ try {
+ map.zoomIn();
+ t.ok(true, "removing a vector layer does not cause problems");
+ } catch(err) {
+ t.fail("removing a vector layer causes problems: " + err);
+ }
+
+ t.ok(legend.currentScaleDenominator !== map.getScale(), "zoomend handler disconnected");
+
+ map.addLayer(layer);
+ map.zoomIn();
+ t.ok(legend.currentScaleDenominator === map.getScale(), "zoomend handler connected again");
+
+ legend.destroy();
+ map.destroy();
+ }
+
function test_createRuleRenderer(t) {
t.plan(2);
More information about the Commits
mailing list