Fix MapServer request string handling by overriding getFullRequestUrl(). Fixes #508.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@2544 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -86,16 +86,84 @@ OpenLayers.Layer.MapServer.prototype =
|
||||
*/
|
||||
getURL: function (bounds) {
|
||||
|
||||
// Make a list, so that getFullRequestString uses literal ","
|
||||
var extent = [bounds.left, bounds. bottom, bounds.right, bounds.top];
|
||||
|
||||
// make lists, so that literal ','s are used
|
||||
var url = this.getFullRequestString(
|
||||
{mapext:bounds.toBBOX().replace(/,/g,"+"),
|
||||
imgext:bounds.toBBOX().replace(/,/g,"+"),
|
||||
map_size:this.tileSize.w+'+'+this.tileSize.h,
|
||||
{mapext: extent,
|
||||
imgext: extent,
|
||||
map_size: [this.tileSize.w,this.tileSize.h],
|
||||
imgx: this.tileSize.w/2,
|
||||
imgy: this.tileSize.h/2,
|
||||
imgxy: this.tileSize.w+"+"+this.tileSize.h
|
||||
imgxy: [this.tileSize.w,this.tileSize.h]
|
||||
});
|
||||
|
||||
return url;
|
||||
},
|
||||
|
||||
/**
|
||||
* getFullRequestString on MapServer layers is special, because we
|
||||
* do a regular expression replace on ',' in parameters to '+'.
|
||||
* This is why it is subclassed here.
|
||||
*
|
||||
* @param {Object} newParams Parameters to add to the default parameters
|
||||
* for the layer.
|
||||
* @param {String} altUrl Alternative base URL to use.
|
||||
*/
|
||||
getFullRequestString:function(newParams, altUrl) {
|
||||
|
||||
|
||||
// use layer's url unless altUrl passed in
|
||||
var url = (altUrl == null) ? this.url : altUrl;
|
||||
|
||||
// if url is not a string, it should be an array of strings,
|
||||
// in which case we will randomly select one of them in order
|
||||
// to evenly distribute requests to different urls.
|
||||
if (typeof url == "object") {
|
||||
url = url[Math.floor(Math.random()*url.length)];
|
||||
}
|
||||
// requestString always starts with url
|
||||
var requestString = url;
|
||||
|
||||
// create a new params hashtable with all the layer params and the
|
||||
// new params together. then convert to string
|
||||
var allParams = OpenLayers.Util.extend(new Object(), this.params);
|
||||
allParams = OpenLayers.Util.extend(allParams, newParams);
|
||||
// ignore parameters that are already in the url search string
|
||||
var urlParams = OpenLayers.Util.upperCaseObject(
|
||||
OpenLayers.Util.getArgs(url));
|
||||
for(var key in allParams) {
|
||||
if(key.toUpperCase() in urlParams) {
|
||||
delete allParams[key];
|
||||
}
|
||||
}
|
||||
var paramsString = OpenLayers.Util.getParameterString(allParams);
|
||||
|
||||
/* MapServer needs '+' seperating things like bounds/height/width.
|
||||
Since typically this is URL encoded, we use a slight hack: we
|
||||
depend on the list-like functionality of getParameterString to
|
||||
leave ',' only in the case of list items (since otherwise it is
|
||||
encoded) then do a regular expression replace on the , characters
|
||||
to '+' */
|
||||
paramsString = paramsString.replace(/,/g, "+");
|
||||
|
||||
if (paramsString != "") {
|
||||
var lastServerChar = url.charAt(url.length - 1);
|
||||
if ((lastServerChar == "&") || (lastServerChar == "?")) {
|
||||
requestString += paramsString;
|
||||
} else {
|
||||
if (url.indexOf('?') == -1) {
|
||||
//serverPath has no ? -- add one
|
||||
requestString += '?' + paramsString;
|
||||
} else {
|
||||
//serverPath contains ?, so must already have paramsString at the end
|
||||
requestString += '&' + paramsString;
|
||||
}
|
||||
}
|
||||
}
|
||||
return requestString;
|
||||
},
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Layer.MapServer"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user