diff --git a/examples/fullScreen.html b/examples/fullScreen.html index 507536e208..450980936b 100644 --- a/examples/fullScreen.html +++ b/examples/fullScreen.html @@ -14,7 +14,7 @@ var map = new OpenLayers.Map('map'); var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", - "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}); + "http://labs.metacarta.com:80/wms/vmap0?", {layers: 'basic'}); var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic", "http://wms.jpl.nasa.gov/wms.cgi", diff --git a/lib/OpenLayers/Tile/Image.js b/lib/OpenLayers/Tile/Image.js index 56342744f3..113e5add5c 100644 --- a/lib/OpenLayers/Tile/Image.js +++ b/lib/OpenLayers/Tile/Image.js @@ -147,7 +147,7 @@ OpenLayers.Tile.Image.prototype = // from the map, in which case this check is not needed. if (this.layer) { var loaded = this.layer.alpha ? this.imgDiv.firstChild.src : this.imgDiv.src; - if (loaded != this.url) { + if (!OpenLayers.Util.isEquivalentUrl(loaded, this.url)) { this.imgDiv.style.display = "none"; } } diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index a2bac3898e..84f1a538ab 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -709,3 +709,112 @@ OpenLayers.Util.pagePosition = function(forElement) { return [valueL, valueT]; }; + + +/** Test two URLs for equivalence. + * + * Setting 'ignoreCase' allows for case-independent comparison. + * + * Comparison is based on: + * - Protocol + * - Host (evaluated without the port) + * - Port (set 'ignorePort80' to ignore "80" values) + * - Hash ( set 'ignoreHash' to disable) + * - Pathname (for relative <-> absolute comparison) + * - Arguments (so they can be out of order) + * + * + * + * @param {String} url1 + * @param {String} url2 + * @param {Object} options allows for customization of comparison: + * 'ignoreCase' - Default is True + * 'ignorePort80' - Default is True + * 'ignoreHash' - Default is True + * + * @returns Whether or not the two URLs are equivalent + * @type Boolean + */ +OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) { + options = options || new Object(); + + OpenLayers.Util.applyDefaults(options, { + ignoreCase: true, + ignorePort80: true, + ignoreHash: true + }); + + urlObj1 = OpenLayers.Util.createUrlObject(url1, options); + urlObj2 = OpenLayers.Util.createUrlObject(url2, options); + + //compare keys (host, port, etc) + for(var key in urlObj1) { + if ( (key != "args") && (urlObj1[key] != urlObj2[key]) ) { + return false; + } + } + + // compare search args - irrespective of order + for(var key in urlObj1.args) { + if(urlObj1.args[key] != urlObj2.args[key]) { + return false; + } + delete urlObj2.args[key]; + } + // urlObj2 shouldn't have any args left + for(var key in urlObj2.args) { + return false; + } + + return true; +}; + +/** + * @private + * + * @param {String} url + * @param {Object} options + * + * @returns An object with separate url, a, port, host, and args parsed out + * and ready for comparison + * @type Object + */ +OpenLayers.Util.createUrlObject = function(url, options) { + options = options || new Object(); + + var urlObject = new Object(); + + if (options.ignoreCase) { + url = url.toLowerCase(); + } + + var a = document.createElement('a'); + + a.href = url; + + //protocol + urlObject.protocol = a.protocol; + + //pathname (this part allows for relative <-> absolute comparison) + urlObject.pathname = a.pathname; + + //hash + urlObject.hash = (options.ignoreHash) ? "" : a.hash; + + //host (without port) + urlObject.host = a.host; + var port = a.port; + if (port.length <= 0) { + var newHostLength = urlObject.host.length - (port.length); + urlObject.host = urlObject.host.substring(0, newHostLength); + } + + //port + urlObject.port = ((port == "80") && (options.ignorePort80)) ? "" : port; + + //args + urlObject.args = OpenLayers.Util.getArgs(a.search); + + return urlObject; +}; + \ No newline at end of file diff --git a/tests/test_Util.html b/tests/test_Util.html index 87f811880b..ce020c432e 100644 --- a/tests/test_Util.html +++ b/tests/test_Util.html @@ -490,7 +490,71 @@ OpenLayers.ImgPath = ''; t.eq(OpenLayers.Util.getImagesLocation().substr(OpenLayers.Util.getImagesLocation().length-4,4), "img/", "ImgPath works as expected when set to ''."); } - // --> + + function test_15_Util_isEquivalentUrl(t) { + t.plan(8); + + var url1, url2, options; + + //CASE + + url1 = "http://www.openlayers.org"; + url2 = "HTTP://WWW.OPENLAYERS.ORG"; + + t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignoreCase works"); + + //ARGS + + url1 = "http://www.openlayers.org?foo=5;bar=6"; + url2 = "http://www.openlayers.org?bar=6;foo=5"; + + t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "shuffled arguments works"); + + //PORT + + url1 = "http://www.openlayers.org:80"; + url2 = "http://www.openlayers.org"; + + t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignorePort80 works"); + options = { + 'ignorePort80': false + } + + url1 = "http://www.openlayers.org:80"; + url2 = "http://www.openlayers.org:50"; + + t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2), "port check works"); + + + //HASH + + url1 = "http://www.openlayers.org#barf"; + url2 = "http://www.openlayers.org"; + + t.ok(OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignoreHash works"); + options = { + 'ignoreHash': false + } + t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2, options), "ignoreHash FALSE works"); + + //PROTOCOL + + url1 = "http://www.openlayers.org"; + url2 = "ftp://www.openlayers.org"; + + t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2), "default ignoreHash works"); + + + //PATHNAME + url1 = document.location.pathName + "/foo.html"; + url2 = "foo.html"; + + t.ok(!OpenLayers.Util.isEquivalentUrl(url1, url2), "relative vs. absolute paths works"); + + + } + + // -->