Changeset 241


Ignore:
Timestamp:
03/22/09 14:40:59 (9 years ago)
Author:
elemoine
Message:

svn merge -r189:HEAD http://www.geoext.org/svn/geoext/core/trunk ./

Location:
sandbox/elemoine/playground
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • sandbox/elemoine/playground/examples/mappanel-div.html

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id Revision
    r240 r241  
     1<html>
     2  <head>
     3    <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script>
     4    <script type="text/javascript" src="../../../ext/2.2.1/adapter/ext/ext-base.js"></script>
     5    <script type="text/javascript" src="../../../ext/2.2.1/ext-all-debug.js"></script>
     6    <script type="text/javascript" src="../lib/GeoExt.js"></script>
     7
     8    <link rel="stylesheet" type="text/css" href="../../../ext/2.2.1/resources/css/ext-all.css"></link>
     9
     10    <script type="text/javascript">
     11
     12    // this example shows the OpenLayerish way to create a map panel. See
     13    // mappanel-window.html for the ExtJSish way to do the same.
     14
     15    var mapPanel;
     16   
     17    Ext.onReady(function() {
     18        var map = new OpenLayers.Map();
     19        var layer = new OpenLayers.Layer.WMS(
     20            "bluemarble",
     21            "http://sigma.openplans.org/geoserver/wms?",
     22            {layers: 'bluemarble'}
     23        );
     24        map.addLayer(layer);
     25
     26        mapPanel = new GeoExt.MapPanel({
     27            title: "GeoExt MapPanel",
     28            renderTo: "mappanel",
     29            height: 400,
     30            width: 600,
     31            map: map,
     32            center: new OpenLayers.LonLat(5, 45),
     33            zoom: 4
     34        });
     35    });
     36
     37    // functions for resizing the map panel
     38    function mapSizeUp() {
     39        var size = mapPanel.getSize();
     40        size.width += 40;
     41        size.height += 40;
     42        mapPanel.setSize(size);
     43    }
     44    function mapSizeDown() {
     45        var size = mapPanel.getSize();
     46        size.width -= 40;
     47        size.height -= 40;
     48        mapPanel.setSize(size);
     49    }
     50
     51    </script>
     52       
     53  </head>
     54  <body>
     55    <div id="mappanel"></div>
     56    <input type="button" onclick="mapSizeUp()" value="bigger"></input>
     57    <input type="button" onclick="mapSizeDown()" value="smaller"></input>
     58  </body>
     59</html>
  • sandbox/elemoine/playground/examples/mappanel-window.html

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id Revision
    r240 r241  
     1<html>
     2  <head>
     3    <link rel="stylesheet" type="text/css" href="../../../ext/2.2.1/resources/css/ext-all.css"></link>
     4    <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script>
     5    <script type="text/javascript" src="../../../ext/2.2.1/adapter/ext/ext-base.js"></script>
     6    <script type="text/javascript" src="../../../ext/2.2.1/ext-all-debug.js"></script>
     7    <script type="text/javascript" src="../lib/GeoExt.js"></script>
     8
     9    <script type="text/javascript">
     10
     11    // this example shows the Extish way to create a map panel. See
     12    // mappanel-div.html for the OpenLayerish way to do the same.
     13   
     14    var mapPanel;
     15   
     16    Ext.onReady(function() {
     17        new Ext.Window({
     18            title: "GeoExt MapPanel Window",
     19            height: 400,
     20            width: 600,
     21            layout: "fit",
     22            items: [{
     23                xtype: "gx_mappanel",
     24                id: "mappanel",
     25                layers: [new OpenLayers.Layer.WMS(
     26                    "bluemarble",
     27                    "http://sigma.openplans.org/geoserver/wms?",
     28                    {layers: 'bluemarble'}
     29                )],
     30                extent: "-5,35,15,55"
     31            }]
     32        }).show();
     33       
     34        mapPanel = Ext.getCmp("mappanel");
     35    });
     36
     37    </script>
     38  </head>
     39  <body>
     40  </body>
     41</html>
  • sandbox/elemoine/playground/lib/GeoExt.js

    r240 r241  
    1 /*
    2  * Copyright (C) 2008 Eric Lemoine, Camptocamp France SAS
    3  *
    4  * This file is part of GeoExt
    5  *
    6  * GeoExt is free software: you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation, either version 3 of the License, or
    9  * (at your option) any later version.
    10  *
    11  * GeoExt is distributed in the hope that it will be useful,
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  * GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License
    17  * along with GeoExt.  If not, see <http://www.gnu.org/licenses/>.
    18  */
     1/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation ¹
     2 * Published under the BSD license.
     3 * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
     4 * of the license.
     5 *
     6 * ¹ pending approval */
    197
    208/*
     
    2513 * full text of the license.
    2614 */
    27 
    28 /*
    29  */
    30 
     15 
    3116(function() {
    3217
     
    7661            "GeoExt/data/FeatureReader.js",
    7762            "GeoExt/data/FeatureStore.js",
     63            "GeoExt/data/LayerStore.js",
     64            "GeoExt/data/LayerRecord.js",
    7865            "GeoExt/data/FeatureStoreMediator.js",
    7966            "GeoExt/data/RecordLayerMediator.js",
    8067            "GeoExt/data/LayerStoreMediator.js",
    81             "GeoExt/data/ProtocolProxy.js"
     68            "GeoExt/data/ProtocolProxy.js",
     69            "GeoExt/widgets/MapPanel.js"
    8270        );
    8371
  • sandbox/elemoine/playground/lib/GeoExt/data/LayerRecord.js

    r240 r241  
     1/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation ¹
     2 * Published under the BSD license.
     3 * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
     4 * of the license.
     5 *
     6 * ¹ pending approval */
     7
     8Ext.namespace("GeoExt.data");
     9
     10/**
     11 * Class: GeoExt.data.LayerRecord
     12 * A subclass of {Ext.data.Record} which provides a special record that
     13 * represents an {OpenLayers.Layer}. This record will always have at least a
     14 * layer and a title field in its data. The id of this record will be the same
     15 * as the id of the layer it represents.
     16 *
     17 * Inherits from
     18 * - {Ext.data.Record}
     19 */
     20GeoExt.data.LayerRecord = Ext.extend(Ext.data.Record, {
     21   
     22    /**
     23     * Constructor: GeoExt.data.LayerRecord
     24     * This constructor should not be used directly. Instead, the create method of
     25     * this class should be used to create a constructor. The parameters are the
     26     * same.
     27     *
     28     * Parameters:
     29     * layer - {OpenLayers.Layer}
     30     * data - {Object} additional values, keyed by field name
     31     */
     32    constructor: function(layer, data) {
     33        this.data = Ext.applyIf({
     34            title: layer.name,
     35            layer: layer
     36        }, data);
     37        this.id = layer.id;
     38    }
     39});
     40
     41/**
     42 * APIFunction: GeoExt.data.LayerRecord.create
     43 * Creates a constructor for a LayerRecord, optionally with additional
     44 * fields.
     45 *
     46 * Parameters:
     47 * fieldDefinition - {Array} Field definition as in {Ext.data.Record.create}.
     48 *     Can be omitted if no additional fields are required (records will
     49 *     always have a {OpenLayers.Layer} layer and a {String} title field).
     50 */
     51GeoExt.data.LayerRecord.create = function(fieldDefinition) {
     52    var o = [
     53        {name: "layer"},
     54        {name: "title"}
     55    ].concat(fieldDefinition);
     56
     57    var f = Ext.extend(GeoExt.data.LayerRecord, {});
     58    var p = f.prototype;
     59    p.fields = new Ext.util.MixedCollection(false, function(field){
     60        return field.name;
     61    });
     62    for(var i = 0, len = o.length; i < len; i++){
     63        p.fields.add(new Ext.data.Field(o[i]));
     64    }
     65    f.getField = function(name){
     66        return p.fields.get(name);
     67    };
     68    return f;
     69}
  • sandbox/elemoine/playground/lib/GeoExt/data/LayerStore.js

    r240 r241  
     1/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation ¹
     2 * Published under the BSD license.
     3 * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
     4 * of the license.
     5 *
     6 * ¹ pending approval */
     7
     8Ext.namespace("GeoExt.data");
     9
     10/**
     11 * Class: LayerStoreMixin
     12 * A store that synchronizes a layers array of an {OpenLayers.Map} with a
     13 * layer store holding {<GeoExt.data.LayerRecord>} entries.
     14 *
     15 * This class can not be instantiated directly. Instead, it is meant to extend
     16 * {Ext.data.Store} or a subclass of it:
     17 * (start code)
     18 * var store = new (Ext.extend(Ext.data.Store, GeoExt.data.LayerStoreMixin))({
     19 *     map: myMap,
     20 *     layers: myLayers
     21 * });
     22 * (end)
     23 *
     24 * For convenience, a {GeoExt.data.LayerStore} class is available as a
     25 * shortcut to the Ext.extend sequence in the above code snippet. The above
     26 * is equivalent to:
     27 * (start code)
     28 * var store = new GeoExt.data.LayerStore({
     29 *     map: myMap,
     30 *     layers: myLayers
     31 * })
     32 * (end)
     33 */
     34GeoExt.data.LayerStoreMixin = {
     35    /**
     36     * APIProperty: map
     37     * {OpenLayers.Map} Map that this store will be in sync with.
     38     */
     39    map: null,
     40   
     41    /**
     42     * APIProperty: recordType
     43     * {<GeoExt.data.LayerRecord>} type of the layer records used by this
     44     *     store.
     45     */
     46    recordType: null,
     47
     48    /**
     49     * Constructor: GeoExt.LayerStore
     50     *
     51     * Parameters:
     52     * config - {Object}
     53     *
     54     * Valid config options:
     55     * map - {OpenLayers.Map|<GeoExt.MapPanel>} map to sync the layer store
     56     *     with.
     57     * layers - {Array(OpenLayers.Layer)} Layers that will be added to the
     58     *     layer store (and the map, because we are already syncing).
     59     * recordType - {<GeoExt.data.LayerRecord>} If provided, a custom layer
     60     *     record type with additional fields will be used. Default fields for
     61     *     every layer record are {OpenLayers.Layer} layer and {String} title.
     62     */
     63    constructor: function(config) {
     64        arguments.callee.superclass.constructor.apply(this, arguments);
     65        config = config || {};
     66        this.recordType = config.recordType || GeoExt.data.LayerRecord.create();
     67        var map = config.map instanceof GeoExt.MapPanel ?
     68            config.map.map : config.map;
     69        if(map) {
     70            // create a snapshop of the map's layers
     71            var layers = map.layers;
     72            var layer;
     73            // walk through the layers snapshot and add layers to the store
     74            for(var i=0; i<layers.length; ++i) {
     75                layer = layers[i];
     76                this.add(new this.recordType(layer));
     77            }
     78
     79            this.setMap(map);
     80            config.layers && map.addLayers(config.layers);
     81        }
     82    },
     83   
     84    /**
     85     * APIMethod: setMap
     86     *
     87     * Parameters:
     88     * map - {OpenLayers.Map}
     89     */
     90    setMap: function(map) {
     91        this.map = map;
     92        map.events.on({
     93            "addlayer": this.onAddLayer,
     94            "removelayer": this.onRemoveLayer,
     95            scope: this
     96        });
     97        this.on({
     98            "add": this.onAdd,
     99            "remove": this.onRemove,
     100            scope: this
     101        });
     102    },
     103   
     104    /**
     105     * Method: onAddLayer
     106     * Handler for a map's addlayer event
     107     *
     108     * Parameters:
     109     * evt - {Object}
     110     */
     111    onAddLayer: function(evt) {
     112        var layer = evt.layer;
     113        this._adding = true;
     114        this.add(new this.recordType(layer));
     115        delete this._adding;
     116    },
     117   
     118    /**
     119     * Method: onRemoveLayer
     120     * Handler for a map's removelayer event
     121     *
     122     * Parameters:
     123     * evt - {Object}
     124     */
     125    onRemoveLayer: function(evt){
     126        var layer = evt.layer;
     127        this._removing = true;
     128        this.remove(this.getById(layer.id));
     129        delete this._removing;
     130    },
     131   
     132    /**
     133     * Method: onAdd
     134     * Handler for a store's add event
     135     *
     136     * Parameters:
     137     * store - {<Ext.data.Store>}
     138     * records - {Array(Ext.data.Record)}
     139     * index - {Number}
     140     */
     141    onAdd: function(store, records, index) {
     142        if(!this._adding) {
     143            for(var i=0; i<records.length; ++i) {
     144                this.map.addLayer(records[i].get("layer"));
     145            }
     146        }
     147    },
     148   
     149    /**
     150     * Method: onRemove
     151     * Handler for a store's remove event
     152     *
     153     * Parameters:
     154     * store - {<Ext.data.Store>}
     155     * records - {Array(Ext.data.Record)}
     156     * index - {Number}
     157     */
     158    onRemove: function(store, record, index){
     159        if(!this._removing) {
     160            this.map.removeLayer(record.get("layer"));
     161        }
     162    }
     163};
     164
     165/**
     166 * Class: GeoExt.data.LayerStore
     167 * Default implementation of an {Ext.data.Store} enhanced with
     168 * {<GeoExt.data.LayerStoreMixin>}
     169 */
     170GeoExt.data.LayerStore = Ext.extend(
     171    Ext.data.Store,
     172    GeoExt.data.LayerStoreMixin
     173);
  • sandbox/elemoine/playground/license.txt

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id Revision
    r240 r241  
     1Copyright (c) 2008-2009, The Open Source Geospatial Foundation ¹
     2All rights reserved.
     3
     4Redistribution and use in source and binary forms, with or without
     5modification, are permitted provided that the following conditions are met:
     6
     7    * Redistributions of source code must retain the above copyright notice,
     8      this list of conditions and the following disclaimer.
     9    * Redistributions in binary form must reproduce the above copyright
     10      notice, this list of conditions and the following disclaimer in the
     11      documentation and/or other materials provided with the distribution.
     12    * Neither the name of the Open Source Geospatial Foundation nor the names
     13      of its contributors may be used to endorse or promote products derived
     14      from this software without specific prior written permission.
     15
     16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     17AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     20LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26POSSIBILITY OF SUCH DAMAGE.
     27
     28¹ pending approval
  • sandbox/elemoine/playground/tests/data/LayerRecord.html

    r240 r241  
     1<!DOCTYPE html>
     2<html debug="true">
     3  <head>
     4    <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script>
     5    <script type="text/javascript" src="../../../../ext/2.2.1/adapter/ext/ext-base.js"></script>
     6    <script type="text/javascript" src="../../../../ext/2.2.1/ext-all-debug.js"></script>
     7    <script type="text/javascript" src="../../lib/GeoExt.js"></script>
     8
     9    <script type="text/javascript">
     10       
     11        function test_layerrecord(t) {
     12            t.plan(4);
     13           
     14            var c = GeoExt.data.LayerRecord.create();
     15           
     16            var layer = new OpenLayers.Layer();
     17            var record = new c(layer);
     18
     19            t.ok(record instanceof GeoExt.data.LayerRecord, "create returns a constructor");
     20            t.eq(record.get("layer").id, layer.id, "Layer stored correctly");
     21            t.eq(record.id, layer.id, "ID set correctly");
     22           
     23            var record = new c(layer, {"foo": "bar"});
     24            t.eq(record.get("foo"), "bar", "foo data row set correctly");
     25        }
     26    </script>
     27  <body>
     28    <div id="mappanel"></div>
     29  </body>
     30</html>
  • sandbox/elemoine/playground/tests/data/LayerStore.html

    r240 r241  
     1<!DOCTYPE html>
     2<html debug="true">
     3  <head>
     4    <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script>
     5    <script type="text/javascript" src="../../../../ext/2.2.1/adapter/ext/ext-base.js"></script>
     6    <script type="text/javascript" src="../../../../ext/2.2.1/ext-all-debug.js"></script>
     7    <script type="text/javascript" src="../../lib/GeoExt.js"></script>
     8
     9    <script type="text/javascript">
     10       
     11        function createMap() {
     12            var map = new OpenLayers.Map();
     13            return map;
     14        }
     15
     16        function loadMapPanel() {
     17            var map = createMap();
     18
     19            mapPanel = new GeoExt.MapPanel({
     20                // panel options
     21                id: "map-panel",
     22                title: "GeoExt MapPanel",
     23                renderTo: "mappanel",
     24                height: 400,
     25                width: 600,
     26                // map panel-specific options
     27                map: map,
     28                center: new OpenLayers.LonLat(5, 45),
     29                zoom: 4
     30            });
     31
     32            return mapPanel;
     33        }
     34
     35        function test_layerstore(t) {
     36            t.plan(6);
     37
     38            var mapPanel = loadMapPanel();
     39            var map = mapPanel.map;
     40
     41            var layer = new OpenLayers.Layer.Vector("Foo Layer");
     42
     43            map.addLayer(layer);
     44
     45            t.eq(map.layers.length,1,"Adding layer to map does not create duplicate layers on map");
     46            t.eq(mapPanel.layers.getCount(),1,"Adding layer to map does not create duplicate records in LayerStore");
     47
     48            mapPanel.layers.remove(mapPanel.layers.getById(layer.id));
     49
     50            t.eq(map.layers.length,0,"removeLayer on MapPanel's LayerStore removes layer from map");
     51            t.eq(mapPanel.layers.getCount(),0,"removeLayer on MapPanel's LayerStore removes layer from map");
     52
     53            mapPanel.layers.add(new GeoExt.data.LayerRecord(layer));
     54            t.eq(map.layers.length,1,"Adding layer to MapPanel's LayerStore adds only one layer to map");
     55            t.eq(mapPanel.layers.getCount(),1,"Adding layers to MapPanel's LayerStore does not create duplicate layers");
     56
     57
     58        }
     59    </script>
     60  <body>
     61    <div id="mappanel"></div>
     62  </body>
     63</html>
  • sandbox/elemoine/playground/tests/list-tests.html

    r240 r241  
    33  <li>data/FeatureStore.html</li>
    44  <li>data/FeatureStoreMediator.html</li>
     5  <li>data/LayerRecord.html</li>
     6  <li>data/LayerStore.html</li>
    57  <li>data/LayerStoreMediator.html</li>
    68  <li>data/ProtocolProxy.html</li>
     9  <li>widgets/MapPanel.html</li>
    710</ul>
Note: See TracChangeset for help on using the changeset viewer.