[Commits] r1737 - trunk/openlayers/lib/OpenLayers/Layer
commits at openlayers.org
commits at openlayers.org
Wed Oct 25 19:05:23 EDT 2006
Author: tschaub
Date: 2006-10-25 19:05:23 -0400 (Wed, 25 Oct 2006)
New Revision: 1737
Modified:
trunk/openlayers/lib/OpenLayers/Layer/Image.js
Log:
Pull in euzuro's patch from #366 - changing how maxResolution is set and a number of other efficiency changes
Modified: trunk/openlayers/lib/OpenLayers/Layer/Image.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/Image.js 2006-10-25 22:55:44 UTC (rev 1736)
+++ trunk/openlayers/lib/OpenLayers/Layer/Image.js 2006-10-25 23:05:23 UTC (rev 1737)
@@ -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,10 +16,12 @@
OpenLayers.Layer.Image.prototype =
OpenLayers.Class.inherit(OpenLayers.Layer, {
+ /** By default, Layer.Image will be a baselayer
+ *
+ * @type Boolean */
+ isBaseLayer: true,
+
/** @type String */
- name: null,
-
- /** @type String */
url: null,
/** @type OpenLayers.Bounds */
@@ -27,14 +30,10 @@
/** @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 @@
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);
},
/**
@@ -96,40 +91,18 @@
},
/**
- * 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 @@
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 @@
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 @@
*/
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) {
More information about the Commits
mailing list