[Commits] r241 - in sandbox/elemoine/playground: . examples lib lib/GeoExt/data lib/GeoExt/widgets tests tests/data tests/widgets

commits at geoext.org commits at geoext.org
Sun Mar 22 14:40:59 CET 2009


Author: elemoine
Date: 2009-03-22 14:40:59 +0100 (Sun, 22 Mar 2009)
New Revision: 241

Modified:
   sandbox/elemoine/playground/examples/mappanel-div.html
   sandbox/elemoine/playground/examples/mappanel-window.html
   sandbox/elemoine/playground/lib/GeoExt.js
   sandbox/elemoine/playground/lib/GeoExt/data/LayerRecord.js
   sandbox/elemoine/playground/lib/GeoExt/data/LayerStore.js
   sandbox/elemoine/playground/lib/GeoExt/widgets/MapPanel.js
   sandbox/elemoine/playground/license.txt
   sandbox/elemoine/playground/tests/data/LayerRecord.html
   sandbox/elemoine/playground/tests/data/LayerStore.html
   sandbox/elemoine/playground/tests/list-tests.html
   sandbox/elemoine/playground/tests/widgets/MapPanel.html
Log:
svn merge -r189:HEAD http://www.geoext.org/svn/geoext/core/trunk ./


Modified: sandbox/elemoine/playground/examples/mappanel-div.html
===================================================================
--- sandbox/elemoine/playground/examples/mappanel-div.html	2009-03-22 13:39:39 UTC (rev 240)
+++ sandbox/elemoine/playground/examples/mappanel-div.html	2009-03-22 13:40:59 UTC (rev 241)
@@ -0,0 +1,59 @@
+<html>
+  <head>
+    <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script>
+    <script type="text/javascript" src="../../../ext/2.2.1/adapter/ext/ext-base.js"></script>
+    <script type="text/javascript" src="../../../ext/2.2.1/ext-all-debug.js"></script>
+    <script type="text/javascript" src="../lib/GeoExt.js"></script>
+
+    <link rel="stylesheet" type="text/css" href="../../../ext/2.2.1/resources/css/ext-all.css"></link>
+
+    <script type="text/javascript">
+
+    // this example shows the OpenLayerish way to create a map panel. See
+    // mappanel-window.html for the ExtJSish way to do the same.
+
+    var mapPanel;
+    
+    Ext.onReady(function() {
+        var map = new OpenLayers.Map();
+        var layer = new OpenLayers.Layer.WMS(
+            "bluemarble",
+            "http://sigma.openplans.org/geoserver/wms?",
+            {layers: 'bluemarble'}
+        );
+        map.addLayer(layer);
+
+        mapPanel = new GeoExt.MapPanel({
+            title: "GeoExt MapPanel",
+            renderTo: "mappanel",
+            height: 400,
+            width: 600,
+            map: map,
+            center: new OpenLayers.LonLat(5, 45),
+            zoom: 4
+        });
+    });
+
+    // functions for resizing the map panel
+    function mapSizeUp() {
+        var size = mapPanel.getSize();
+        size.width += 40;
+        size.height += 40;
+        mapPanel.setSize(size);
+    }
+    function mapSizeDown() {
+        var size = mapPanel.getSize();
+        size.width -= 40;
+        size.height -= 40;
+        mapPanel.setSize(size);
+    }
+
+    </script>
+        
+  </head>
+  <body>
+    <div id="mappanel"></div>
+    <input type="button" onclick="mapSizeUp()" value="bigger"></input>
+    <input type="button" onclick="mapSizeDown()" value="smaller"></input>
+  </body>
+</html>


