[Commits] r187 - in sandbox/camptocamp/studio: . examples lib/GeoExt lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Wed Feb 18 16:58:40 CET 2009
Author: elemoine
Date: 2009-02-18 16:58:40 +0100 (Wed, 18 Feb 2009)
New Revision: 187
Added:
sandbox/camptocamp/studio/examples/
sandbox/camptocamp/studio/examples/mappanel-div.html
sandbox/camptocamp/studio/examples/mappanel-window.html
sandbox/camptocamp/studio/lib/GeoExt/widgets/
sandbox/camptocamp/studio/lib/GeoExt/widgets/MapPanel.js
Log:
MapPanel #4
Added: sandbox/camptocamp/studio/examples/mappanel-div.html
===================================================================
--- sandbox/camptocamp/studio/examples/mappanel-div.html (rev 0)
+++ sandbox/camptocamp/studio/examples/mappanel-div.html 2009-02-18 15:58:40 UTC (rev 187)
@@ -0,0 +1,71 @@
+<html>
+ <head>
+ <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="../../../ext/2.2/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../ext/2.2/ext-all-debug.js"></script>
+ <script type="text/javascript" src="../lib/GeoExt/widgets/MapPanel.js"></script>
+
+ <link rel="stylesheet" type="text/css" href="../../../ext/2.2/resources/css/ext-all.css"></link>
+
+ <script type="text/javascript">
+ var app = (function() {
+
+ var mapPanel = null;
+
+ var createMap = function() {
+ var map = new OpenLayers.Map();
+ var layer = new OpenLayers.Layer.WMS(
+ "vmap0",
+ "http://labs.metacarta.com/wms/vmap0",
+ {layers: 'basic'}
+ );
+ map.addLayer(layer);
+ return map;
+ };
+
+ return {
+ load: function() {
+ 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
+ });
+ },
+
+ mapSizeUp: function() {
+ var size = mapPanel.getSize();
+ size.width += 40;
+ size.height += 40;
+ mapPanel.setSize(size);
+ },
+
+ mapSizeDown: function() {
+ var size = mapPanel.getSize();
+ size.width -= 40;
+ size.height -= 40;
+ mapPanel.setSize(size);
+ }
+ }
+ })();
+
+ Ext.onReady(function() {
+ app.load();
+ });
+ </script>
+
+ </head>
+ <body>
+ <div id="mappanel"></div>
+ <input type="button" onclick="app.mapSizeUp()" value="bigger"></input>
+ <input type="button" onclick="app.mapSizeDown()" value="smaller"></input>
+ </body>
+</html>
Added: sandbox/camptocamp/studio/examples/mappanel-window.html
===================================================================
--- sandbox/camptocamp/studio/examples/mappanel-window.html (rev 0)
+++ sandbox/camptocamp/studio/examples/mappanel-window.html 2009-02-18 15:58:40 UTC (rev 187)
@@ -0,0 +1,54 @@
+<html>
+ <head>
+ <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="../../../ext/2.2/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../ext/2.2/ext-all-debug.js"></script>
+ <script type="text/javascript" src="../lib/GeoExt/widgets/MapPanel.js"></script>
+
+ <link rel="stylesheet" type="text/css" href="../../../ext/2.2/resources/css/ext-all.css"></link>
+
+ <script type="text/javascript">
+ var app = (function() {
+
+ var mapPanel = null;
+
+ var createMap = function() {
+ var map = new OpenLayers.Map();
+ var layer = new OpenLayers.Layer.WMS(
+ "vmap0",
+ "http://labs.metacarta.com/wms/vmap0",
+ {layers: 'basic'}
+ );
+ map.addLayer(layer);
+ return map;
+ };
+
+ return {
+ load: function() {
+ var map = createMap();
+
+ new Ext.Window({
+ id: "window",
+ title: "GeoExt MapPanel Window",
+ height: 400,
+ width: 600,
+ layout: "fit",
+ items: [{
+ xtype: "gx_mappanel",
+ map: map,
+ extent: new OpenLayers.Bounds(-165, 45, -90, 45)
+ }]
+ }).show();
+ }
+ }
+ })();
+
+ Ext.onReady(function() {
+ app.load();
+ });
+ </script>
+
+ </head>
+ <body>
+ </body>
+</html>
Added: sandbox/camptocamp/studio/lib/GeoExt/widgets/MapPanel.js
===================================================================
--- sandbox/camptocamp/studio/lib/GeoExt/widgets/MapPanel.js (rev 0)
+++ sandbox/camptocamp/studio/lib/GeoExt/widgets/MapPanel.js 2009-02-18 15:58:40 UTC (rev 187)
@@ -0,0 +1,143 @@
+/*
+ * Initial code
+ * (C) 2008 Tim Coulter, The Open Planing Project
+ *
+ * Misc tweaks for inclusion into trunk GeoExt
+ * (C) 2009 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/>.
+ */
+
+Ext.namespace("GeoExt");
+
+/**
+ * Class: GeoExt.MapPanel
+ * A map panel is a panel with a map inside it.
+ *
+ * Example: create a map panel and render it in a div identified
+ * by "div-id".
+ *
+ * (start code)
+ * var mapPanel = new GeoExt.MapPanel({
+ * border: false,
+ * renderTo: "div-id",
+ * map: new OpenLayers.Map({
+ * maxExtent: new OpenLayers.Bounds(-90, -45, 90, 45)
+ * })
+ * });
+ * (end)
+ *
+ * Example: create a panel including a map panel with a toolbar.
+ *
+ * (start code)
+ * var panel = new Ext.Panel({
+ * items: [{
+ * xtype: "gx_mappanel",
+ * bbar: new Ext.Toolbar()
+ * }]
+ * });
+ * (end)
+ *
+ * Inherits from:
+ * - {Ext.Panel}
+ */
+
+/**
+ * Constructor: GeoExt.MapPanel
+ * Creates a panel with a map inside it.
+ *
+ * Parameters:
+ * config - {Object} A config object. In addition to the config options
+ * of its parent class, this object can receive specific options,
+ * see the API properties to know about these specific options.
+ */
+GeoExt.MapPanel = Ext.extend(Ext.Panel, {
+ /**
+ * APIProperty: map
+ * {OpenLayers.Map|Object} An {OpenLayers.Map} instance
+ * or an {OpenLayers.Map} config object, in the latter case
+ * the map panel will take care of creating the {OpenLayers.Map}
+ * object.
+ */
+ map: null,
+
+ /**
+ * APIProperty: center
+ * {OpenLayers.LonLat} The lonlat to which the map will
+ * be initially centered, to be used in conjunction with
+ * the zoom option.
+ */
+ center: null,
+
+ /**
+ * APIProperty: zoom
+ * {Number} The initial zoom level of the map, to be used
+ * in conjunction with the center option.
+ */
+ zoom: null,
+
+ /**
+ * APIProperty: extent
+ * {OpenLayers.Bounds} The initial extent of the map, use
+ * either this option of the center and zoom options.
+ */
+ extent: null,
+
+ /**
+ * Method: initComponent
+ * Initializes the map panel. Creates an OpenLayers map if
+ * none was provided in the config options passed to the
+ * constructor.
+ */
+ initComponent: function(){
+ if(!(this.map instanceof OpenLayers.Map)) {
+ this.map = new OpenLayers.Map(this.map);
+ }
+ this.on("render", this.gx_onRender, this);
+ this.on("bodyresize", this.gx_onBodyResize, this);
+ GeoExt.MapPanel.superclass.initComponent.call(this);
+ },
+
+ /**
+ * Method: gx_onRender
+ * Private method called after the panel has been
+ * rendered.
+ */
+ gx_onRender: function() {
+ var map = this.map;
+ map.render(this.body.dom);
+ if(map.layers.length > 0) {
+ if(this.center && this.zoom) {
+ map.setCenter(this.center, this.zoom);
+ } else if(this.extent) {
+ map.zoomToExtent(this.extent);
+ } else {
+ map.zoomToMaxExtent();
+ }
+ }
+ },
+
+ /**
+ * Method: gx_onBodyResize
+ * Private method called after the panel has been
+ * resized.
+ */
+ gx_onBodyResize: function() {
+ this.map.updateSize();
+ }
+});
+
+Ext.reg('gx_mappanel', GeoExt.MapPanel);
More information about the Commits
mailing list