[Commits] r2697 - in core/trunk/geoext: examples examples/data lib/GeoExt/data tests/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Mon May 16 21:02:13 CEST 2011
Author: ahocevar
Date: 2011-05-16 21:02:13 +0200 (Mon, 16 May 2011)
New Revision: 2697
Added:
core/trunk/geoext/examples/data/wfscap_tiny_100.xml
core/trunk/geoext/examples/wfs-capabilities.html
core/trunk/geoext/examples/wfs-capabilities.js
Modified:
core/trunk/geoext/lib/GeoExt/data/WFSCapabilitiesReader.js
core/trunk/geoext/tests/lib/GeoExt/data/WFSCapabilitiesReader.html
Log:
making it possible to pass a function as layerOptions. With new example. p=adube,me, r=me (closes #412)
Added: core/trunk/geoext/examples/data/wfscap_tiny_100.xml
===================================================================
--- core/trunk/geoext/examples/data/wfscap_tiny_100.xml (rev 0)
+++ core/trunk/geoext/examples/data/wfscap_tiny_100.xml 2011-05-16 19:02:13 UTC (rev 2697)
@@ -0,0 +1,150 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<WFS_Capabilities
+version='1.0.0' updateSequence='0'
+ xmlns='http://www.opengis.net/wfs'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:ogc='http://www.opengis.net/ogc'
+ xsi:schemaLocation='http://www.opengis.net/wfs
+ http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd' >
+ <Service>
+ <Name>TinyOWS ServerWFS</Name>
+ <Title>TinyOWS Server - Demo Service</Title>
+ <OnlineResource>http://127.0.0.1/cgi-bin/tinyows</OnlineResource>
+ </Service>
+ <Capability>
+ <Request>
+ <GetCapabilities>
+ <DCPType>
+ <HTTP>
+ <Get onlineResource="http://127.0.0.1/cgi-bin/tinyows?"/>
+ </HTTP>
+ </DCPType>
+ <DCPType>
+ <HTTP>
+ <Post onlineResource="http://127.0.0.1/cgi-bin/tinyows"/>
+ </HTTP>
+ </DCPType>
+ </GetCapabilities>
+ <DescribeFeatureType>
+ <SchemaDescriptionLanguage>
+ <XMLSCHEMA/>
+ </SchemaDescriptionLanguage>
+ <DCPType>
+ <HTTP>
+ <Get onlineResource="http://127.0.0.1/cgi-bin/tinyows?"/>
+ </HTTP>
+ </DCPType>
+ <DCPType>
+ <HTTP>
+ <Post onlineResource="http://127.0.0.1/cgi-bin/tinyows"/>
+ </HTTP>
+ </DCPType>
+ </DescribeFeatureType>
+ <GetFeature>
+<ResultFormat>
+<GML2/>
+</ResultFormat>
+ <DCPType>
+ <HTTP>
+ <Get onlineResource="http://127.0.0.1/cgi-bin/tinyows?"/>
+ </HTTP>
+ </DCPType>
+ <DCPType>
+ <HTTP>
+ <Post onlineResource="http://127.0.0.1/cgi-bin/tinyows"/>
+ </HTTP>
+ </DCPType>
+ </GetFeature>
+ <Transaction>
+ <DCPType>
+ <HTTP>
+ <Get onlineResource="http://127.0.0.1/cgi-bin/tinyows?"/>
+ </HTTP>
+ </DCPType>
+ <DCPType>
+ <HTTP>
+ <Post onlineResource="http://127.0.0.1/cgi-bin/tinyows"/>
+ </HTTP>
+ </DCPType>
+ </Transaction>
+ </Request>
+ </Capability>
+ <FeatureTypeList>
+ <Operations>
+ <Query/>
+ <Insert/>
+ <Update/>
+ <Delete/>
+ </Operations>
+<FeatureType xmlns:tows="http://www.tinyows.org/">
+ <Name>tows:world</Name>
+ <Title>World Administrative Boundaries</Title>
+ <SRS>EPSG:4326</SRS>
+ <LatLongBoundingBox minx='-180.000183' miny='-90.000000' maxx='180.000000' maxy='83.623032' />
+</FeatureType>
+<FeatureType xmlns:tows="http://www.tinyows.org/">
+ <Name>tows:france</Name>
+ <Title>French Administrative Sub Boundaries (IGN - GeoFLA Departements)</Title>
+ <SRS>EPSG:27582</SRS>
+ <LatLongBoundingBox minx='-5.478742' miny='41.363043' maxx='9.559832' maxy='51.089388' />
+</FeatureType>
+ </FeatureTypeList>
+<ogc:Filter_Capabilities>
+ <ogc:Spatial_Capabilities>
+ <ogc:Spatial_Operators>
+ <ogc:Disjoint/>
+ <ogc:Equals/>
+ <ogc:DWithin/>
+ <ogc:Beyond/>
+ <ogc:Intersect/>
+ <ogc:Touches/>
+ <ogc:Crosses/>
+ <ogc:Within/>
+ <ogc:Contains/>
+ <ogc:Overlaps/>
+ <ogc:BBOX/>
+ </ogc:Spatial_Operators>
+ </ogc:Spatial_Capabilities>
+ <ogc:Scalar_Capabilities>
+ <ogc:Logical_Operators/>
+ <ogc:Comparison_Operators>
+ <ogc:Simple_Comparisons/>
+ <ogc:Between/>
+ <ogc:Like/>
+ <ogc:NullCheck/>
+ </ogc:Comparison_Operators>
+ <ogc:Arithmetic_Operators>
+ <ogc:Simple_Arithmetic/>
+ <ogc:Functions>
+ <ogc:Function_Names>
+ <ogc:Function_Name nArgs='1'>abs</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>acos</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>asin</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>atan</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>avg</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>cbrt</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>ceil</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>ceiling</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>cos</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>cot</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>count</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>degrees</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>exp</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>floor</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>length</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>ln</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>log</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>min</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>max</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>radians</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>round</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>sin</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>sqrt</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>tan</ogc:Function_Name>
+ <ogc:Function_Name nArgs='1'>trunc</ogc:Function_Name>
+ </ogc:Function_Names>
+ </ogc:Functions>
+ </ogc:Arithmetic_Operators>
+ </ogc:Scalar_Capabilities>
+</ogc:Filter_Capabilities>
+</WFS_Capabilities>
Added: core/trunk/geoext/examples/wfs-capabilities.html
===================================================================
--- core/trunk/geoext/examples/wfs-capabilities.html (rev 0)
+++ core/trunk/geoext/examples/wfs-capabilities.html 2011-05-16 19:02:13 UTC (rev 2697)
@@ -0,0 +1,25 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-3.2.1/resources/css/ext-all.css" />
+ <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-3.2.1/examples/shared/examples.css" />
+ <title>GeoExt WFS Capabilities Example</title>
+ </head>
+ <body>
+ <h1 id="title">GeoExt WFS Capabilities Example</h1>
+ <p>
+ This example shows how to load a grid with data from a WFS
+ capabilities document. Also shows how to have layer-specific object as
+ properties of the 'layerOptions' property by using a function returning
+ them.
+ </p>
+ <div id="capgrid"></div>
+ <script src="http://extjs.cachefly.net/ext-3.2.1/adapter/ext/ext-base.js"
+ type="text/javascript"></script>
+ <script src="http://extjs.cachefly.net/ext-3.2.1/ext-all.js"
+ type="text/javascript" ></script>
+ <script src="http://www.openlayers.org/api/2.10/OpenLayers.js"
+ type="text/javascript"></script>
+ <script src="../lib/GeoExt.js" type="text/javascript"></script>
+ <script src="wfs-capabilities.js" type="text/javascript"></script>
+ </body>
+</html>
Added: core/trunk/geoext/examples/wfs-capabilities.js
===================================================================
--- core/trunk/geoext/examples/wfs-capabilities.js (rev 0)
+++ core/trunk/geoext/examples/wfs-capabilities.js 2011-05-16 19:02:13 UTC (rev 2697)
@@ -0,0 +1,51 @@
+/**
+ * Copyright (c) 2008-2011 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+
+/** api: example[wfs-capabilities]
+ * WFS Capabilities Store
+ * ----------------------
+ * Create layer records from WFS capabilities documents.
+ */
+
+var store;
+
+Ext.onReady(function() {
+
+ // create a new WFS capabilities store
+ store = new GeoExt.data.WFSCapabilitiesStore({
+ url: "data/wfscap_tiny_100.xml",
+ // set as a function that returns a hash of layer options. This allows
+ // to have new objects created upon each new OpenLayers.Layer.Vector
+ // object creations.
+ layerOptions: function() {
+ return {
+ visibility: false,
+ displayInLayerSwitcher: false,
+ strategies: [new OpenLayers.Strategy.BBOX({ratio: 1})]
+ };
+ }
+ });
+ // load the store with records derived from the doc at the above url
+ store.load();
+
+ // create a grid to display records from the store
+ var grid = new Ext.grid.GridPanel({
+ title: "WFS Capabilities",
+ store: store,
+ columns: [
+ {header: "Title", dataIndex: "title", sortable: true, width: 250},
+ {header: "Name", dataIndex: "name", sortable: true},
+ {header: "Namespace", dataIndex: "namespace", sortable: true, width: 150},
+ {id: "description", header: "Description", dataIndex: "abstract"}
+ ],
+ renderTo: "capgrid",
+ height: 300,
+ width: 650
+ });
+});
Modified: core/trunk/geoext/lib/GeoExt/data/WFSCapabilitiesReader.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/WFSCapabilitiesReader.js 2011-05-16 18:58:42 UTC (rev 2696)
+++ core/trunk/geoext/lib/GeoExt/data/WFSCapabilitiesReader.js 2011-05-16 19:02:13 UTC (rev 2697)
@@ -21,8 +21,9 @@
* .. class:: WFSCapabilitiesReader(meta, recordType)
*
* :param meta: ``Object`` Reader configuration from which:
- * ``layerOptions`` is an optional object passed as default options
- * to the ``OpenLayers.Layer.Vector`` constructor.
+ * ``layerOptions`` is an optional object (or function that returns
+ * an object) passed as default options to the
+ * ``OpenLayers.Layer.Vector`` constructor.
* ``protocolOptions`` is an optional set of parameters to pass to the
* ``OpenLayers.Protocol.WFS`` constructor.
* :param recordType: ``Array | Ext.data.Record`` An array of field
@@ -125,8 +126,10 @@
protocol: new OpenLayers.Protocol.WFS(protocolOptions),
strategies: [new OpenLayers.Strategy.Fixed()]
};
- if(this.meta.layerOptions) {
- Ext.apply(layerOptions, this.meta.layerOptions);
+ var metaLayerOptions = this.meta.layerOptions;
+ if (metaLayerOptions) {
+ Ext.apply(layerOptions, Ext.isFunction(metaLayerOptions) ?
+ metaLayerOptions() : metaLayerOptions);
}
values.layer = new OpenLayers.Layer.Vector(
Modified: core/trunk/geoext/tests/lib/GeoExt/data/WFSCapabilitiesReader.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/WFSCapabilitiesReader.html 2011-05-16 18:58:42 UTC (rev 2696)
+++ core/trunk/geoext/tests/lib/GeoExt/data/WFSCapabilitiesReader.html 2011-05-16 19:02:13 UTC (rev 2697)
@@ -61,7 +61,48 @@
t.eq(layer.protocol.url, "http://someserver.com:8080/geoserver/wfs?", "[0] protocol has correct URL");
t.eq(layer.protocol.featureNS, "http://www.openplans.org/spearfish", "[0] protocol has correct featureNS");
}
-
+
+ function test_read_layerOptions(t) {
+ t.plan(6);
+ var reader = new GeoExt.data.WFSCapabilitiesReader({
+ // test layerOptions object
+ layerOptions: {
+ visibility: false,
+ displayInLayerSwitcher: false
+ }
+ });
+ var records = reader.read({responseXML : doc});
+ var record = records.records[0];
+
+ //3 tests -- testing the first record layer properties and objects
+ var layer = record.getLayer();
+ t.eq(layer.displayInLayerSwitcher, false, "(object) layer displayInLayerSwitcher correctly set to false");
+ t.eq(layer.visibility, false, "(object) layer visibility property correctly set to false");
+
+ reader = new GeoExt.data.WFSCapabilitiesReader({
+ // test layerOptions function
+ layerOptions: function() {
+ return {
+ visibility: false,
+ displayInLayerSwitcher: false,
+ strategies: [new OpenLayers.Strategy.BBOX({ratio: 1})]
+ };
+ }
+ });
+ records = reader.read({responseXML : doc});
+ record = records.records[0];
+
+ //3 tests -- testing the first record layer properties and objects
+ var layer = record.getLayer();
+ t.eq(layer.displayInLayerSwitcher, false, "(function) layer displayInLayerSwitcher correctly set to false");
+ t.eq(layer.visibility, false, "(function) layer visibility property correctly set to false");
+ t.eq(layer.strategies[0].CLASS_NAME, "OpenLayers.Strategy.BBOX", "(function) layer first strategy is type OpenLayers.Strategy.BBOX");
+
+ //1 test -- testing the first two records layer strategies. Make
+ // sure they are not the same object instance.
+ var log = layer.strategies[0] !== records.records[1].getLayer().strategies[0];
+ t.ok(log, "Record layer strategies are unique OpenLayers.Strategy.BBOX object instances")
+ }
</script>
<body>
<div id="map"></div>
More information about the Commits
mailing list