We are dealing with strings for comparison
Because OpenLayers.Util.getParameters turns comma delimited values into arrays, comparing e.g. bbox values in urls will return false. By introducing a splitArgs option, we can use getParameters in a way that leaves such values as strings and makes them comparable in OpenLayers.Util.isEquivalentUrl.
This commit is contained in:
committed by
Bart van den Eijnden
parent
7c5afe1acf
commit
8b4592e71a
@@ -866,11 +866,17 @@ OpenLayers.Util.destinationVincenty = function(lonlat, brng, dist) {
|
|||||||
* url - {String} Optional url used to extract the query string.
|
* url - {String} Optional url used to extract the query string.
|
||||||
* If url is null or is not supplied, query string is taken
|
* If url is null or is not supplied, query string is taken
|
||||||
* from the page location.
|
* from the page location.
|
||||||
|
* options - {Object} Additional options. Optional.
|
||||||
|
*
|
||||||
|
* Valid options:
|
||||||
|
* splitArgs - {Boolean} Split comma delimited params into arrays? Default is
|
||||||
|
* true.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Object} An object of key/value pairs from the query string.
|
* {Object} An object of key/value pairs from the query string.
|
||||||
*/
|
*/
|
||||||
OpenLayers.Util.getParameters = function(url) {
|
OpenLayers.Util.getParameters = function(url, options) {
|
||||||
|
options = options || {};
|
||||||
// if no url specified, take it from the location bar
|
// if no url specified, take it from the location bar
|
||||||
url = (url === null || url === undefined) ? window.location.href : url;
|
url = (url === null || url === undefined) ? window.location.href : url;
|
||||||
|
|
||||||
@@ -906,7 +912,9 @@ OpenLayers.Util.getParameters = function(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// follow OGC convention of comma delimited values
|
// follow OGC convention of comma delimited values
|
||||||
|
if (options.splitArgs !== false) {
|
||||||
value = value.split(",");
|
value = value.split(",");
|
||||||
|
}
|
||||||
|
|
||||||
//if there's only one value, do not return as array
|
//if there's only one value, do not return as array
|
||||||
if (value.length == 1) {
|
if (value.length == 1) {
|
||||||
@@ -1299,7 +1307,8 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) {
|
|||||||
OpenLayers.Util.applyDefaults(options, {
|
OpenLayers.Util.applyDefaults(options, {
|
||||||
ignoreCase: true,
|
ignoreCase: true,
|
||||||
ignorePort80: true,
|
ignorePort80: true,
|
||||||
ignoreHash: true
|
ignoreHash: true,
|
||||||
|
splitArgs: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var urlObj1 = OpenLayers.Util.createUrlObject(url1, options);
|
var urlObj1 = OpenLayers.Util.createUrlObject(url1, options);
|
||||||
@@ -1340,6 +1349,8 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) {
|
|||||||
* ignoreCase - {Boolean} lowercase url,
|
* ignoreCase - {Boolean} lowercase url,
|
||||||
* ignorePort80 - {Boolean} don't include explicit port if port is 80,
|
* ignorePort80 - {Boolean} don't include explicit port if port is 80,
|
||||||
* ignoreHash - {Boolean} Don't include part of url after the hash (#).
|
* ignoreHash - {Boolean} Don't include part of url after the hash (#).
|
||||||
|
* splitArgs - {Boolean} Split comma delimited params into arrays? Default is
|
||||||
|
* true.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Object} An object with separate url, a, port, host, and args parsed out
|
* {Object} An object with separate url, a, port, host, and args parsed out
|
||||||
@@ -1395,7 +1406,8 @@ OpenLayers.Util.createUrlObject = function(url, options) {
|
|||||||
var qMark = url.indexOf("?");
|
var qMark = url.indexOf("?");
|
||||||
queryString = (qMark != -1) ? url.substr(qMark) : "";
|
queryString = (qMark != -1) ? url.substr(qMark) : "";
|
||||||
}
|
}
|
||||||
urlObject.args = OpenLayers.Util.getParameters(queryString);
|
urlObject.args = OpenLayers.Util.getParameters(queryString,
|
||||||
|
{splitArgs: options.splitArgs});
|
||||||
|
|
||||||
// pathname
|
// pathname
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -783,7 +783,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Util_isEquivalentUrl(t) {
|
function test_Util_isEquivalentUrl(t) {
|
||||||
t.plan(9);
|
t.plan(10);
|
||||||
|
|
||||||
var url1, url2, options;
|
var url1, url2, options;
|
||||||
|
|
||||||
@@ -846,6 +846,11 @@
|
|||||||
url2 = new Array(window.location.pathname.split("/").length-1).join("../")+"foo/bar";
|
url2 = new Array(window.location.pathname.split("/").length-1).join("../")+"foo/bar";
|
||||||
|
|
||||||
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "absolute and relative path without host works for "+url2)
|
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "absolute and relative path without host works for "+url2)
|
||||||
|
|
||||||
|
//ARGS
|
||||||
|
url1 = "foo.html?bbox=1,2,3,4",
|
||||||
|
url2 = url1;
|
||||||
|
t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "equal urls with comma delimited params are equal");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_createUrlObject(t) {
|
function test_createUrlObject(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user