Property changes on: sandbox/elemoine/playground/examples/mappanel-div.html
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: sandbox/elemoine/playground/examples/mappanel-window.html
===================================================================
--- sandbox/elemoine/playground/examples/mappanel-window.html	2009-03-22 13:39:39 UTC (rev 240)
+++ sandbox/elemoine/playground/examples/mappanel-window.html	2009-03-22 13:40:59 UTC (rev 241)
@@ -0,0 +1,41 @@
+<html>
+  <head>
+    <link rel="stylesheet" type="text/css" href="../../../ext/2.2.1/resources/css/ext-all.css"></link>
+    <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script>
+    <script type="text/javascript" src="../../../ext/2.2.1/adapter/ext/ext-base.js"></script>
+    <script type="text/javascript" src="../../../ext/2.2.1/ext-all-debug.js"></script>
+    <script type="text/javascript" src="../lib/GeoExt.js"></script>
+
+    <script type="text/javascript">
+
+    // this example shows the Extish way to create a map panel. See
+    // mappanel-div.html for the OpenLayerish way to do the same.
+    
+    var mapPanel;
+    
+    Ext.onReady(function() {
+        new Ext.Window({
+            title: "GeoExt MapPanel Window",
+            height: 400,
+            width: 600,
+            layout: "fit",
+            items: [{
+                xtype: "gx_mappanel",
+                id: "mappanel",
+                layers: [new OpenLayers.Layer.WMS(
+                    "bluemarble",
+                    "http://sigma.openplans.org/geoserver/wms?",
+                    {layers: 'bluemarble'}
+                )],
+                extent: "-5,35,15,55"
+            }]
+        }).show();
+        
+        mapPanel = Ext.getCmp("mappanel");
+    });
+
+    </script>
+  </head>
+  <body>
+  </body>
+</html>


Property changes on: sandbox/elemoine/playground/examples/mappanel-window.html
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: sandbox/elemoine/playground/lib/GeoExt/data/LayerRecord.js
===================================================================
--- sandbox/elemoine/playground/lib/GeoExt/data/LayerRecord.js	2009-03-22 13:39:39 UTC (rev 240)
+++ sandbox/elemoine/playground/lib/GeoExt/data/LayerRecord.js	2009-03-22 13:40:59 UTC (rev 241)
@@ -0,0 +1,69 @@
+/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation ¹
+ * Published under the BSD license.
+ * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
+ * of the license.
+ * 
+ * ¹ pending approval */
+
+Ext.namespace("GeoExt.data");
+
+/**
+ * Class: GeoExt.data.LayerRecord
+ * A subclass of {Ext.data.Record} which provides a special record that
+ * represents an {OpenLayers.Layer}. This record will always have at least a
+ * layer and a title field in its data. The id of this record will be the same
+ * as the id of the layer it represents.
+ * 
+ * Inherits from
+ * - {Ext.data.Record}
+ */
+GeoExt.data.LayerRecord = Ext.extend(Ext.data.Record, {
+    
+    /**
+     * Constructor: GeoExt.data.LayerRecord
+     * This constructor should not be used directly. Instead, the create method of
+     * this class should be used to create a constructor. The parameters are the
+     * same.
+     * 
+     * Parameters:
+     * layer - {OpenLayers.Layer}
+     * data - {Object} additional values, keyed by field name
+     */
+    constructor: function(layer, data) {
+        this.data = Ext.applyIf({
+            title: layer.name,
+            layer: layer
+        }, data);
+        this.id = layer.id;
+    }
+});
+
+/**
+ * APIFunction: GeoExt.data.LayerRecord.create
+ * Creates a constructor for a LayerRecord, optionally with additional
+ * fields.
+ * 
+ * Parameters:
+ * fieldDefinition - {Array} Field definition as in {Ext.data.Record.create}.
+ *     Can be omitted if no additional fields are required (records will
+ *     always have a {OpenLayers.Layer} layer and a {String} title field).
+ */
+GeoExt.data.LayerRecord.create = function(fieldDefinition) {
+    var o = [
+        {name: "layer"},
+        {name: "title"}
+    ].concat(fieldDefinition);
+
+    var f = Ext.extend(GeoExt.data.LayerRecord, {});
+    var p = f.prototype;
+    p.fields = new Ext.util.MixedCollection(false, function(field){
+        return field.name;
+    });
+    for(var i = 0, len = o.length; i < len; i++){
+        p.fields.add(new Ext.data.Field(o[i]));
+    }
+    f.getField = function(name){
+        return p.fields.get(name);
+    };
+    return f;
+}

