From c8afa7222b84c05d1c0c503b0b9fc290f76b4e53 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Fri, 24 Aug 2007 23:50:43 +0000 Subject: [PATCH] Allow for users to determine whether the bounding box should be encoded or not on WMS and WFS layers. This change, by default, makes us compliant with the WMS spec again. git-svn-id: http://svn.openlayers.org/trunk/openlayers@4038 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/BaseTypes/Bounds.js | 10 ++++++++ lib/OpenLayers/Layer/WFS.js | 10 +++++++- lib/OpenLayers/Layer/WMS.js | 9 ++++++- tests/BaseTypes/test_Bounds.html | 5 ++++ tests/Layer/test_WFS.html | 37 ++++++++++++++++++++++++++++ tests/Layer/test_WMS.html | 39 ++++++++++++++++++++++++++++++ tests/Layer/test_WrapDateLine.html | 4 +-- tests/Tile/test_Image.html | 4 +-- 8 files changed, 112 insertions(+), 6 deletions(-) diff --git a/lib/OpenLayers/BaseTypes/Bounds.js b/lib/OpenLayers/BaseTypes/Bounds.js index cfb6fd36bf..90e7fbce04 100644 --- a/lib/OpenLayers/BaseTypes/Bounds.js +++ b/lib/OpenLayers/BaseTypes/Bounds.js @@ -99,6 +99,16 @@ OpenLayers.Bounds = OpenLayers.Class({ + " right-top=(" + this.right + "," + this.top + ")" ); }, + /** + * APIMethod: toArray + * + * Return: + * {Array} array of left, bottom, right, top + */ + toArray: function() { + return [this.left, this.bottom, this.right, this.top]; + }, + /** * APIMethod: toBBOX * diff --git a/lib/OpenLayers/Layer/WFS.js b/lib/OpenLayers/Layer/WFS.js index a229bd595b..fb5e8d2b02 100644 --- a/lib/OpenLayers/Layer/WFS.js +++ b/lib/OpenLayers/Layer/WFS.js @@ -51,6 +51,13 @@ OpenLayers.Layer.WFS = OpenLayers.Class( * {Boolean} Should be calculated automatically. */ vectorMode: true, + + /** + * APIProperty: encodeBBOX + * {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no', + * but some services want it that way. Default false. + */ + encodeBBOX: false, /** * Constructor: OpenLayers.Layer.WFS @@ -196,7 +203,8 @@ OpenLayers.Layer.WFS = OpenLayers.Class( //formulate request url string var url = this.getFullRequestString(); - var params = { BBOX:tileBounds.toBBOX() }; + var params = {BBOX: this.encodeBBOX ? tileBounds.toBBOX() + : tileBounds.toArray()}; url += "&" + OpenLayers.Util.getParameterString(params); if (!this.tile) { diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index 115be2c611..5e3dff88b2 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -43,6 +43,13 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { * {Boolean} Default is true for WMS layer */ isBaseLayer: true, + + /** + * APIProperty: encodeBBOX + * {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no', + * but some services want it that way. Default false. + */ + encodeBBOX: false, /** * Constructor: OpenLayers.Layer.WMS @@ -146,7 +153,7 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { var imageSize = this.getImageSize(); return this.getFullRequestString( - {BBOX:bounds.toBBOX(), + {BBOX: this.encodeBBOX ? bounds.toBBOX() : bounds.toArray(), WIDTH:imageSize.w, HEIGHT:imageSize.h}); }, diff --git a/tests/BaseTypes/test_Bounds.html b/tests/BaseTypes/test_Bounds.html index 120f1afd05..f9a403fbb0 100644 --- a/tests/BaseTypes/test_Bounds.html +++ b/tests/BaseTypes/test_Bounds.html @@ -60,6 +60,11 @@ bounds = new OpenLayers.Bounds(1,2,3,4); t.eq( bounds.toString(), "left-bottom=(1,2) right-top=(3,4)", "toString() returns correct value." ); } + function test_Bounds_toArray(t) { + t.plan( 1 ); + bounds = new OpenLayers.Bounds(1,2,3,4); + t.eq( bounds.toArray(), [1,2,3,4], "toArray() returns correct value." ); + } function test_04_Bounds_contains(t) { t.plan( 6 ); diff --git a/tests/Layer/test_WFS.html b/tests/Layer/test_WFS.html index 332dcba353..f60411872d 100644 --- a/tests/Layer/test_WFS.html +++ b/tests/Layer/test_WFS.html @@ -28,6 +28,43 @@ t.eq(setSize, true, "Renderer resize called on map size change."); } + function test_Layer_WFS_drawmap(t) { + t.plan(2); + var map = new OpenLayers.Map('map'); + layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", + "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); + map.addLayer(layer); + + layer = new OpenLayers.Layer.WFS( "Owl Survey", + "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?", + {typename: "OWLS", maxfeatures: 10}, + { featureClass: OpenLayers.Feature.WFS}); + map.addLayer(layer); + map.addControl(new OpenLayers.Control.LayerSwitcher()); + try { + map.setCenter(new OpenLayers.LonLat(-100, 60), 3); + } catch (Exception) { + } + 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"); + var map = new OpenLayers.Map('map'); + layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", + "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} + ); + map.addLayer(layer); + + layer = new OpenLayers.Layer.WFS( "Owl Survey", + "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?", + {typename: "OWLS", maxfeatures: 10}, + { featureClass: OpenLayers.Feature.WFS, 'encodeBBOX': true}); + map.addLayer(layer); + map.addControl(new OpenLayers.Control.LayerSwitcher()); + try { + map.setCenter(new OpenLayers.LonLat(-100, 60), 3); + } catch (Exception) { + } + 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"); + } + // --> diff --git a/tests/Layer/test_WMS.html b/tests/Layer/test_WMS.html index 6b2c033382..d222fd8510 100644 --- a/tests/Layer/test_WMS.html +++ b/tests/Layer/test_WMS.html @@ -63,6 +63,45 @@ var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel); tile.draw(); + var img = tile.imgDiv; + var tParams = OpenLayers.Util.extend({}, + OpenLayers.Util.upperCaseObject(params)); + tParams = OpenLayers.Util.extend(tParams, { + SERVICE: "WMS", VERSION: "1.1.1", + REQUEST: "GetMap", STYLES: "", + EXCEPTIONS: "application/vnd.ogc.se_inimage", + SRS: "EPSG:4326", BBOX: [1,2,3,4], + WIDTH: "256", HEIGHT: "256" + }); + t.eq( img.src, + url + "?" + OpenLayers.Util.getParameterString(tParams), + "image src is created correctly via addtile" ); + t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" ); + t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" ); + + var firstChild = layer.div.firstChild.firstChild; + if (!isMozilla) + t.ok( true, "skipping element test outside of Mozilla"); + else + t.ok( firstChild instanceof HTMLElement, "div first child is an image object" ); + t.eq( firstChild.src, + url + "?" + OpenLayers.Util.getParameterString(tParams), + "div first child is correct image object" ); + t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." ); + map.destroy(); + } + + function test_Layer_WMS_bboxEncoding (t) { + t.plan( 6 ); + + var url = "http://octo.metacarta.com/cgi-bin/mapserv"; + layer = new OpenLayers.Layer.WMS(name, url, params, {encodeBBOX:true}); + var map = new OpenLayers.Map('map'); + map.addLayer(layer); + var pixel = new OpenLayers.Pixel(5,6); + var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel); + tile.draw(); + var img = tile.imgDiv; var tParams = OpenLayers.Util.extend({}, OpenLayers.Util.upperCaseObject(params)); diff --git a/tests/Layer/test_WrapDateLine.html b/tests/Layer/test_WrapDateLine.html index aac91045f8..5c668c0d2f 100644 --- a/tests/Layer/test_WrapDateLine.html +++ b/tests/Layer/test_WrapDateLine.html @@ -127,7 +127,7 @@ t.plan( 3 ); var url = "http://octo.metacarta.com/cgi-bin/mapserv"; - layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); + layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true,encodeBBOX:true}); var m = new OpenLayers.Map('map'); m.addLayer(layer); m.zoomToMaxExtent(); @@ -159,7 +159,7 @@ {layers: "bathymetry,land_fn,park,drain_fn,drainage," + "prov_bound,fedlimit,rail,road,popplace", transparent: "true", format: "image/png"}, - {wrapDateLine: true, reproject: false}); + {wrapDateLine: true, reproject: false,encodeBBOX:true}); var m = new OpenLayers.Map('map'); m.addLayers([baselayer,layer]); m.zoomToMaxExtent(); diff --git a/tests/Tile/test_Image.html b/tests/Tile/test_Image.html index dd761beae4..fd578fea12 100644 --- a/tests/Tile/test_Image.html +++ b/tests/Tile/test_Image.html @@ -64,7 +64,7 @@ SERVICE: "WMS", VERSION: "1.1.1", REQUEST: "GetMap", STYLES: "", EXCEPTIONS: "application/vnd.ogc.se_inimage", FORMAT: "image/jpeg", - SRS: "EPSG:4326", BBOX: "1,2,3,4", + SRS: "EPSG:4326", BBOX: [1,2,3,4], WIDTH: String(size.w), HEIGHT: String(size.h) }; t.eq( img.src, @@ -86,7 +86,7 @@ var size = new OpenLayers.Size(5,6); var map = new OpenLayers.Map('map'); var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", - "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, {reproject:false}); + "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, {reproject:false, encodeBBOX: true}); map.addLayer(layer); tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-185,-90,-180,90), url, size); tile.draw()