3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 var name = "Vector Layer";
8 function test_Layer_WFS_constructor(t) {
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");
18 function test_Layer_WFS_getDataExtent(t) {
21 var layer = new OpenLayers.Layer.WFS(name, "url", {});
22 layer.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0, 0)));
23 layer.addFeatures(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0, 1)));
24 t.eq(layer.getDataExtent().toBBOX(), "0,0,0,1", "bbox is correctly pulled from vectors.");
28 function test_Layer_WFS_setOpacity(t) {
31 var layer = new OpenLayers.Layer.WFS(name, "url", {});
33 t.eq(layer.opacity, 0.5, "vector setOpacity didn't fail");
34 var layer = new OpenLayers.Layer.WFS(name, "url", {}, {'featureClass': OpenLayers.Feature.WFS});
35 var marker = new OpenLayers.Marker(new OpenLayers.LonLat(0,0));
36 marker.setOpacity = function() {
37 t.ok(true, "Marker setOpacity was called");
39 layer.addMarker(marker);
41 t.eq(layer.opacity, 0.6, "setOpacity didn't fail on markers");
44 function test_Layer_WFS_destroy(t) {
47 var tVectorDestroy = OpenLayers.Layer.Vector.prototype.destroy;
48 OpenLayers.Layer.Vector.prototype.destroy = function() {
49 g_VectorDestroyed = true;
52 var tMarkersDestroy = OpenLayers.Layer.Markers.prototype.destroy;
53 OpenLayers.Layer.Markers.prototype.destroy = function() {
54 g_MarkersDestroyed = true;
60 'destroy': function() {
61 t.ok(true, "wfs layer's tile is destroyed");
68 'destroy': function() {
69 t.ok(true, "wfs layer's format object is destroyed");
74 'extractAttributes': {}
77 //this call should set off two tests (destroys for tile and format object)
78 g_VectorDestroyed = null;
79 g_MarkersDestroyed = null;
80 OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []);
82 t.ok(g_VectorDestroyed && !g_MarkersDestroyed, "when vector mode is set to true, the default vector layer's destroy() method is called");
83 t.eq(layer.vectorMode, null, "'vectorMode' property nullified");
84 t.eq(layer.tile, null, "'tile' property nullified");
85 t.eq(layer.ratio, null, "'ratio' property nullified");
86 t.eq(layer.featureClass, null, "'featureClass' property nullified");
87 t.eq(layer.format, null, "'format' property nullified");
88 t.eq(layer.formatObject, null, "'formatObject' property nullified");
89 t.eq(layer.formatOptions, null, "'formatOptions' property nullified");
90 t.eq(layer.encodeBBOX, null, "'encodeBBOX' property nullified");
91 t.eq(layer.extractAttributes, null, "'extractAttributes' property nullified");
93 layer.vectorMode = false;
95 //this call will *not* set off two tests (tile and format object are null)
96 g_VectorDestroyed = null;
97 g_MarkersDestroyed = null;
98 OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []);
99 t.ok(!g_VectorDestroyed && g_MarkersDestroyed, "when vector mode is set to false, the default markers layer's destroy() method is called");
101 OpenLayers.Layer.Vector.prototype.destroy = tVectorDestroy;
102 OpenLayers.Layer.Markers.prototype.destroy = tMarkersDestroy;
105 function test_Layer_WFS_mapresizevector(t) {
108 var map = new OpenLayers.Map("map");
109 map.addLayer(new OpenLayers.Layer.WMS("WMS", "url", {}));
110 var layer = new OpenLayers.Layer.WFS(name, "url", {});
111 t.ok(layer.renderer.CLASS_NAME, "layer has a renderer");
114 layer.renderer.setSize = function() { setSize = true; }
116 t.eq(setSize, true, "Renderer resize called on map size change.");
120 function test_Layer_WFS_drawmap(t) {
122 var map = new OpenLayers.Map('map');
123 layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
124 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
127 layer = new OpenLayers.Layer.WFS( "Owl Survey",
128 "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?",
129 {typename: "OWLS", maxfeatures: 10},
130 { featureClass: OpenLayers.Feature.WFS});
132 map.addControl(new OpenLayers.Control.LayerSwitcher());
134 map.setCenter(new OpenLayers.LonLat(-100, 60), 3);
135 } catch (Exception) {
137 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");
139 var map = new OpenLayers.Map('map');
140 layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
141 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'}
145 layer = new OpenLayers.Layer.WFS( "Owl Survey",
146 "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?",
147 {typename: "OWLS", maxfeatures: 10},
148 { featureClass: OpenLayers.Feature.WFS, 'encodeBBOX': true});
150 map.addControl(new OpenLayers.Control.LayerSwitcher());
152 map.setCenter(new OpenLayers.LonLat(-100, 60), 3);
153 } catch (Exception) {
155 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");
158 function test_projection_srs(t) {
160 var map = new OpenLayers.Map('map');
161 map.addLayer(new OpenLayers.Layer("",{isBaseLayer: true} ));
162 // we use an empty moveTo function because we don't want to request tiles
163 var layer = new OpenLayers.Layer.WFS("","",{},{'projection': new OpenLayers.Projection("EPSG:900913"),
164 moveTo: function() {}});
166 map.zoomToMaxExtent();
167 var params = OpenLayers.Util.getParameters(layer.getFullRequestString());
168 t.eq(params.SRS, "EPSG:900913", "SRS represents projection of WFS layer, instead of map (#1537)");
175 <div id="map" style="width:500px;height:550px"></div>