Modified: sandbox/elemoine/playground/lib/GeoExt/data/LayerStore.js
===================================================================
--- sandbox/elemoine/playground/lib/GeoExt/data/LayerStore.js	2009-03-22 13:39:39 UTC (rev 240)
+++ sandbox/elemoine/playground/lib/GeoExt/data/LayerStore.js	2009-03-22 13:40:59 UTC (rev 241)
@@ -0,0 +1,173 @@
+/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation ¹
+ * Published under the BSD license.
+ * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
+ * of the license.
+ * 
+ * ¹ pending approval */
+
+Ext.namespace("GeoExt.data");
+
+/**
+ * Class: LayerStoreMixin
+ * A store that synchronizes a layers array of an {OpenLayers.Map} with a
+ * layer store holding {<GeoExt.data.LayerRecord>} entries.
+ * 
+ * This class can not be instantiated directly. Instead, it is meant to extend
+ * {Ext.data.Store} or a subclass of it:
+ * (start code)
+ * var store = new (Ext.extend(Ext.data.Store, GeoExt.data.LayerStoreMixin))({
+ *     map: myMap,
+ *     layers: myLayers
+ * });
+ * (end)
+ * 
+ * For convenience, a {GeoExt.data.LayerStore} class is available as a
+ * shortcut to the Ext.extend sequence in the above code snippet. The above
+ * is equivalent to:
+ * (start code)
+ * var store = new GeoExt.data.LayerStore({
+ *     map: myMap,
+ *     layers: myLayers
+ * })
+ * (end)
+ */
+GeoExt.data.LayerStoreMixin = {
+    /**
+     * APIProperty: map
+     * {OpenLayers.Map} Map that this store will be in sync with.
+     */
+    map: null,
+    
+    /**
+     * APIProperty: recordType
+     * {<GeoExt.data.LayerRecord>} type of the layer records used by this
+     *     store.
+     */
+    recordType: null,
+
+    /**
+     * Constructor: GeoExt.LayerStore
+     * 
+     * Parameters:
+     * config - {Object}
+     * 
+     * Valid config options:
+     * map - {OpenLayers.Map|<GeoExt.MapPanel>} map to sync the layer store
+     *     with.
+     * layers - {Array(OpenLayers.Layer)} Layers that will be added to the
+     *     layer store (and the map, because we are already syncing).
+     * recordType - {<GeoExt.data.LayerRecord>} If provided, a custom layer
+     *     record type with additional fields will be used. Default fields for
+     *     every layer record are {OpenLayers.Layer} layer and {String} title.
+     */
+    constructor: function(config) {
+        arguments.callee.superclass.constructor.apply(this, arguments);
+        config = config || {};
+        this.recordType = config.recordType || GeoExt.data.LayerRecord.create();
+        var map = config.map instanceof GeoExt.MapPanel ?
+            config.map.map : config.map;
+        if(map) {
+            // create a snapshop of the map's layers
+            var layers = map.layers;
+            var layer;
+            // walk through the layers snapshot and add layers to the store
+            for(var i=0; i<layers.length; ++i) {
+                layer = layers[i];
+                this.add(new this.recordType(layer));
+            }
+
+            this.setMap(map);
+            config.layers && map.addLayers(config.layers);
+        }
+    },
+    
+    /**
+     * APIMethod: setMap
+     * 
+     * Parameters:
+     * map - {OpenLayers.Map}
+     */
+    setMap: function(map) {
+        this.map = map;
+        map.events.on({
+            "addlayer": this.onAddLayer,
+            "removelayer": this.onRemoveLayer,
+            scope: this
+        });
+        this.on({
+            "add": this.onAdd,
+            "remove": this.onRemove,
+            scope: this
+        });
+    },
+    
+    /**
+     * Method: onAddLayer
+     * Handler for a map's addlayer event
+     * 
+     * Parameters:
+     * evt - {Object}
+     */
+    onAddLayer: function(evt) {
+        var layer = evt.layer;
+        this._adding = true;
+        this.add(new this.recordType(layer));
+        delete this._adding;
+    },
+    
+    /**
+     * Method: onRemoveLayer
+     * Handler for a map's removelayer event
+     * 
+     * Parameters:
+     * evt - {Object}
+     */
+    onRemoveLayer: function(evt){
+        var layer = evt.layer;
+        this._removing = true;
+        this.remove(this.getById(layer.id));
+        delete this._removing;
+    },
+    
+    /**
+     * Method: onAdd
+     * Handler for a store's add event
+     * 
+     * Parameters:
+     * store - {<Ext.data.Store>}
+     * records - {Array(Ext.data.Record)}
+     * index - {Number}
+     */
+    onAdd: function(store, records, index) {
+        if(!this._adding) {
+            for(var i=0; i<records.length; ++i) {
+                this.map.addLayer(records[i].get("layer"));
+            }
+        }
+    },
+    
+    /**
+     * Method: onRemove
+     * Handler for a store's remove event
+     * 
+     * Parameters:
+     * store - {<Ext.data.Store>}
+     * records - {Array(Ext.data.Record)}
+     * index - {Number}
+     */
+    onRemove: function(store, record, index){
+        if(!this._removing) {
+            this.map.removeLayer(record.get("layer"));
+        }
+    }
+};
+
+/**
+ * Class: GeoExt.data.LayerStore
+ * Default implementation of an {Ext.data.Store} enhanced with
+ * {<GeoExt.data.LayerStoreMixin>}
+ */
+GeoExt.data.LayerStore = Ext.extend(
+    Ext.data.Store,
+    GeoExt.data.LayerStoreMixin
+);


