Tile.js
4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
* See http://svn.openlayers.org/trunk/openlayers/release-license.txt
* for the full text of the license. */
/*
* @class
* @requires OpenLayers/Util.js
*
* This is a class designed to designate a single tile, however
* it is explicitly designed to do relatively little. Tiles store information
* about themselves -- such as the URL that they are related to, and their
* size - but do not add themselves to the layer div automatically, for
* example.
*
* TBD 3.0 - remove reference to url in above paragraph
*
*/
OpenLayers.Tile = OpenLayers.Class.create();
OpenLayers.Tile.prototype = {
/** @type String */
id: null,
/** @type OpenLayers.Layer */
layer: null,
/** TBD 3.0
* @deprecated The base tile class does not need an url. This should be
* handled in subclasses. Does not belong here.
*
* @type String url of the request */
url:null,
/** @type OpenLayers.Bounds */
bounds:null,
/** @type OpenLayers.Size */
size:null,
/** Top Left pixel of the tile
* @type OpenLayers.Pixel */
position:null,
/** @type Boolean */
drawn: false,
/** TBD 3.0 -- remove 'url' from the list of parameters to the constructor.
* there is no need for the base tile class to have a url.
*
* @constructor
*
* @param {OpenLayers.Layer} layer
* @param {OpenLayers.Pixel} position
* @param {OpenLayers.Bounds} bounds
* @param {String} url
* @param {OpenLayers.Size} size
*/
initialize: function(layer, position, bounds, url, size) {
this.layer = layer;
this.position = position;
this.bounds = bounds;
this.url = url;
this.size = size;
//give the tile a unique id based on its BBOX.
this.id = OpenLayers.Util.createUniqueID("Tile_");
},
/** nullify references to prevent circular references and memory leaks
*/
destroy:function() {
this.layer = null;
this.bounds = null;
this.size = null;
this.position = null;
},
/**
*/
draw:function() {
this.clear();
return ((this.layer.displayOutsideMaxExtent
|| (this.layer.maxExtent
&& this.bounds.intersectsBounds(this.layer.maxExtent, false)))
&& !(this.layer.buffer == 0
&& !this.bounds.intersectsBounds(this.layer.map.getExtent(), false)));
},
/**
* @param {OpenLayers.Bounds}
* @param {OpenLayers.pixel} position
* @param {Boolean} redraw Redraw tile after moving?
* Default is true
*/
moveTo: function (bounds, position, redraw) {
if (redraw == null) {
redraw = true;
}
this.clear();
this.bounds = bounds.clone();
this.position = position.clone();
if (redraw) {
this.draw();
}
},
/** Clear the tile of any bounds/position-related data so that it can
* be reused in a new location.
*/
clear: function() {
this.drawn = false;
},
getBoundsFromBaseLayer: function(position) {
var topLeft = this.layer.map.getLonLatFromLayerPx(position);
var bottomRightPx = position.clone();
bottomRightPx.x += this.size.w;
bottomRightPx.y += this.size.h;
var bottomRight = this.layer.map.getLonLatFromLayerPx(bottomRightPx);
// Handle the case where the base layer wraps around the date line.
// Google does this, and it breaks WMS servers to request bounds in that fashion.
if (topLeft.lon > bottomRight.lon) {
if (topLeft.lon < 0) {
topLeft.lon = -180 - (topLeft.lon+180);
} else {
bottomRight.lon = 180+bottomRight.lon+180;
}
}
bounds = new OpenLayers.Bounds(topLeft.lon, bottomRight.lat, bottomRight.lon, topLeft.lat);
return bounds;
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Tile"
};