-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
urltile.js
203 lines (174 loc) · 4.93 KB
/
urltile.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
goog.provide('ol.source.UrlTile');
goog.require('ol');
goog.require('ol.TileState');
goog.require('ol.TileUrlFunction');
goog.require('ol.source.Tile');
goog.require('ol.source.TileEventType');
goog.require('ol.tilecoord');
/**
* @classdesc
* Base class for sources providing tiles divided into a tile grid over http.
*
* @constructor
* @abstract
* @fires ol.source.Tile.Event
* @extends {ol.source.Tile}
* @param {ol.SourceUrlTileOptions} options Image tile options.
*/
ol.source.UrlTile = function(options) {
ol.source.Tile.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
extent: options.extent,
logo: options.logo,
opaque: options.opaque,
projection: options.projection,
state: options.state,
tileGrid: options.tileGrid,
tilePixelRatio: options.tilePixelRatio,
wrapX: options.wrapX,
transition: options.transition
});
/**
* @protected
* @type {ol.TileLoadFunctionType}
*/
this.tileLoadFunction = options.tileLoadFunction;
/**
* @protected
* @type {ol.TileUrlFunctionType}
*/
this.tileUrlFunction = this.fixedTileUrlFunction ?
this.fixedTileUrlFunction.bind(this) :
ol.TileUrlFunction.nullTileUrlFunction;
/**
* @protected
* @type {!Array.<string>|null}
*/
this.urls = null;
if (options.urls) {
this.setUrls(options.urls);
} else if (options.url) {
this.setUrl(options.url);
}
if (options.tileUrlFunction) {
this.setTileUrlFunction(options.tileUrlFunction);
}
/**
* @private
* @type {Object.<number, boolean>}
*/
this.tileLoadingKeys_ = {};
};
ol.inherits(ol.source.UrlTile, ol.source.Tile);
/**
* @type {ol.TileUrlFunctionType|undefined}
* @protected
*/
ol.source.UrlTile.prototype.fixedTileUrlFunction;
/**
* Return the tile load function of the source.
* @return {ol.TileLoadFunctionType} TileLoadFunction
* @api
*/
ol.source.UrlTile.prototype.getTileLoadFunction = function() {
return this.tileLoadFunction;
};
/**
* Return the tile URL function of the source.
* @return {ol.TileUrlFunctionType} TileUrlFunction
* @api
*/
ol.source.UrlTile.prototype.getTileUrlFunction = function() {
return this.tileUrlFunction;
};
/**
* Return the URLs used for this source.
* When a tileUrlFunction is used instead of url or urls,
* null will be returned.
* @return {!Array.<string>|null} URLs.
* @api
*/
ol.source.UrlTile.prototype.getUrls = function() {
return this.urls;
};
/**
* Handle tile change events.
* @param {ol.events.Event} event Event.
* @protected
*/
ol.source.UrlTile.prototype.handleTileChange = function(event) {
var tile = /** @type {ol.Tile} */ (event.target);
var uid = ol.getUid(tile);
var tileState = tile.getState();
var type;
if (tileState == ol.TileState.LOADING) {
this.tileLoadingKeys_[uid] = true;
type = ol.source.TileEventType.TILELOADSTART;
} else if (uid in this.tileLoadingKeys_) {
delete this.tileLoadingKeys_[uid];
type = tileState == ol.TileState.ERROR ? ol.source.TileEventType.TILELOADERROR :
(tileState == ol.TileState.LOADED || tileState == ol.TileState.ABORT) ?
ol.source.TileEventType.TILELOADEND : undefined;
}
if (type != undefined) {
this.dispatchEvent(new ol.source.Tile.Event(type, tile));
}
};
/**
* Set the tile load function of the source.
* @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
* @api
*/
ol.source.UrlTile.prototype.setTileLoadFunction = function(tileLoadFunction) {
this.tileCache.clear();
this.tileLoadFunction = tileLoadFunction;
this.changed();
};
/**
* Set the tile URL function of the source.
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
* @param {string=} opt_key Optional new tile key for the source.
* @api
*/
ol.source.UrlTile.prototype.setTileUrlFunction = function(tileUrlFunction, opt_key) {
this.tileUrlFunction = tileUrlFunction;
this.tileCache.pruneExceptNewestZ();
if (typeof opt_key !== 'undefined') {
this.setKey(opt_key);
} else {
this.changed();
}
};
/**
* Set the URL to use for requests.
* @param {string} url URL.
* @api
*/
ol.source.UrlTile.prototype.setUrl = function(url) {
var urls = this.urls = ol.TileUrlFunction.expandUrl(url);
this.setTileUrlFunction(this.fixedTileUrlFunction ?
this.fixedTileUrlFunction.bind(this) :
ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid), url);
};
/**
* Set the URLs to use for requests.
* @param {Array.<string>} urls URLs.
* @api
*/
ol.source.UrlTile.prototype.setUrls = function(urls) {
this.urls = urls;
var key = urls.join('\n');
this.setTileUrlFunction(this.fixedTileUrlFunction ?
this.fixedTileUrlFunction.bind(this) :
ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid), key);
};
/**
* @inheritDoc
*/
ol.source.UrlTile.prototype.useTile = function(z, x, y) {
var tileCoordKey = ol.tilecoord.getKeyZXY(z, x, y);
if (this.tileCache.containsKey(tileCoordKey)) {
this.tileCache.get(tileCoordKey);
}
};