Property changes on: sandbox/elemoine/playground/lib/GeoExt/data/LayerStore.js
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: sandbox/elemoine/playground/lib/GeoExt.js
===================================================================
--- sandbox/elemoine/playground/lib/GeoExt.js	2009-03-22 13:39:39 UTC (rev 240)
+++ sandbox/elemoine/playground/lib/GeoExt.js	2009-03-22 13:40:59 UTC (rev 241)
@@ -1,21 +1,9 @@
-/*
- * Copyright (C) 2008 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/>.
- */
+/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation ¹
+ * Published under the BSD license.
+ * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
+ * of the license.
+ * 
+ * ¹ pending approval */
 
 /*
  * The code in this file is based on code taken from OpenLayers.
@@ -24,10 +12,7 @@
  * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
  * full text of the license.
  */
-
-/* 
- */ 
-
+ 
 (function() {
 
     /**
@@ -75,10 +60,13 @@
         var jsfiles = new Array(
             "GeoExt/data/FeatureReader.js",
             "GeoExt/data/FeatureStore.js",
+            "GeoExt/data/LayerStore.js",
+            "GeoExt/data/LayerRecord.js",
             "GeoExt/data/FeatureStoreMediator.js",
             "GeoExt/data/RecordLayerMediator.js",
             "GeoExt/data/LayerStoreMediator.js",
-            "GeoExt/data/ProtocolProxy.js"
+            "GeoExt/data/ProtocolProxy.js",
+            "GeoExt/widgets/MapPanel.js"
         );
 
         var agent = navigator.userAgent;

Modified: sandbox/elemoine/playground/license.txt
===================================================================
--- sandbox/elemoine/playground/license.txt	2009-03-22 13:39:39 UTC (rev 240)
+++ sandbox/elemoine/playground/license.txt	2009-03-22 13:40:59 UTC (rev 241)
@@ -0,0 +1,28 @@
+Copyright (c) 2008-2009, The Open Source Geospatial Foundation ¹
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of the Open Source Geospatial Foundation nor the names
+      of its contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+¹ pending approval
\ No newline at end of file


Property changes on: sandbox/elemoine/playground/license.txt
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: sandbox/elemoine/playground/tests/data/LayerRecord.html
===================================================================
--- sandbox/elemoine/playground/tests/data/LayerRecord.html	2009-03-22 13:39:39 UTC (rev 240)
+++ sandbox/elemoine/playground/tests/data/LayerRecord.html	2009-03-22 13:40:59 UTC (rev 241)
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html debug="true">
+  <head>
+    <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script>
+    <script type="text/javascript" src="../../../../ext/2.2.1/adapter/ext/ext-base.js"></script>
+    <script type="text/javascript" src="../../../../ext/2.2.1/ext-all-debug.js"></script>
+    <script type="text/javascript" src="../../lib/GeoExt.js"></script>
+
+    <script type="text/javascript">
+       
+        function test_layerrecord(t) {
+            t.plan(4);
+            
+            var c = GeoExt.data.LayerRecord.create();
+            
+            var layer = new OpenLayers.Layer();
+            var record = new c(layer);
+
+            t.ok(record instanceof GeoExt.data.LayerRecord, "create returns a constructor");
+            t.eq(record.get("layer").id, layer.id, "Layer stored correctly");
+            t.eq(record.id, layer.id, "ID set correctly");
+            
+            var record = new c(layer, {"foo": "bar"});
+            t.eq(record.get("foo"), "bar", "foo data row set correctly");
+        }
+    </script>
+  <body>
+    <div id="mappanel"></div>
+  </body>
+</html>

Modified: sandbox/elemoine/playground/tests/data/LayerStore.html
===================================================================
--- sandbox/elemoine/playground/tests/data/LayerStore.html	2009-03-22 13:39:39 UTC (rev 240)
+++ sandbox/elemoine/playground/tests/data/LayerStore.html	2009-03-22 13:40:59 UTC (rev 241)
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html debug="true">
+  <head>
+    <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script>
+    <script type="text/javascript" src="../../../../ext/2.2.1/adapter/ext/ext-base.js"></script>
+    <script type="text/javascript" src="../../../../ext/2.2.1/ext-all-debug.js"></script>
+    <script type="text/javascript" src="../../lib/GeoExt.js"></script>
+
+    <script type="text/javascript">
+       
+        function createMap() {
+            var map = new OpenLayers.Map();
+            return map;
+        }
+
+        function loadMapPanel() {
+            var map = createMap();
+
+            mapPanel = new GeoExt.MapPanel({
+                // panel options
+                id: "map-panel",
+                title: "GeoExt MapPanel",
+                renderTo: "mappanel",
+                height: 400,
+                width: 600,
+                // map panel-specific options
+                map: map,
+                center: new OpenLayers.LonLat(5, 45),
+                zoom: 4
+            });
+
+            return mapPanel;
+        }
+
+        function test_layerstore(t) {
+            t.plan(6);
+
+            var mapPanel = loadMapPanel();
+            var map = mapPanel.map;
+
+            var layer = new OpenLayers.Layer.Vector("Foo Layer");
+
+            map.addLayer(layer);
+
+            t.eq(map.layers.length,1,"Adding layer to map does not create duplicate layers on map");
+            t.eq(mapPanel.layers.getCount(),1,"Adding layer to map does not create duplicate records in LayerStore");
+
+            mapPanel.layers.remove(mapPanel.layers.getById(layer.id));
+
+            t.eq(map.layers.length,0,"removeLayer on MapPanel's LayerStore removes layer from map");
+            t.eq(mapPanel.layers.getCount(),0,"removeLayer on MapPanel's LayerStore removes layer from map");
+
+            mapPanel.layers.add(new GeoExt.data.LayerRecord(layer));
+            t.eq(map.layers.length,1,"Adding layer to MapPanel's LayerStore adds only one layer to map");
+            t.eq(mapPanel.layers.getCount(),1,"Adding layers to MapPanel's LayerStore does not create duplicate layers"); 
+
+
+        }
+    </script>
+  <body>
+    <div id="mappanel"></div>
+  </body>
+</html>


Property changes on: sandbox/elemoine/playground/tests/data/LayerStore.html
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: sandbox/elemoine/playground/tests/list-tests.html
===================================================================
--- sandbox/elemoine/playground/tests/list-tests.html	2009-03-22 13:39:39 UTC (rev 240)
+++ sandbox/elemoine/playground/tests/list-tests.html	2009-03-22 13:40:59 UTC (rev 241)
@@ -2,6 +2,9 @@
   <li>data/FeatureReader.html</li>
   <li>data/FeatureStore.html</li>
   <li>data/FeatureStoreMediator.html</li>
+  <li>data/LayerRecord.html</li>
+  <li>data/LayerStore.html</li>
   <li>data/LayerStoreMediator.html</li>
   <li>data/ProtocolProxy.html</li>
+  <li>widgets/MapPanel.html</li>
 </ul>



More information about the Commits mailing list