OpenLayers OpenLayers

root/trunk/openlayers/tests/Layer/WFS.html

Revision 7894, 6.3 kB (checked in by ahocevar, 4 months ago)

use empty moveTo function to prevent tiles from actually being requested. (closes #1701)

  • Property svn:eol-style set to native
Line 
1 <html>
2 <head>
3 <script src="../../lib/OpenLayers.js"></script>
4   <script type="text/javascript">
5
6     var name = "Vector Layer";
7    
8     function test_Layer_WFS_constructor(t) {
9         t.plan(3);
10
11         var layer = new OpenLayers.Layer.WFS(name, "url", {});
12         t.ok(layer instanceof OpenLayers.Layer.WFS, "new OpenLayers.Layer.Vector returns correct object" );
13         t.eq(layer.name, name, "layer name is correctly set");
14         t.ok(layer.renderer.CLASS_NAME, "layer has a renderer");
15
16     }
17    
18     function test_Layer_WFS_destroy(t) {
19         t.plan(13);
20        
21         var tVectorDestroy = OpenLayers.Layer.Vector.prototype.destroy;
22         OpenLayers.Layer.Vector.prototype.destroy = function() {
23             g_VectorDestroyed = true;
24         }
25
26         var tMarkersDestroy = OpenLayers.Layer.Markers.prototype.destroy;
27         OpenLayers.Layer.Markers.prototype.destroy = function() {
28             g_MarkersDestroyed = true;
29         }
30
31         var layer = {
32             'vectorMode': true,
33             'tile': {
34                 'destroy': function() {
35                     t.ok(true, "wfs layer's tile is destroyed");
36                 }
37             },
38             'ratio': {},
39             'featureClass': {},
40             'format': {},
41             'formatObject': {
42                 'destroy': function() {
43                     t.ok(true, "wfs layer's format object is destroyed");
44                 }
45             },
46             'formatOptions': {},
47             'encodeBBOX': {},
48             'extractAttributes': {}
49         };
50        
51         //this call should set off two tests (destroys for tile and format object)
52         g_VectorDestroyed = null;
53         g_MarkersDestroyed = null;       
54         OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []);       
55
56         t.ok(g_VectorDestroyed && !g_MarkersDestroyed, "when vector mode is set to true, the default vector layer's destroy() method is called");
57         t.eq(layer.vectorMode, null, "'vectorMode' property nullified");
58         t.eq(layer.tile, null, "'tile' property nullified");
59         t.eq(layer.ratio, null, "'ratio' property nullified");
60         t.eq(layer.featureClass, null, "'featureClass' property nullified");
61         t.eq(layer.format, null, "'format' property nullified");
62         t.eq(layer.formatObject, null, "'formatObject' property nullified");
63         t.eq(layer.formatOptions, null, "'formatOptions' property nullified");
64         t.eq(layer.encodeBBOX, null, "'encodeBBOX' property nullified");
65         t.eq(layer.extractAttributes, null, "'extractAttributes' property nullified");
66
67         layer.vectorMode = false;
68
69         //this call will *not* set off two tests (tile and format object are null)
70         g_VectorDestroyed = null;
71         g_MarkersDestroyed = null;       
72         OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []);       
73         t.ok(!g_VectorDestroyed && g_MarkersDestroyed, "when vector mode is set to false, the default markers layer's destroy() method is called");
74        
75         OpenLayers.Layer.Vector.prototype.destroy = tVectorDestroy;
76         OpenLayers.Layer.Markers.prototype.destroy = tMarkersDestroy;
77     }
78    
79     function test_Layer_WFS_mapresizevector(t) {
80         t.plan(2);
81
82         var map = new OpenLayers.Map("map");
83         map.addLayer(new OpenLayers.Layer.WMS("WMS", "url", {}));
84         var layer = new OpenLayers.Layer.WFS(name, "url", {});
85         t.ok(layer.renderer.CLASS_NAME, "layer has a renderer");
86         map.addLayer(layer);
87         setSize = false;
88         layer.renderer.setSize = function() { setSize = true; }
89         layer.onMapResize();
90         t.eq(setSize, true, "Renderer resize called on map size change.");
91         map.destroy();     
92
93     }
94     function test_Layer_WFS_drawmap(t) {
95         t.plan(2);
96         var map = new OpenLayers.Map('map');
97         layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
98             "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
99         map.addLayer(layer);
100
101         layer = new OpenLayers.Layer.WFS( "Owl Survey",
102             "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?",
103             {typename: "OWLS", maxfeatures: 10},
104             { featureClass: OpenLayers.Feature.WFS});
105         map.addLayer(layer);
106         map.addControl(new OpenLayers.Control.LayerSwitcher());
107         try {
108             map.setCenter(new OpenLayers.LonLat(-100, 60), 3);
109         } catch (Exception) {
110         }   
111         t.eq(layer.tile.url, "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?typename=OWLS&maxfeatures=10&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&SRS=EPSG%3A4326&BBOX=-187.890625,-36.6796875,-12.109375,156.6796875", "Tile URL is set correctly when not encoded");
112         map.destroy();     
113         var map = new OpenLayers.Map('map');
114         layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
115             "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'}
116             );
117         map.addLayer(layer);
118
119         layer = new OpenLayers.Layer.WFS( "Owl Survey",
120             "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?",
121             {typename: "OWLS", maxfeatures: 10},
122             { featureClass: OpenLayers.Feature.WFS, 'encodeBBOX': true});
123         map.addLayer(layer);
124         map.addControl(new OpenLayers.Control.LayerSwitcher());
125         try {
126             map.setCenter(new OpenLayers.LonLat(-100, 60), 3);
127         } catch (Exception) {
128         } 
129         t.eq(layer.tile.url, "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?typename=OWLS&maxfeatures=10&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&SRS=EPSG%3A4326&BBOX=-187.890625%2C-36.679687%2C-12.109375%2C156.679688", "Tile URL is set correctly when not encoded");
130         map.destroy();     
131     }
132     function test_projection_srs(t) {
133         t.plan(1);
134         var map = new OpenLayers.Map('map');
135         map.addLayer(new OpenLayers.Layer("",{isBaseLayer: true} ));
136         // we use an empty moveTo function because we don't want to request tiles
137         var layer = new OpenLayers.Layer.WFS("","",{},{'projection': new OpenLayers.Projection("EPSG:900913"),
138             moveTo: function() {}});
139         map.addLayer(layer);
140         map.zoomToMaxExtent();
141         var params = OpenLayers.Util.getParameters(layer.getFullRequestString());
142         t.eq(params.SRS, "EPSG:900913", "SRS represents projection of WFS layer, instead of map (#1537)");   
143     }
144
145
146   </script>
147 </head>
148 <body>
149 <div id="map" style="width:500px;height:550px"></div>
150 </body>
151 </html>
Note: See TracBrowser for help on using the browser.