[Commits] r2771 - sandbox/gxm/geoext/gxm/lib/GXM/widgets
commits at geoext.org
commits at geoext.org
Sat Jul 23 23:54:52 CEST 2011
Author: marcjansen
Date: 2011-07-23 23:54:52 +0200 (Sat, 23 Jul 2011)
New Revision: 2771
Modified:
sandbox/gxm/geoext/gxm/lib/GXM/widgets/MapPanel.js
Log:
[gxm] improve layer syncing on layer removal or adding, respect user configuration and adding API docs
Modified: sandbox/gxm/geoext/gxm/lib/GXM/widgets/MapPanel.js
===================================================================
--- sandbox/gxm/geoext/gxm/lib/GXM/widgets/MapPanel.js 2011-07-22 15:01:03 UTC (rev 2770)
+++ sandbox/gxm/geoext/gxm/lib/GXM/widgets/MapPanel.js 2011-07-23 21:54:52 UTC (rev 2771)
@@ -48,8 +48,37 @@
*/
//TODO: rename to GXM.Map, since this is not a Panel
GXM.MapPanel = Ext.extend(Ext.Component, {
+ /** api: config[map]
+ * ``OpenLayers.Map or Object`` A configured map or a configuration object
+ * for the map constructor. A configured map will be available after
+ * construction through the :attr:`map` property.
+ */
+
+ /** api: property[map]
+ * ``OpenLayers.Map`` or ``Object`` A map or map configuration.
+ */
map: null,
+
+ /** api: config[layers]
+ * ``GeoExt.data.LayerStore or GeoExt.data.GroupingStore or Array(OpenLayers.Layer)``
+ * A store holding records. The layers provided here will be added to this
+ * MapPanel's map when it is rendered.
+ */
+
+ /** api: property[layers]
+ * :class:`GXM.data.LayerStore` A store containing gxm_layer-model
+ * instances.
+ */
+ layers: null,
+
+ /** api: config[center]
+ * ``OpenLayers.LonLat or Array(Number)`` A location for the initial map
+ * center. If an array is provided, the first two items should represent
+ * x & y coordinates.
+ */
center: null,
+
+
zoom: null,
bounds: null,
//TODO: do we really wish to have this fullscreen?
@@ -67,28 +96,34 @@
initComponent: function(){
// set scroll to false just as the original Map-component of
// Sencha Touch does (Review BvdE).
- //this.scroll = false;
+ this.scroll = false;
// check config-property map for an existing OpenLayers.Map-instance, a
// conf object for an OpenLayers.Map or null
if ( !(this.map instanceof OpenLayers.Map) ) {
- this.controls = this.defaultControls;
var mapConf = Ext.applyIf(this.map || {}, {
allOverlays: true,
- controls: this.getDefaultControls()
+ controls: this.initialConfig.controls || this.getDefaultControls()
});
this.map = new OpenLayers.Map(mapConf);
+ } else {
+ // add any additionally configured controls:
+ if (this.initialConfig.controls) {
+ this.map.addControls(this.initialConfig.controls);
+ }
}
- // this.map is now initialized in any case
+ // this.map is now initialized in any case and has needed and
+ // configured controls
-
-
// check config-property layers for any layers to be added to the map
if ( this.layers ) {
// normalize the case where this.layers was not an array but a layer
if(this.layers instanceof OpenLayers.Layer) {
this.layers = [this.layers];
}
+
+ //TODO: this possibly requests data from the layers to early
+ // we might move this e.g. to the renderMap-method
this.map.addLayers(this.layers);
}
@@ -112,6 +147,7 @@
this.center = OpenLayers.LonLat.fromString(this.center);
} else if(Ext.isArray(this.center)) {
//TODO: this method does not exist. but IMO should
+ // see: http://trac.osgeo.org/openlayers/ticket/3433
// this.center = OpenLayers.LonLat.fromArray(this.center);
this.center = new OpenLayers.LonLat(this.center[0], this.center[1]);
}
@@ -124,6 +160,7 @@
this.extent = OpenLayers.Bounds.fromArray(this.extent);
}
GXM.MapPanel.superclass.initComponent.call(this);
+
// events
this.addEvents(
/** private: event[aftermapmove]
@@ -201,30 +238,14 @@
/** private: method[onAddlayer]
*/
onAddlayer: function() {
-
- //CM
- // update the layerstore by creating a new one
- // with the current maps layers
- //TODO: sync?
- this.layers = new GXM.data.LayerStore({
- data: this.map.layers
- });
-
+ this.layers.load();
this.fireEvent("afterlayeradd");
},
/** private: method[onRemovelayer]
*/
onRemovelayer: function() {
-
- //CM
- // update the layerstore by creating a new one
- // with the current maps layers
- //TODO: sync?
- this.layers = new GXM.data.LayerStore({
- data: this.map.layers
- });
-
+ this.layers.load();
this.fireEvent("afterlayerremove");
},
@@ -273,7 +294,8 @@
}else {
map.zoomToMaxExtent();
}
- }
+ }
+
},
//TODO: check if we need this
updateMapSize: function() {
More information about the Commits
mailing list