[Commits] r238 - in core/trunk: . examples lib lib/GeoExt lib/GeoExt/data lib/GeoExt/widgets tests tests/data tests/widgets
commits at geoext.org
commits at geoext.org
Sat Mar 21 22:51:01 CET 2009
Author: ahocevar
Date: 2009-03-21 22:51:00 +0100 (Sat, 21 Mar 2009)
New Revision: 238
Added:
core/trunk/examples/
core/trunk/examples/mappanel-div.html
core/trunk/examples/mappanel-window.html
core/trunk/lib/GeoExt/data/LayerRecord.js
core/trunk/lib/GeoExt/data/LayerStore.js
core/trunk/lib/GeoExt/widgets/
core/trunk/lib/GeoExt/widgets/MapPanel.js
core/trunk/license.txt
core/trunk/tests/data/LayerRecord.html
core/trunk/tests/data/LayerStore.html
core/trunk/tests/widgets/
core/trunk/tests/widgets/MapPanel.html
Modified:
core/trunk/lib/GeoExt.js
core/trunk/tests/list-tests.html
Log:
Added MapPanel, LayerRecord and LayerStore with examples and tests; also contains license.txt file. Big thanks to sbenthall and tcoulter for their original input, to elemoine for the good discussion today about the LayerStoreMixin and his patience despite my angryness, to tschaub for the constructive comments, and finally to everyone who participated in the discussions on the mailing list about what we want this component to be. r=elemoine,tschaub (closes #4)
Added: core/trunk/examples/mappanel-div.html
===================================================================
--- core/trunk/examples/mappanel-div.html (rev 0)
+++ core/trunk/examples/mappanel-div.html 2009-03-21 21:51:00 UTC (rev 238)
@@ -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: core/trunk/examples/mappanel-div.html
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: core/trunk/examples/mappanel-window.html
===================================================================
--- core/trunk/examples/mappanel-window.html (rev 0)
+++ core/trunk/examples/mappanel-window.html 2009-03-21 21:51:00 UTC (rev 238)
@@ -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: core/trunk/examples/mappanel-window.html
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: core/trunk/lib/GeoExt/data/LayerRecord.js
===================================================================
--- core/trunk/lib/GeoExt/data/LayerRecord.js (rev 0)
+++ core/trunk/lib/GeoExt/data/LayerRecord.js 2009-03-21 21:51:00 UTC (rev 238)
@@ -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;
+}
Added: core/trunk/lib/GeoExt/data/LayerStore.js
===================================================================
--- core/trunk/lib/GeoExt/data/LayerStore.js (rev 0)
+++ core/trunk/lib/GeoExt/data/LayerStore.js 2009-03-21 21:51:00 UTC (rev 238)
@@ -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: core/trunk/lib/GeoExt/data/LayerStore.js
___________________________________________________________________
Name: svn:mergeinfo
+
Added: core/trunk/lib/GeoExt/widgets/MapPanel.js
===================================================================
--- core/trunk/lib/GeoExt/widgets/MapPanel.js (rev 0)
+++ core/trunk/lib/GeoExt/widgets/MapPanel.js 2009-03-21 21:51:00 UTC (rev 238)
@@ -0,0 +1,152 @@
+/* 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");
+
+/**
+ * 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: layers
+ * {GeoExt.data.LayerStore|GeoExt.data.GroupingStore|Array(OpenLayers.Layer)}
+ * A store holding records. If not provided, an empty
+ * {<GeoExt.data.LayerStore>} will be created. After instantiation
+ * this property will always be an {Ext.data.Store}, even if an array
+ * of {OpenLayers.Layer} was provided.
+ */
+ layers: 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);
+ }
+ var layers = this.layers;
+ if(!layers || layers instanceof Array) {
+ this.layers = new GeoExt.data.LayerStore({
+ layers: layers,
+ map: this.map
+ });
+ }
+
+ var args;
+ if(typeof this.center == "string") {
+ this.center = OpenLayers.LonLat.fromString(this.center);
+ }
+ if(typeof this.extent == "string") {
+ this.extent = OpenLayers.Bounds.fromString(this.extent);
+ }
+
+ GeoExt.MapPanel.superclass.initComponent.call(this);
+ },
+
+ /**
+ * Method: onRender
+ * Private method called after the panel has been
+ * rendered.
+ */
+ onRender: function() {
+ GeoExt.MapPanel.superclass.onRender.apply(this, arguments);
+ this.map.render(this.body.dom);
+ if(this.map.layers.length > 0) {
+ if(this.center && this.zoom) {
+ this.map.setCenter(this.center, this.zoom);
+ } else if(this.extent) {
+ this.map.zoomToExtent(this.extent);
+ } else {
+ this.map.zoomToMaxExtent();
+ }
+ }
+ },
+
+ /**
+ * Method: onResize
+ * Private method called after the panel has been
+ * resized.
+ */
+ onResize: function() {
+ GeoExt.MapPanel.superclass.onResize.apply(this, arguments);
+ this.map.updateSize();
+ }
+});
+
+Ext.reg('gx_mappanel', GeoExt.MapPanel);
Property changes on: core/trunk/lib/GeoExt/widgets/MapPanel.js
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: core/trunk/lib/GeoExt.js
===================================================================
--- core/trunk/lib/GeoExt.js 2009-03-20 16:58:04 UTC (rev 237)
+++ core/trunk/lib/GeoExt.js 2009-03-21 21:51:00 UTC (rev 238)
@@ -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,8 +60,11 @@
var jsfiles = new Array(
"GeoExt/data/FeatureReader.js",
"GeoExt/data/FeatureStoreMediator.js",
+ "GeoExt/data/LayerStore.js",
+ "GeoExt/data/LayerRecord.js",
"GeoExt/data/LayerStoreMediator.js",
- "GeoExt/data/ProtocolProxy.js"
+ "GeoExt/data/ProtocolProxy.js",
+ "GeoExt/widgets/MapPanel.js"
);
var agent = navigator.userAgent;
@@ -102,4 +90,4 @@
document.write(allScriptTags.join(""));
}
}
-})();
+})();
\ No newline at end of file
Added: core/trunk/license.txt
===================================================================
--- core/trunk/license.txt (rev 0)
+++ core/trunk/license.txt 2009-03-21 21:51:00 UTC (rev 238)
@@ -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: core/trunk/license.txt
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: core/trunk/tests/data/LayerRecord.html
===================================================================
--- core/trunk/tests/data/LayerRecord.html (rev 0)
+++ core/trunk/tests/data/LayerRecord.html 2009-03-21 21:51:00 UTC (rev 238)
@@ -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>
Added: core/trunk/tests/data/LayerStore.html
===================================================================
--- core/trunk/tests/data/LayerStore.html (rev 0)
+++ core/trunk/tests/data/LayerStore.html 2009-03-21 21:51:00 UTC (rev 238)
@@ -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: core/trunk/tests/data/LayerStore.html
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: core/trunk/tests/list-tests.html
===================================================================
--- core/trunk/tests/list-tests.html 2009-03-20 16:58:04 UTC (rev 237)
+++ core/trunk/tests/list-tests.html 2009-03-21 21:51:00 UTC (rev 238)
@@ -1,6 +1,9 @@
<ul id="testlist">
<li>data/FeatureReader.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>
Added: core/trunk/tests/widgets/MapPanel.html
===================================================================
--- core/trunk/tests/widgets/MapPanel.html (rev 0)
+++ core/trunk/tests/widgets/MapPanel.html 2009-03-21 21:51:00 UTC (rev 238)
@@ -0,0 +1,49 @@
+<!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();
+ var layer = new OpenLayers.Layer("test", {isBaseLayer: true});
+ map.addLayer(layer);
+ 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_mappanel(t) {
+ t.plan(2)
+
+ loadMapPanel();
+ t.eq(mapPanel.map.getCenter().toString(), "lon=5,lat=45", "Map center set correctly");
+ t.eq(mapPanel.map.getZoom(), 4, "Zoom set correctly");
+ }
+
+ </script>
+ <body>
+ <div id="mappanel"></div>
+ </body>
+</html>
Property changes on: core/trunk/tests/widgets/MapPanel.html
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
More information about the Commits
mailing list