1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
6
* @requires OpenLayers/Layer.js
7
* @requires OpenLayers/Tile/Image.js
11
* Class: OpenLayers.Layer.Image
12
* Instances of OpenLayers.Layer.Image are used to display data from a web
13
* accessible image as a map layer. Create a new image layer with the
14
* <OpenLayers.Layer.Image> constructor. Inherits from <OpenLayers.Layer>.
16
OpenLayers.Layer.Image = OpenLayers.Class(OpenLayers.Layer, {
19
* Property: isBaseLayer
20
* {Boolean} The layer is a base layer. Default is true. Set this property
21
* in the layer options
27
* {String} URL of the image to use
33
* {<OpenLayers.Bounds>} The image bounds in map units
39
* {<OpenLayers.Size>} The image size in pixels
45
* {<OpenLayers.Tile.Image>}
50
* Property: aspectRatio
51
* {Float} The ratio of height/width represented by a single pixel in the
57
* Constructor: OpenLayers.Layer.Image
58
* Create a new image layer
61
* name - {String} A name for the layer.
62
* url - {String} Relative or absolute path to the image
63
* extent - {<OpenLayers.Bounds>} The extent represented by the image
64
* size - {<OpenLayers.Size>} The size (in pixels) of the image
65
* options - {Object} Hashtable of extra options to tag onto the layer
67
initialize: function(name, url, extent, size, options) {
71
OpenLayers.Layer.prototype.initialize.apply(this, [name, options]);
73
this.aspectRatio = (this.extent.getHeight() / this.size.h) /
74
(this.extent.getWidth() / this.size.w);
86
OpenLayers.Layer.prototype.destroy.apply(this, arguments);
91
* Create a clone of this layer
94
* obj - {Object} An optional layer (is this ever used?)
97
* {<OpenLayers.Layer.Image>} An exact copy of this layer
99
clone: function(obj) {
102
obj = new OpenLayers.Layer.Image(this.name,
109
//get all additions from superclasses
110
obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]);
112
// copy/set any non-init, non-simple values here
121
* map - {<OpenLayers.Map>}
123
setMap: function(map) {
125
* If nothing to do with resolutions has been set, assume a single
126
* resolution determined by ratio*extent/size - if an image has a
127
* pixel aspect ratio different than one (as calculated above), the
128
* image will be stretched in one dimension only.
130
if( this.options.maxResolution == null ) {
131
this.options.maxResolution = this.aspectRatio *
132
this.extent.getWidth() /
135
OpenLayers.Layer.prototype.setMap.apply(this, arguments);
140
* Create the tile for the image or resize it for the new resolution
143
* bounds - {<OpenLayers.Bounds>}
144
* zoomChanged - {Boolean}
145
* dragging - {Boolean}
147
moveTo:function(bounds, zoomChanged, dragging) {
148
OpenLayers.Layer.prototype.moveTo.apply(this, arguments);
150
var firstRendering = (this.tile == null);
152
if(zoomChanged || firstRendering) {
154
//determine new tile size
157
//determine new position (upper left corner of new bounds)
158
var ul = new OpenLayers.LonLat(this.extent.left, this.extent.top);
159
var ulPx = this.map.getLayerPxFromLonLat(ul);
162
//create the new tile
163
this.tile = new OpenLayers.Tile.Image(this, ulPx, this.extent,
164
null, this.tileSize);
166
//just resize the tile and set it's new position
167
this.tile.size = this.tileSize.clone();
168
this.tile.position = ulPx.clone();
175
* Set the tile size based on the map size.
177
setTileSize: function() {
178
var tileWidth = this.extent.getWidth() / this.map.getResolution();
179
var tileHeight = this.extent.getHeight() / this.map.getResolution();
180
this.tileSize = new OpenLayers.Size(tileWidth, tileHeight);
189
setUrl: function(newUrl) {
196
* The url we return is always the same (the image itself never changes)
197
* so we can ignore the bounds parameter (it will always be the same,
201
* bounds - {<OpenLayers.Bounds>}
203
getURL: function(bounds) {
207
CLASS_NAME: "OpenLayers.Layer.Image"