diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index d0a6d2d397..7b8e0e9424 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -4,14 +4,9 @@ // @require: OpenLayers/Layer.js // @require: OpenLayers/Util.js OpenLayers.Layer.Grid = Class.create(); -OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), { +OpenLayers.Layer.Grid.prototype = + Object.extend( new OpenLayers.Layer.HTTPRequest(), { - // str: url - url: null, - - // hash: params - params: null, - // tileSize: OpenLayers.Size tileSize: null, @@ -30,23 +25,17 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), { * @param {Object} options Hash of extra options to tag onto the layer */ initialize: function(name, url, params, options) { - var newArguments = arguments; - if (arguments.length > 0) { - newArguments = [name, options]; - } - OpenLayers.Layer.prototype.initialize.apply(this, newArguments); - this.url = url; - this.params = params; + OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this, + arguments); }, /** * */ destroy: function() { - this.params = null; this.clearGrid(); this.grid = null; - OpenLayers.Layer.prototype.destroy.apply(this, arguments); + OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments); }, /** When the layer is added to a map, then we can ask the map for @@ -55,7 +44,7 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), { * @param {OpenLayers.Map} map */ setMap: function(map) { - OpenLayers.Layer.prototype.setMap.apply(this, arguments); + OpenLayers.Layer.HTTPRequest.prototype.setMap.apply(this, arguments); if (this.tileSize == null) { this.tileSize = this.map.getTileSize(); } @@ -243,40 +232,7 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), { } } }, - /** combine the ds's serverPath with its params and the tile's params. - * - * does checking on the serverPath variable, allowing for cases when it - * is supplied with trailing ? or &, as well as cases where not. - * - * return in formatted string like this: - * "server?key1=value1&key2=value2&key3=value3" - * - * @return {str} - */ - getFullRequestString:function(params) { - var requestString = ""; - this.params.SRS = this.map.getProjection(); - // concat tile params with layer params and convert to string - var allParams = Object.extend(this.params, params); - var paramsString = OpenLayers.Util.getParameterString(allParams); - var server = this.url; - var lastServerChar = server.charAt(server.length - 1); - - if ((lastServerChar == "&") || (lastServerChar == "?")) { - requestString = server + paramsString; - } else { - if (server.indexOf('?') == -1) { - //serverPath has no ? -- add one - requestString = server + '?' + paramsString; - } else { - //serverPath contains ?, so must already have paramsString at the end - requestString = server + '&' + paramsString; - } - } - return requestString; - }, - /** go through and remove all tiles from the grid, calling * destroy() on each of them to kill circular references * @@ -310,15 +266,6 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), { // Should be implemented by subclasses }, - /** - * changeParams is designed to allow you to change the - * parameters of a layer after it's created. - * @param {Object} params Hash of new params to use - */ - changeParams:function(params) { - this.params = Object.extend(this.params, OpenLayers.Util.upperCaseObject(params)); - this._initTiles(); - }, /** * @returns Degrees per Pixel diff --git a/lib/OpenLayers/Layer/WFS.js b/lib/OpenLayers/Layer/WFS.js index 03c2928569..1a43dc7eee 100644 --- a/lib/OpenLayers/Layer/WFS.js +++ b/lib/OpenLayers/Layer/WFS.js @@ -117,6 +117,38 @@ OpenLayers.Layer.WFS.prototype = }, + + /** + * Catch changeParams and uppercase the new params to be merged in + * before calling changeParams on the super class. + * + * Once params have been changed, we will need to re-init our tiles + * + * @param {Object} params Hash of new params to use + */ + mergeNewParams:function(params) { + var upperParams = OpenLayers.Util.upperCaseObject(params); + var newArguments = [upperParams]; + OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, newArguments); + + this._initTiles(); + }, + + /** combine the layer's url with its params and these newParams. + * + * Add the SRS parameter from getProjection() -- this is probably + * more eloquently done via a setProjection() method, but this + * works for now and always. + * + * @param {Object} newParams + * + * @type String + */ + getFullRequestString:function(newParams) { + this.params.SRS = this.map.getProjection(); + return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( + this, arguments); + }, /** @final @type String */ CLASS_NAME: "OpenLayers.Layer.WFS" } diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index b964ab3576..a1ae329080 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -89,6 +89,39 @@ OpenLayers.Layer.WMS.prototype = url, this.tileSize); }, + + /** + * Catch changeParams and uppercase the new params to be merged in + * before calling changeParams on the super class. + * + * Once params have been changed, we will need to re-init our tiles + * + * @param {Object} params Hash of new params to use + */ + mergeNewParams:function(params) { + var upperParams = OpenLayers.Util.upperCaseObject(params); + var newArguments = [upperParams]; + OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, newArguments); + + this._initTiles(); + }, + + /** combine the layer's url with its params and these newParams. + * + * Add the SRS parameter from getProjection() -- this is probably + * more eloquently done via a setProjection() method, but this + * works for now and always. + * + * @param {Object} newParams + * + * @type String + */ + getFullRequestString:function(newParams) { + this.params.SRS = this.map.getProjection(); + return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( + this, arguments); + }, + /** @final @type String */ CLASS_NAME: "OpenLayers.Layer.WMS" });