#616: untiled layers set layer.tileSize on setMap and every moveTo

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2974 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-04-02 15:13:50 +00:00
parent d68caa00a5
commit 9e688ebb37
2 changed files with 249 additions and 247 deletions
+238 -237
View File
@@ -1,237 +1,238 @@
/* Copyright (c) 2006-2007 MetaCarta, Inc., published under the BSD license. /* Copyright (c) 2006-2007 MetaCarta, Inc., published under the BSD license.
* See http://svn.openlayers.org/trunk/openlayers/release-license.txt * See http://svn.openlayers.org/trunk/openlayers/release-license.txt
* for the full text of the license. */ * for the full text of the license. */
/* Derived from the WMS/Untiled.js script by Stephen Woodbridge, 2007 */ /* Derived from the WMS/Untiled.js script by Stephen Woodbridge, 2007 */
/** /**
* @class * @class
* *
* @requires OpenLayers/Layer/HTTPRequest.js * @requires OpenLayers/Layer/HTTPRequest.js
* @requires OpenLayers/Layer/MapServer.js * @requires OpenLayers/Layer/MapServer.js
*/ */
OpenLayers.Layer.MapServer.Untiled = OpenLayers.Class.create(); OpenLayers.Layer.MapServer.Untiled = OpenLayers.Class.create();
OpenLayers.Layer.MapServer.Untiled.prototype = OpenLayers.Layer.MapServer.Untiled.prototype =
OpenLayers.Class.inherit( OpenLayers.Layer.HTTPRequest, { OpenLayers.Class.inherit( OpenLayers.Layer.HTTPRequest, {
/** Hashtable of default parameter key/value pairs /** Hashtable of default parameter key/value pairs
* @final @type Object */ * @final @type Object */
default_params: { default_params: {
mode: "map", mode: "map",
map_imagetype: "png" map_imagetype: "png"
}, },
reproject: true, reproject: true,
/** the ratio of image/tile size to map size (this is the untiled buffer) /** the ratio of image/tile size to map size (this is the untiled buffer)
* @type int */ * @type int */
ratio: 1, ratio: 1,
/** @type OpenLayers.Tile.Image */ /** @type OpenLayers.Tile.Image */
tile: null, tile: null,
/** did the image finish loading before a new draw was initiated? /** did the image finish loading before a new draw was initiated?
* @type Boolean */ * @type Boolean */
doneLoading: false, doneLoading: false,
/** /**
* @constructor * @constructor
* *
* @param {String} name * @param {String} name
* @param {String} url * @param {String} url
* @param {Object} params * @param {Object} params
*/ */
initialize: function(name, url, params, options) { initialize: function(name, url, params, options) {
var newArguments = []; var newArguments = [];
newArguments.push(name, url, params, options); newArguments.push(name, url, params, options);
OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this, OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this,
newArguments); newArguments);
OpenLayers.Util.applyDefaults( OpenLayers.Util.applyDefaults(
this.params, this.params,
this.default_params this.default_params
); );
// unless explicitly set in options, if the layer is transparent, // unless explicitly set in options, if the layer is transparent,
// it will be an overlay // it will be an overlay
if ((options == null) || (options.isBaseLayer == null)) { if ((options == null) || (options.isBaseLayer == null)) {
this.isBaseLayer = ((this.params.transparent != "true") && this.isBaseLayer = ((this.params.transparent != "true") &&
(this.params.transparent != true)); (this.params.transparent != true));
} }
}, },
/** /**
* *
*/ */
destroy: function() { destroy: function() {
if (this.tile) { if (this.tile) {
this.tile.destroy(); this.tile.destroy();
this.tile = null; this.tile = null;
} }
OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments); OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments);
}, },
/** /**
* @param {Object} obj * @param {Object} obj
* *
* @returns An exact clone of this OpenLayers.Layer.MapServer.Untiled * @returns An exact clone of this OpenLayers.Layer.MapServer.Untiled
* @type OpenLayers.Layer.MapServer.Untiled * @type OpenLayers.Layer.MapServer.Untiled
*/ */
clone: function (obj) { clone: function (obj) {
if (obj == null) { if (obj == null) {
obj = new OpenLayers.Layer.MapServer.Untiled(this.name, obj = new OpenLayers.Layer.MapServer.Untiled(this.name,
this.url, this.url,
this.params, this.params,
this.options); this.options);
} }
//get all additions from superclasses //get all additions from superclasses
obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]); obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]);
// copy/set any non-init, non-simple values here // copy/set any non-init, non-simple values here
return obj; return obj;
}, },
/** Once HTTPRequest has set the map, we can load the image div /** Once HTTPRequest has set the map, we can load the image div
* *
* @param {OpenLayers.Map} map * @param {OpenLayers.Map} map
*/ */
setMap: function(map) { setMap: function(map) {
OpenLayers.Layer.HTTPRequest.prototype.setMap.apply(this, arguments); //determine new tile size
}, this.tileSize = map.getSize();
this.tileSize.w = this.tileSize.w * this.ratio;
/** When it is not a dragging move (ie when done dragging) this.tileSize.h = this.tileSize.h * this.ratio;
* reload and recenter the div. OpenLayers.Layer.HTTPRequest.prototype.setMap.apply(this, arguments);
* },
* @param {OpenLayers.Bounds} bounds
* @param {Boolean} zoomChanged /** When it is not a dragging move (ie when done dragging)
* @param {Boolean} dragging * reload and recenter the div.
*/ *
moveTo:function(bounds, zoomChanged, dragging) { * @param {OpenLayers.Bounds} bounds
if (!this.doneLoading) { * @param {Boolean} zoomChanged
this.events.triggerEvent("loadcancel"); * @param {Boolean} dragging
this.doneLoading = true; */
} moveTo:function(bounds, zoomChanged, dragging) {
OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this,arguments); if (!this.doneLoading) {
this.events.triggerEvent("loadcancel");
if (bounds == null) { this.doneLoading = true;
bounds = this.map.getExtent(); }
} OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this,arguments);
var firstRendering = (this.tile == null); if (bounds == null) {
bounds = this.map.getExtent();
//does the new bounds to which we need to move fall outside of the }
// current tile's bounds?
var outOfBounds = (!firstRendering && var firstRendering = (this.tile == null);
!this.tile.bounds.containsBounds(bounds));
//does the new bounds to which we need to move fall outside of the
if ( zoomChanged || firstRendering || (!dragging && outOfBounds) ) { // current tile's bounds?
var outOfBounds = (!firstRendering &&
//clear out the old tile !this.tile.bounds.containsBounds(bounds));
if (this.tile) {
this.tile.clear(); if ( zoomChanged || firstRendering || (!dragging && outOfBounds) ) {
}
//clear out the old tile
//determine new tile bounds if (this.tile) {
var center = bounds.getCenterLonLat(); this.tile.clear();
var tileWidth = bounds.getWidth() * this.ratio; }
var tileHeight = bounds.getHeight() * this.ratio;
var tileBounds = //determine new tile bounds
new OpenLayers.Bounds(center.lon - (tileWidth / 2), var center = bounds.getCenterLonLat();
center.lat - (tileHeight / 2), var tileWidth = bounds.getWidth() * this.ratio;
center.lon + (tileWidth / 2), var tileHeight = bounds.getHeight() * this.ratio;
center.lat + (tileHeight / 2)); var tileBounds =
new OpenLayers.Bounds(center.lon - (tileWidth / 2),
//determine new tile size center.lat - (tileHeight / 2),
var tileSize = this.map.getSize(); center.lon + (tileWidth / 2),
tileSize.w = tileSize.w * this.ratio; center.lat + (tileHeight / 2));
tileSize.h = tileSize.h * this.ratio;
//determine new tile size
//formulate request url string this.tileSize = this.map.getSize();
var url = this.getURL(tileBounds); this.tileSize.w = this.tileSize.w * this.ratio;
this.tileSize.h = this.tileSize.h * this.ratio;
//determine new position (upper left corner of new bounds)
var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top); //formulate request url string
var pos = this.map.getLayerPxFromLonLat(ul); var url = this.getURL(tileBounds);
if ( this.tile && !this.tile.size.equals(tileSize)) { //determine new position (upper left corner of new bounds)
this.tile.destroy(); var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top);
this.tile = null; var pos = this.map.getLayerPxFromLonLat(ul);
}
if ( this.tile && !this.tile.size.equals(this.tileSize)) {
this.events.triggerEvent("loadstart"); this.tile.destroy();
this.doneLoading = false; this.tile = null;
if (!this.tile) { }
this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds,
url, tileSize); this.events.triggerEvent("loadstart");
this.tile.draw(); this.doneLoading = false;
var onload = function() { if (!this.tile) {
this.doneLoading = true; this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds,
this.events.triggerEvent("loadend"); url, this.tileSize);
} this.tile.draw();
OpenLayers.Event.observe(this.tile.imgDiv, 'load', var onload = function() {
onload.bindAsEventListener(this)); this.doneLoading = true;
} else { this.events.triggerEvent("loadend");
this.tile.moveTo(tileBounds, pos); }
} OpenLayers.Event.observe(this.tile.imgDiv, 'load',
onload.bindAsEventListener(this));
} } else {
}, this.tile.moveTo(tileBounds, pos);
}
getURL: function(bounds) {
var tileSize = this.map.getSize(); }
tileSize.w = tileSize.w * this.ratio; },
tileSize.h = tileSize.h * this.ratio;
var url = this.getFullRequestString( getURL: function(bounds) {
{mapext:bounds.toBBOX().replace(/,/g," "), var url = this.getFullRequestString(
imgext:bounds.toBBOX().replace(/,/g," "), {mapext:bounds.toBBOX().replace(/,/g," "),
map_size:tileSize.w+' '+tileSize.h, imgext:bounds.toBBOX().replace(/,/g," "),
imgx: tileSize.w/2, map_size: this.tileSize.w + " " + this.tileSize.h,
imgy: tileSize.h/2, imgx: this.tileSize.w / 2,
imgxy: tileSize.w+" "+tileSize.h imgy: this.tileSize.h / 2,
}); imgxy: this.tileSize.w + " " + this.tileSize.h
return url; });
}, return url;
},
/** Once HTTPRequest has updated the url, reload the image div
* @param {String} newUrl /** Once HTTPRequest has updated the url, reload the image div
*/ * @param {String} newUrl
setUrl: function(newUrl) { */
OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments); setUrl: function(newUrl) {
this.moveTo(); OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments);
}, this.moveTo();
},
/** Once HTTPRequest has updated new params, reload the image div
* @param {Object} newParams /** Once HTTPRequest has updated new params, reload the image div
*/ * @param {Object} newParams
mergeNewParams:function(newParams) { */
OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this, mergeNewParams:function(newParams) {
[newParams]); OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,
//redraw [newParams]);
this.moveTo(null, true); //redraw
}, this.moveTo(null, true);
},
/** combine the layer's url with its params and these newParams.
* /** combine the layer's url with its params and these newParams.
* Add the SRS parameter from 'projection' -- this is probably *
* more eloquently done via a setProjection() method, but this * Add the SRS parameter from 'projection' -- this is probably
* works for now and always. * more eloquently done via a setProjection() method, but this
* * works for now and always.
* @param {Object} newParams *
* * @param {Object} newParams
* @type String *
*/ * @type String
getFullRequestString:function(newParams) { */
var projection = this.map.getProjection(); getFullRequestString:function(newParams) {
this.params.srs = (projection == "none") ? null : projection; var projection = this.map.getProjection();
this.params.srs = (projection == "none") ? null : projection;
return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
this, arguments); return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
}, this, arguments);
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.MapServer.Untiled" /** @final @type String */
}); CLASS_NAME: "OpenLayers.Layer.MapServer.Untiled"
});
+11 -10
View File
@@ -102,6 +102,10 @@ OpenLayers.Layer.WMS.Untiled.prototype =
* @param {OpenLayers.Map} map * @param {OpenLayers.Map} map
*/ */
setMap: function(map) { setMap: function(map) {
//determine new tile size
this.tileSize = map.getSize();
this.tileSize.w = this.tileSize.w * this.ratio;
this.tileSize.h = this.tileSize.h * this.ratio;
OpenLayers.Layer.HTTPRequest.prototype.setMap.apply(this, arguments); OpenLayers.Layer.HTTPRequest.prototype.setMap.apply(this, arguments);
}, },
@@ -148,9 +152,9 @@ OpenLayers.Layer.WMS.Untiled.prototype =
center.lat + (tileHeight / 2)); center.lat + (tileHeight / 2));
//determine new tile size //determine new tile size
var tileSize = this.map.getSize(); this.tileSize = this.map.getSize();
tileSize.w = tileSize.w * this.ratio; this.tileSize.w = this.tileSize.w * this.ratio;
tileSize.h = tileSize.h * this.ratio; this.tileSize.h = this.tileSize.h * this.ratio;
//formulate request url string //formulate request url string
var url = this.getURL(tileBounds); var url = this.getURL(tileBounds);
@@ -159,7 +163,7 @@ OpenLayers.Layer.WMS.Untiled.prototype =
var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top); var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top);
var pos = this.map.getLayerPxFromLonLat(ul); var pos = this.map.getLayerPxFromLonLat(ul);
if ( this.tile && !this.tile.size.equals(tileSize)) { if ( this.tile && !this.tile.size.equals(this.tileSize)) {
this.tile.destroy(); this.tile.destroy();
this.tile = null; this.tile = null;
} }
@@ -168,7 +172,7 @@ OpenLayers.Layer.WMS.Untiled.prototype =
this.doneLoading = false; this.doneLoading = false;
if (!this.tile) { if (!this.tile) {
this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds, this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds,
url, tileSize); url, this.tileSize);
this.tile.draw(); this.tile.draw();
var onload = function() { var onload = function() {
this.doneLoading = true; this.doneLoading = true;
@@ -184,12 +188,9 @@ OpenLayers.Layer.WMS.Untiled.prototype =
}, },
getURL: function(bounds) { getURL: function(bounds) {
var tileSize = this.map.getSize();
tileSize.w = tileSize.w * this.ratio;
tileSize.h = tileSize.h * this.ratio;
return this.getFullRequestString( {'BBOX': bounds.toBBOX(), return this.getFullRequestString( {'BBOX': bounds.toBBOX(),
'WIDTH': tileSize.w, 'WIDTH': this.tileSize.w,
'HEIGHT': tileSize.h} ); 'HEIGHT': this.tileSize.h} );
}, },