Pull in euzuro's patch from #366 - changing how maxResolution is set and a number of other efficiency changes
git-svn-id: http://svn.openlayers.org/trunk/openlayers@1737 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
|
||||
* for the full text of the license. */
|
||||
|
||||
/**
|
||||
* @fileoverview Image Layer
|
||||
* @author Tim Schaub
|
||||
@@ -15,9 +16,11 @@ OpenLayers.Layer.Image = OpenLayers.Class.create();
|
||||
OpenLayers.Layer.Image.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Layer, {
|
||||
|
||||
/** @type String */
|
||||
name: null,
|
||||
|
||||
/** By default, Layer.Image will be a baselayer
|
||||
*
|
||||
* @type Boolean */
|
||||
isBaseLayer: true,
|
||||
|
||||
/** @type String */
|
||||
url: null,
|
||||
|
||||
@@ -27,14 +30,10 @@ OpenLayers.Layer.Image.prototype =
|
||||
/** @type OpenLayers.Size */
|
||||
size: null,
|
||||
|
||||
/** @type Object */
|
||||
options: null,
|
||||
|
||||
/** @type OpenLayers.Tile.Image */
|
||||
tile: null,
|
||||
|
||||
/**
|
||||
* The ratio of height/width represented by a single pixel in the graphic
|
||||
/** The ratio of height/width represented by a single pixel in the graphic
|
||||
*
|
||||
* @type Float */
|
||||
aspectRatio: null,
|
||||
@@ -52,14 +51,10 @@ OpenLayers.Layer.Image.prototype =
|
||||
this.url = url;
|
||||
this.extent = extent;
|
||||
this.size = size;
|
||||
this.aspectRatio = (this.extent.getHeight() / this.size.h) /
|
||||
(this.extent.getWidth() / this.size.w);
|
||||
OpenLayers.Layer.prototype.initialize.apply(this, [name, options]);
|
||||
|
||||
// unless explicitly set in options, the layer will be a base layer
|
||||
if((options == null) || (options.isBaseLayer == null)) {
|
||||
this.isBaseLayer = true;
|
||||
}
|
||||
this.aspectRatio = (this.extent.getHeight() / this.size.h) /
|
||||
(this.extent.getWidth() / this.size.w);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -95,41 +90,19 @@ OpenLayers.Layer.Image.prototype =
|
||||
return obj;
|
||||
},
|
||||
|
||||
/**
|
||||
* This is a bad method to have here. It would be nicer to be able
|
||||
* to ask Layer directly.
|
||||
*/
|
||||
shouldCalcResolutions: function() {
|
||||
var props = new Array(
|
||||
'scales', 'resolutions',
|
||||
'maxScale', 'minScale',
|
||||
'maxResolution', 'minResolution',
|
||||
'minExtent', 'maxExtent',
|
||||
'numZoomLevels', 'maxZoomLevel'
|
||||
);
|
||||
for(var i=0; i < props.length; i++) {
|
||||
var property = props[i];
|
||||
if(this.options[property] != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Map} map
|
||||
*/
|
||||
setMap: function(map) {
|
||||
// If nothing to do with resolutions has been set, assume a single
|
||||
// resolution determined by extent/size
|
||||
if(this.shouldCalcResolutions()) {
|
||||
this.options.resolutions = [this.extent.getWidth() / this.size.w];
|
||||
if( this.options.maxResolution == null ) {
|
||||
this.options.maxResolution = this.extent.getWidth() / this.size.w;
|
||||
}
|
||||
OpenLayers.Layer.prototype.setMap.apply(this, arguments);
|
||||
},
|
||||
|
||||
/** When zooming or first rendering, create a new tile for the image.
|
||||
/** Create the tile for the image or resize it for the new resolution
|
||||
*
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
* @param {Boolean} zoomChanged
|
||||
@@ -142,15 +115,6 @@ OpenLayers.Layer.Image.prototype =
|
||||
|
||||
if(zoomChanged || firstRendering) {
|
||||
|
||||
//clear out the old tile
|
||||
if(this.tile) {
|
||||
this.tile.destroy();
|
||||
this.tile = null;
|
||||
}
|
||||
|
||||
//determine new tile bounds
|
||||
var tileBounds = this.extent.clone();
|
||||
|
||||
//determine new tile size
|
||||
var tileWidth = this.extent.getWidth() / this.map.getResolution();
|
||||
var tileHeight = this.extent.getHeight() /
|
||||
@@ -158,11 +122,18 @@ OpenLayers.Layer.Image.prototype =
|
||||
var tileSize = new OpenLayers.Size(tileWidth, tileHeight);
|
||||
|
||||
//determine new position (upper left corner of new bounds)
|
||||
var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top);
|
||||
var pos = this.map.getLayerPxFromLonLat(ul);
|
||||
var ul = new OpenLayers.LonLat(this.extent.left, this.extent.top);
|
||||
var ulPx = this.map.getLayerPxFromLonLat(ul);
|
||||
|
||||
this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds,
|
||||
this.url, tileSize);
|
||||
if(firstRendering) {
|
||||
//create the new tile
|
||||
this.tile = new OpenLayers.Tile.Image(this, ulPx, this.extent,
|
||||
this.url, tileSize);
|
||||
} else {
|
||||
//just resize the tile and set it's new position
|
||||
this.tile.size = tileSize.clone();
|
||||
this.tile.position = ulPx.clone();
|
||||
}
|
||||
this.tile.draw();
|
||||
}
|
||||
},
|
||||
@@ -172,10 +143,13 @@ OpenLayers.Layer.Image.prototype =
|
||||
*/
|
||||
setUrl: function(newUrl) {
|
||||
this.url = newUrl;
|
||||
this.moveTo();
|
||||
this.draw();
|
||||
},
|
||||
|
||||
/**
|
||||
/** The url we return is always the same (the image itself never changes)
|
||||
* so we can ignore the bounds parameter (it will always be the same,
|
||||
* anyways)
|
||||
*
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*/
|
||||
getURL: function(bounds) {
|
||||
|
||||
Reference in New Issue
Block a user