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
This commit is contained in:
crschmidt
2007-08-24 23:50:43 +00:00
parent 42e4f72a9f
commit c8afa7222b
8 changed files with 112 additions and 6 deletions

View File

@@ -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
*

View File

@@ -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) {

View File

@@ -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});
},

View File

@@ -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 );

View File

@@ -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");
}
// -->
</script>
</head>

View File

@@ -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));

View File

@@ -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();

View File

@@ -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()