| | 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 | |
|---|
| | 24 | Ext.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 | */ |
|---|
| | 67 | GeoExt.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 | |
|---|
| | 143 | Ext.reg('gx_mappanel', GeoExt.MapPanel); |