Ticket #4: patch-4-r186-A1.diff

File patch-4-r186-A1.diff, 8.8 kB (added by elemoine, 1 year ago)
  • lib/GeoExt/widgets/MapPanel.js

    old new  
     1/* 
     2 * Initial code 
     3 * (C) 2008 Tim Coulter, The Open Planing Project 
     4 * 
     5 * Misc tweaks for inclusion into trunk GeoExt 
     6 * (C) 2009 Eric Lemoine, Camptocamp France SAS 
     7 * 
     8 * This file is part of GeoExt 
     9 * 
     10 * GeoExt is free software: you can redistribute it and/or modify 
     11 * it under the terms of the GNU General Public License as published by 
     12 * the Free Software Foundation, either version 3 of the License, or 
     13 * (at your option) any later version. 
     14 * 
     15 * GeoExt is distributed in the hope that it will be useful, 
     16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     18 * GNU General Public License for more details. 
     19 * 
     20 * You should have received a copy of the GNU General Public License 
     21 * along with GeoExt.  If not, see <http://www.gnu.org/licenses/>. 
     22 */ 
     23 
     24Ext.namespace("GeoExt"); 
     25 
     26/** 
     27 * Class: GeoExt.MapPanel 
     28 *     A map panel is a panel with a map inside it. 
     29 * 
     30 * Example: create a map panel and render it in a div identified 
     31 * by "div-id". 
     32 * 
     33 * (start code) 
     34 * var mapPanel = new GeoExt.MapPanel({ 
     35 *     border: false, 
     36 *     renderTo: "div-id", 
     37 *     map: new OpenLayers.Map({ 
     38 *         maxExtent: new OpenLayers.Bounds(-90, -45, 90, 45) 
     39 *     }) 
     40 * }); 
     41 * (end) 
     42 * 
     43 * Example: create a panel including a map panel with a toolbar. 
     44 * 
     45 * (start code) 
     46 * var panel = new Ext.Panel({ 
     47 *     items: [{ 
     48 *         xtype: "gx_mappanel", 
     49 *         bbar: new Ext.Toolbar() 
     50 *     }] 
     51 * }); 
     52 * (end) 
     53 * 
     54 * Inherits from: 
     55 *  - {Ext.Panel} 
     56 */ 
     57 
     58/** 
     59 * Constructor: GeoExt.MapPanel 
     60 *     Creates a panel with a map inside it. 
     61 * 
     62 * Parameters: 
     63 * config - {Object} A config object. In addition to the config options 
     64 *     of its parent class, this object can receive specific options, 
     65 *     see the API properties to know about these specific options. 
     66 */ 
     67GeoExt.MapPanel = Ext.extend(Ext.Panel, { 
     68    /** 
     69     * APIProperty: map 
     70     * {OpenLayers.Map|Object} An {OpenLayers.Map} instance 
     71     * or an {OpenLayers.Map} config object, in the latter case 
     72     * the map panel will take care of creating the {OpenLayers.Map} 
     73     * object. 
     74     */ 
     75    map: null, 
     76 
     77    /** 
     78     * APIProperty: center 
     79     * {OpenLayers.LonLat} The lonlat to which the map will 
     80     * be initially centered, to be used in conjunction with 
     81     * the zoom option. 
     82     */ 
     83    center: null, 
     84 
     85    /** 
     86     * APIProperty: zoom 
     87     * {Number} The initial zoom level of the map, to be used 
     88     * in conjunction with the center option. 
     89     */ 
     90    zoom: null, 
     91 
     92    /** 
     93     * APIProperty: extent 
     94     * {OpenLayers.Bounds} The initial extent of the map, use 
     95     * either this option of the center and zoom options. 
     96     */ 
     97    extent: null, 
     98 
     99    /** 
     100     * Method: initComponent 
     101     *     Initializes the map panel. Creates an OpenLayers map if 
     102     *     none was provided in the config options passed to the 
     103     *     constructor. 
     104     */ 
     105    initComponent: function(){   
     106        if(!(this.map instanceof OpenLayers.Map)) { 
     107            this.map = new OpenLayers.Map(this.map); 
     108        } 
     109        this.on("render", this.gx_onRender, this); 
     110        this.on("bodyresize", this.gx_onBodyResize, this); 
     111        GeoExt.MapPanel.superclass.initComponent.call(this);        
     112    }, 
     113 
     114    /** 
     115     * Method: gx_onRender 
     116     *     Private method called after the panel has been 
     117     *     rendered. 
     118     */ 
     119    gx_onRender: function() { 
     120        var map = this.map; 
     121        map.render(this.body.dom); 
     122        if(map.layers.length > 0) { 
     123            if(this.center && this.zoom) { 
     124                map.setCenter(this.center, this.zoom); 
     125            } else if(this.extent) { 
     126                map.zoomToExtent(this.extent); 
     127            } else { 
     128                map.zoomToMaxExtent(); 
     129            } 
     130        } 
     131    }, 
     132 
     133    /** 
     134     * Method: gx_onBodyResize 
     135     *     Private method called after the panel has been 
     136     *     resized. 
     137     */ 
     138    gx_onBodyResize: function() { 
     139        this.map.updateSize(); 
     140    } 
     141}); 
     142 
     143Ext.reg('gx_mappanel', GeoExt.MapPanel);  
  • examples/mappanel-div.html

    old new  
     1<html> 
     2  <head> 
     3    <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script> 
     4    <script type="text/javascript" src="../../../ext/2.2/adapter/ext/ext-base.js"></script> 
     5    <script type="text/javascript" src="../../../ext/2.2/ext-all-debug.js"></script> 
     6    <script type="text/javascript" src="../lib/GeoExt/widgets/MapPanel.js"></script> 
     7 
     8    <link rel="stylesheet" type="text/css" href="../../../ext/2.2/resources/css/ext-all.css"></link> 
     9 
     10    <script type="text/javascript"> 
     11        var app = (function() { 
     12 
     13            var mapPanel = null; 
     14             
     15            var createMap = function() { 
     16                var map = new OpenLayers.Map(); 
     17                var layer = new OpenLayers.Layer.WMS( 
     18                    "vmap0", 
     19                    "http://labs.metacarta.com/wms/vmap0", 
     20                    {layers: 'basic'} 
     21                ); 
     22                map.addLayer(layer); 
     23                return map; 
     24            }; 
     25 
     26            return { 
     27                load: function() { 
     28                    var map = createMap(); 
     29 
     30                    mapPanel = new GeoExt.MapPanel({ 
     31                        // panel options 
     32                        id: "map-panel", 
     33                        title: "GeoExt MapPanel", 
     34                        renderTo: "mappanel", 
     35                        height: 400, 
     36                        width: 600, 
     37                        // map panel-specific options 
     38                        map: map, 
     39                        center: new OpenLayers.LonLat(5, 45), 
     40                        zoom: 4 
     41                    }); 
     42                }, 
     43 
     44                mapSizeUp: function() { 
     45                    var size = mapPanel.getSize(); 
     46                    size.width += 40; 
     47                    size.height += 40; 
     48                    mapPanel.setSize(size); 
     49                }, 
     50 
     51                mapSizeDown: function() { 
     52                    var size = mapPanel.getSize(); 
     53                    size.width -= 40; 
     54                    size.height -= 40; 
     55                    mapPanel.setSize(size); 
     56                } 
     57            } 
     58        })(); 
     59 
     60        Ext.onReady(function() { 
     61            app.load(); 
     62        }); 
     63    </script> 
     64         
     65  </head> 
     66  <body> 
     67    <div id="mappanel"></div> 
     68    <input type="button" onclick="app.mapSizeUp()" value="bigger"></input> 
     69    <input type="button" onclick="app.mapSizeDown()" value="smaller"></input> 
     70  </body> 
     71</html> 
  • examples/mappanel-window.html

    old new  
     1<html> 
     2  <head> 
     3    <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script> 
     4    <script type="text/javascript" src="../../../ext/2.2/adapter/ext/ext-base.js"></script> 
     5    <script type="text/javascript" src="../../../ext/2.2/ext-all-debug.js"></script> 
     6    <script type="text/javascript" src="../lib/GeoExt/widgets/MapPanel.js"></script> 
     7 
     8    <link rel="stylesheet" type="text/css" href="../../../ext/2.2/resources/css/ext-all.css"></link> 
     9 
     10    <script type="text/javascript"> 
     11        var app = (function() { 
     12 
     13            var mapPanel = null; 
     14             
     15            var createMap = function() { 
     16                var map = new OpenLayers.Map(); 
     17                var layer = new OpenLayers.Layer.WMS( 
     18                    "vmap0", 
     19                    "http://labs.metacarta.com/wms/vmap0", 
     20                    {layers: 'basic'} 
     21                ); 
     22                map.addLayer(layer); 
     23                return map; 
     24            }; 
     25 
     26            return { 
     27                load: function() { 
     28                    var map = createMap(); 
     29 
     30                    new Ext.Window({ 
     31                        id: "window", 
     32                        title: "GeoExt MapPanel Window", 
     33                        height: 400, 
     34                        width: 600, 
     35                        layout: "fit", 
     36                        items: [{ 
     37                            xtype: "gx_mappanel", 
     38                            map: map, 
     39                            extent: new OpenLayers.Bounds(-165, 45, -90, 45) 
     40                        }] 
     41                    }).show(); 
     42                } 
     43            } 
     44        })(); 
     45 
     46        Ext.onReady(function() { 
     47            app.load(); 
     48        }); 
     49    </script> 
     50         
     51  </head> 
     52  <body> 
     53  </body> 
     54</html>