ol 4.4.1-beta.1 → 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/package.json +1 -1
- package/render/canvas/textreplay.js +16 -15
- package/renderer/canvas/tilelayer.js +3 -1
- package/renderer/layer.js +1 -1
- package/source/raster.js +7 -0
- package/source/tile.js +1 -11
- package/source/tiledebug.js +2 -1
- package/source/tileimage.js +3 -2
- package/source/tileutfgrid.js +3 -2
- package/source/tilewms.js +0 -43
- package/source/urltile.js +3 -1
- package/source/vectortile.js +3 -2
- package/structs/lrucache.js +37 -0
- package/tilecache.js +20 -0
- package/tilecoord.js +20 -0
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -307,6 +307,7 @@ _ol_render_canvas_TextReplay_.prototype.getImage_ = function(text, fill, stroke)
|
|
|
307
307
|
var fillState = this.textFillState_;
|
|
308
308
|
var textState = this.textState_;
|
|
309
309
|
var pixelRatio = this.pixelRatio;
|
|
310
|
+
var scale = this.textScale_ * pixelRatio;
|
|
310
311
|
var align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || _ol_render_canvas_.defaultTextAlign];
|
|
311
312
|
var strokeWidth = stroke && strokeState.lineWidth ? strokeState.lineWidth : 0;
|
|
312
313
|
|
|
@@ -314,17 +315,17 @@ _ol_render_canvas_TextReplay_.prototype.getImage_ = function(text, fill, stroke)
|
|
|
314
315
|
var width = _ol_render_canvas_TextReplay_.measureTextWidths(textState.font, lines, widths);
|
|
315
316
|
var lineHeight = _ol_render_canvas_TextReplay_.measureTextHeight(textState.font);
|
|
316
317
|
var height = lineHeight * numLines;
|
|
317
|
-
var renderWidth = (width +
|
|
318
|
+
var renderWidth = (width + strokeWidth);
|
|
318
319
|
var context = _ol_dom_.createCanvasContext2D(
|
|
319
|
-
Math.ceil(renderWidth *
|
|
320
|
-
Math.ceil((height +
|
|
320
|
+
Math.ceil(renderWidth * scale),
|
|
321
|
+
Math.ceil((height + strokeWidth) * scale));
|
|
321
322
|
label = context.canvas;
|
|
322
323
|
_ol_render_canvas_TextReplay_.labelCache_.set(key, label);
|
|
323
|
-
context.scale(
|
|
324
|
+
context.scale(scale, scale);
|
|
324
325
|
context.font = textState.font;
|
|
325
326
|
if (stroke) {
|
|
326
327
|
context.strokeStyle = strokeState.strokeStyle;
|
|
327
|
-
context.lineWidth =
|
|
328
|
+
context.lineWidth = strokeWidth * (_ol_has_.SAFARI ? scale : 1);
|
|
328
329
|
context.lineCap = strokeState.lineCap;
|
|
329
330
|
context.lineJoin = strokeState.lineJoin;
|
|
330
331
|
context.miterLimit = strokeState.miterLimit;
|
|
@@ -339,16 +340,16 @@ _ol_render_canvas_TextReplay_.prototype.getImage_ = function(text, fill, stroke)
|
|
|
339
340
|
context.textBaseline = 'top';
|
|
340
341
|
context.textAlign = 'center';
|
|
341
342
|
var leftRight = (0.5 - align);
|
|
342
|
-
var x = align * label.width /
|
|
343
|
+
var x = align * label.width / scale + leftRight * strokeWidth;
|
|
343
344
|
var i;
|
|
344
345
|
if (stroke) {
|
|
345
346
|
for (i = 0; i < numLines; ++i) {
|
|
346
|
-
context.strokeText(lines[i], x + leftRight * widths[i], strokeWidth + i * lineHeight);
|
|
347
|
+
context.strokeText(lines[i], x + leftRight * widths[i], 0.5 * strokeWidth + i * lineHeight);
|
|
347
348
|
}
|
|
348
349
|
}
|
|
349
350
|
if (fill) {
|
|
350
351
|
for (i = 0; i < numLines; ++i) {
|
|
351
|
-
context.fillText(lines[i], x + leftRight * widths[i], strokeWidth + i * lineHeight);
|
|
352
|
+
context.fillText(lines[i], x + leftRight * widths[i], 0.5 * strokeWidth + i * lineHeight);
|
|
352
353
|
}
|
|
353
354
|
}
|
|
354
355
|
}
|
|
@@ -375,12 +376,12 @@ _ol_render_canvas_TextReplay_.prototype.drawTextImage_ = function(label, begin,
|
|
|
375
376
|
this.instructions.push([_ol_render_canvas_Instruction_.DRAW_IMAGE, begin, end,
|
|
376
377
|
label, (anchorX - this.textOffsetX_) * pixelRatio, (anchorY - this.textOffsetY_) * pixelRatio,
|
|
377
378
|
label.height, 1, 0, 0, this.textRotateWithView_, this.textRotation_,
|
|
378
|
-
|
|
379
|
+
1, true, label.width
|
|
379
380
|
]);
|
|
380
381
|
this.hitDetectionInstructions.push([_ol_render_canvas_Instruction_.DRAW_IMAGE, begin, end,
|
|
381
382
|
label, (anchorX - this.textOffsetX_) * pixelRatio, (anchorY - this.textOffsetY_) * pixelRatio,
|
|
382
383
|
label.height, 1, 0, 0, this.textRotateWithView_, this.textRotation_,
|
|
383
|
-
|
|
384
|
+
1 / pixelRatio, true, label.width
|
|
384
385
|
]);
|
|
385
386
|
};
|
|
386
387
|
|
|
@@ -421,14 +422,14 @@ _ol_render_canvas_TextReplay_.prototype.drawChars_ = function(begin, end) {
|
|
|
421
422
|
this.instructions.push([_ol_render_canvas_Instruction_.DRAW_CHARS,
|
|
422
423
|
begin, end, labels, baseline,
|
|
423
424
|
textState.exceedLength, textState.maxAngle,
|
|
424
|
-
_ol_render_canvas_TextReplay_.getTextWidth.bind(widths, context, pixelRatio),
|
|
425
|
-
offsetY, this.text_, align,
|
|
425
|
+
_ol_render_canvas_TextReplay_.getTextWidth.bind(widths, context, pixelRatio * this.textScale_),
|
|
426
|
+
offsetY, this.text_, align, 1
|
|
426
427
|
]);
|
|
427
428
|
this.hitDetectionInstructions.push([_ol_render_canvas_Instruction_.DRAW_CHARS,
|
|
428
429
|
begin, end, labels, baseline,
|
|
429
430
|
textState.exceedLength, textState.maxAngle,
|
|
430
|
-
_ol_render_canvas_TextReplay_.getTextWidth.bind(widths, context,
|
|
431
|
-
offsetY, this.text_, align,
|
|
431
|
+
_ol_render_canvas_TextReplay_.getTextWidth.bind(widths, context, this.textScale_),
|
|
432
|
+
offsetY, this.text_, align, 1 / pixelRatio
|
|
432
433
|
]);
|
|
433
434
|
};
|
|
434
435
|
|
|
@@ -528,7 +529,7 @@ _ol_render_canvas_TextReplay_.prototype.setTextStyle = function(textStyle) {
|
|
|
528
529
|
strokeState.lineCap + strokeState.lineDashOffset + '|' + strokeState.lineWidth +
|
|
529
530
|
strokeState.lineJoin + strokeState.miterLimit + '[' + strokeState.lineDash.join() + ']' :
|
|
530
531
|
'';
|
|
531
|
-
this.textKey_ = textState.font + textState.textAlign;
|
|
532
|
+
this.textKey_ = textState.font + (textState.textAlign || '?') + this.textScale_;
|
|
532
533
|
this.fillKey_ = fillState ?
|
|
533
534
|
(typeof fillState.fillStyle == 'string' ? fillState.fillStyle : ('|' + _ol_.getUid(fillState.fillStyle))) :
|
|
534
535
|
'';
|
|
@@ -226,7 +226,9 @@ _ol_renderer_canvas_TileLayer_.prototype.prepareFrame = function(frameState, lay
|
|
|
226
226
|
canvas.width = width;
|
|
227
227
|
canvas.height = height;
|
|
228
228
|
} else {
|
|
229
|
-
|
|
229
|
+
if (this.renderedExtent_ && !_ol_extent_.equals(imageExtent, this.renderedExtent_)) {
|
|
230
|
+
context.clearRect(0, 0, width, height);
|
|
231
|
+
}
|
|
230
232
|
oversampling = this.oversampling_;
|
|
231
233
|
}
|
|
232
234
|
}
|
package/renderer/layer.js
CHANGED
|
@@ -254,7 +254,7 @@ _ol_renderer_Layer_.prototype.manageTilePyramid = function(
|
|
|
254
254
|
var tileQueue = frameState.tileQueue;
|
|
255
255
|
var minZoom = tileGrid.getMinZoom();
|
|
256
256
|
var tile, tileRange, tileResolution, x, y, z;
|
|
257
|
-
for (z =
|
|
257
|
+
for (z = minZoom; z <= currentZ; ++z) {
|
|
258
258
|
tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z, tileRange);
|
|
259
259
|
tileResolution = tileGrid.getResolution(z);
|
|
260
260
|
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
package/source/raster.js
CHANGED
|
@@ -179,6 +179,8 @@ _ol_source_Raster_.prototype.updateFrameState_ = function(extent, resolution, pr
|
|
|
179
179
|
frameState.focus = center;
|
|
180
180
|
frameState.size[0] = Math.round(_ol_extent_.getWidth(extent) / resolution);
|
|
181
181
|
frameState.size[1] = Math.round(_ol_extent_.getHeight(extent) / resolution);
|
|
182
|
+
frameState.time = Date.now();
|
|
183
|
+
frameState.animate = false;
|
|
182
184
|
|
|
183
185
|
var viewState = frameState.viewState;
|
|
184
186
|
viewState.center = center;
|
|
@@ -232,6 +234,11 @@ _ol_source_Raster_.prototype.getImage = function(extent, resolution, pixelRatio,
|
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
frameState.tileQueue.loadMoreTiles(16, 16);
|
|
237
|
+
|
|
238
|
+
if (frameState.animate) {
|
|
239
|
+
requestAnimationFrame(this.changed.bind(this));
|
|
240
|
+
}
|
|
241
|
+
|
|
235
242
|
return this.renderedImageCanvas_;
|
|
236
243
|
};
|
|
237
244
|
|
package/source/tile.js
CHANGED
|
@@ -118,7 +118,7 @@ _ol_source_Tile_.prototype.forEachLoadedTile = function(projection, z, tileRange
|
|
|
118
118
|
var tile, tileCoordKey, loaded;
|
|
119
119
|
for (var x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
|
120
120
|
for (var y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
|
121
|
-
tileCoordKey =
|
|
121
|
+
tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
|
122
122
|
loaded = false;
|
|
123
123
|
if (tileCache.containsKey(tileCoordKey)) {
|
|
124
124
|
tile = /** @type {!ol.Tile} */ (tileCache.get(tileCoordKey));
|
|
@@ -168,16 +168,6 @@ _ol_source_Tile_.prototype.setKey = function(key) {
|
|
|
168
168
|
};
|
|
169
169
|
|
|
170
170
|
|
|
171
|
-
/**
|
|
172
|
-
* @param {number} z Z.
|
|
173
|
-
* @param {number} x X.
|
|
174
|
-
* @param {number} y Y.
|
|
175
|
-
* @return {string} Key.
|
|
176
|
-
* @protected
|
|
177
|
-
*/
|
|
178
|
-
_ol_source_Tile_.prototype.getKeyZXY = _ol_tilecoord_.getKeyZXY;
|
|
179
|
-
|
|
180
|
-
|
|
181
171
|
/**
|
|
182
172
|
* @param {ol.proj.Projection} projection Projection.
|
|
183
173
|
* @return {boolean} Opaque.
|
package/source/tiledebug.js
CHANGED
|
@@ -4,6 +4,7 @@ import _ol_TileState_ from '../tilestate.js';
|
|
|
4
4
|
import _ol_dom_ from '../dom.js';
|
|
5
5
|
import _ol_size_ from '../size.js';
|
|
6
6
|
import _ol_source_Tile_ from '../source/tile.js';
|
|
7
|
+
import _ol_tilecoord_ from '../tilecoord.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @classdesc
|
|
@@ -36,7 +37,7 @@ _ol_.inherits(_ol_source_TileDebug_, _ol_source_Tile_);
|
|
|
36
37
|
* @inheritDoc
|
|
37
38
|
*/
|
|
38
39
|
_ol_source_TileDebug_.prototype.getTile = function(z, x, y) {
|
|
39
|
-
var tileCoordKey =
|
|
40
|
+
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
|
40
41
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
|
41
42
|
return /** @type {!ol.source.TileDebug.Tile_} */ (this.tileCache.get(tileCoordKey));
|
|
42
43
|
} else {
|
package/source/tileimage.js
CHANGED
|
@@ -7,6 +7,7 @@ import _ol_events_EventType_ from '../events/eventtype.js';
|
|
|
7
7
|
import _ol_proj_ from '../proj.js';
|
|
8
8
|
import _ol_reproj_Tile_ from '../reproj/tile.js';
|
|
9
9
|
import _ol_source_UrlTile_ from '../source/urltile.js';
|
|
10
|
+
import _ol_tilecoord_ from '../tilecoord.js';
|
|
10
11
|
import _ol_tilegrid_ from '../tilegrid.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -243,7 +244,7 @@ _ol_source_TileImage_.prototype.getTile = function(z, x, y, pixelRatio, projecti
|
|
|
243
244
|
var cache = this.getTileCacheForProjection(projection);
|
|
244
245
|
var tileCoord = [z, x, y];
|
|
245
246
|
var tile;
|
|
246
|
-
var tileCoordKey =
|
|
247
|
+
var tileCoordKey = _ol_tilecoord_.getKey(tileCoord);
|
|
247
248
|
if (cache.containsKey(tileCoordKey)) {
|
|
248
249
|
tile = /** @type {!ol.Tile} */ (cache.get(tileCoordKey));
|
|
249
250
|
}
|
|
@@ -291,7 +292,7 @@ _ol_source_TileImage_.prototype.getTile = function(z, x, y, pixelRatio, projecti
|
|
|
291
292
|
*/
|
|
292
293
|
_ol_source_TileImage_.prototype.getTileInternal = function(z, x, y, pixelRatio, projection) {
|
|
293
294
|
var tile = null;
|
|
294
|
-
var tileCoordKey =
|
|
295
|
+
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
|
295
296
|
var key = this.getKey();
|
|
296
297
|
if (!this.tileCache.containsKey(tileCoordKey)) {
|
|
297
298
|
tile = this.createTile_(z, x, y, pixelRatio, projection, key);
|
package/source/tileutfgrid.js
CHANGED
|
@@ -11,6 +11,7 @@ import _ol_net_ from '../net.js';
|
|
|
11
11
|
import _ol_proj_ from '../proj.js';
|
|
12
12
|
import _ol_source_State_ from '../source/state.js';
|
|
13
13
|
import _ol_source_Tile_ from '../source/tile.js';
|
|
14
|
+
import _ol_tilecoord_ from '../tilecoord.js';
|
|
14
15
|
import _ol_tilegrid_ from '../tilegrid.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -221,7 +222,7 @@ _ol_source_TileUTFGrid_.prototype.handleTileJSONResponse = function(tileJSON) {
|
|
|
221
222
|
* @inheritDoc
|
|
222
223
|
*/
|
|
223
224
|
_ol_source_TileUTFGrid_.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
|
224
|
-
var tileCoordKey =
|
|
225
|
+
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
|
225
226
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
|
226
227
|
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
|
|
227
228
|
} else {
|
|
@@ -246,7 +247,7 @@ _ol_source_TileUTFGrid_.prototype.getTile = function(z, x, y, pixelRatio, projec
|
|
|
246
247
|
* @inheritDoc
|
|
247
248
|
*/
|
|
248
249
|
_ol_source_TileUTFGrid_.prototype.useTile = function(z, x, y) {
|
|
249
|
-
var tileCoordKey =
|
|
250
|
+
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
|
250
251
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
|
251
252
|
this.tileCache.get(tileCoordKey);
|
|
252
253
|
}
|
package/source/tilewms.js
CHANGED
|
@@ -79,13 +79,6 @@ var _ol_source_TileWMS_ = function(opt_options) {
|
|
|
79
79
|
*/
|
|
80
80
|
this.hidpi_ = options.hidpi !== undefined ? options.hidpi : true;
|
|
81
81
|
|
|
82
|
-
/**
|
|
83
|
-
* @private
|
|
84
|
-
* @type {string}
|
|
85
|
-
*/
|
|
86
|
-
this.coordKeyPrefix_ = '';
|
|
87
|
-
this.resetCoordKeyPrefix_();
|
|
88
|
-
|
|
89
82
|
/**
|
|
90
83
|
* @private
|
|
91
84
|
* @type {ol.Extent}
|
|
@@ -170,14 +163,6 @@ _ol_source_TileWMS_.prototype.getGutterInternal = function() {
|
|
|
170
163
|
};
|
|
171
164
|
|
|
172
165
|
|
|
173
|
-
/**
|
|
174
|
-
* @inheritDoc
|
|
175
|
-
*/
|
|
176
|
-
_ol_source_TileWMS_.prototype.getKeyZXY = function(z, x, y) {
|
|
177
|
-
return this.coordKeyPrefix_ + _ol_source_TileImage_.prototype.getKeyZXY.call(this, z, x, y);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
|
|
181
166
|
/**
|
|
182
167
|
* Get the user-provided params, i.e. those passed to the constructor through
|
|
183
168
|
* the "params" option, and possibly updated using the updateParams method.
|
|
@@ -272,24 +257,6 @@ _ol_source_TileWMS_.prototype.getTilePixelRatio = function(pixelRatio) {
|
|
|
272
257
|
};
|
|
273
258
|
|
|
274
259
|
|
|
275
|
-
/**
|
|
276
|
-
* @private
|
|
277
|
-
*/
|
|
278
|
-
_ol_source_TileWMS_.prototype.resetCoordKeyPrefix_ = function() {
|
|
279
|
-
var i = 0;
|
|
280
|
-
var res = [];
|
|
281
|
-
|
|
282
|
-
if (this.urls) {
|
|
283
|
-
var j, jj;
|
|
284
|
-
for (j = 0, jj = this.urls.length; j < jj; ++j) {
|
|
285
|
-
res[i++] = this.urls[j];
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
this.coordKeyPrefix_ = res.join('#');
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
|
|
293
260
|
/**
|
|
294
261
|
* @private
|
|
295
262
|
* @return {string} The key for the current params.
|
|
@@ -351,15 +318,6 @@ _ol_source_TileWMS_.prototype.fixedTileUrlFunction = function(tileCoord, pixelRa
|
|
|
351
318
|
pixelRatio, projection, baseParams);
|
|
352
319
|
};
|
|
353
320
|
|
|
354
|
-
/**
|
|
355
|
-
* @inheritDoc
|
|
356
|
-
*/
|
|
357
|
-
_ol_source_TileWMS_.prototype.setUrls = function(urls) {
|
|
358
|
-
_ol_source_TileImage_.prototype.setUrls.call(this, urls);
|
|
359
|
-
this.resetCoordKeyPrefix_();
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
|
|
363
321
|
/**
|
|
364
322
|
* Update the user-provided params.
|
|
365
323
|
* @param {Object} params Params.
|
|
@@ -367,7 +325,6 @@ _ol_source_TileWMS_.prototype.setUrls = function(urls) {
|
|
|
367
325
|
*/
|
|
368
326
|
_ol_source_TileWMS_.prototype.updateParams = function(params) {
|
|
369
327
|
_ol_obj_.assign(this.params_, params);
|
|
370
|
-
this.resetCoordKeyPrefix_();
|
|
371
328
|
this.updateV13_();
|
|
372
329
|
this.setKey(this.getKeyForParams_());
|
|
373
330
|
};
|
package/source/urltile.js
CHANGED
|
@@ -3,6 +3,7 @@ import _ol_TileState_ from '../tilestate.js';
|
|
|
3
3
|
import _ol_TileUrlFunction_ from '../tileurlfunction.js';
|
|
4
4
|
import _ol_source_Tile_ from '../source/tile.js';
|
|
5
5
|
import _ol_source_TileEventType_ from '../source/tileeventtype.js';
|
|
6
|
+
import _ol_tilecoord_ from '../tilecoord.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @classdesc
|
|
@@ -153,6 +154,7 @@ _ol_source_UrlTile_.prototype.setTileLoadFunction = function(tileLoadFunction) {
|
|
|
153
154
|
*/
|
|
154
155
|
_ol_source_UrlTile_.prototype.setTileUrlFunction = function(tileUrlFunction, opt_key) {
|
|
155
156
|
this.tileUrlFunction = tileUrlFunction;
|
|
157
|
+
this.tileCache.pruneExceptNewestZ();
|
|
156
158
|
if (typeof opt_key !== 'undefined') {
|
|
157
159
|
this.setKey(opt_key);
|
|
158
160
|
} else {
|
|
@@ -192,7 +194,7 @@ _ol_source_UrlTile_.prototype.setUrls = function(urls) {
|
|
|
192
194
|
* @inheritDoc
|
|
193
195
|
*/
|
|
194
196
|
_ol_source_UrlTile_.prototype.useTile = function(z, x, y) {
|
|
195
|
-
var tileCoordKey =
|
|
197
|
+
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
|
196
198
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
|
197
199
|
this.tileCache.get(tileCoordKey);
|
|
198
200
|
}
|
package/source/vectortile.js
CHANGED
|
@@ -3,8 +3,9 @@ import _ol_TileState_ from '../tilestate.js';
|
|
|
3
3
|
import _ol_VectorImageTile_ from '../vectorimagetile.js';
|
|
4
4
|
import _ol_VectorTile_ from '../vectortile.js';
|
|
5
5
|
import _ol_size_ from '../size.js';
|
|
6
|
-
import _ol_tilegrid_ from '../tilegrid.js';
|
|
7
6
|
import _ol_source_UrlTile_ from '../source/urltile.js';
|
|
7
|
+
import _ol_tilecoord_ from '../tilecoord.js';
|
|
8
|
+
import _ol_tilegrid_ from '../tilegrid.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @classdesc
|
|
@@ -108,7 +109,7 @@ _ol_source_VectorTile_.prototype.clear = function() {
|
|
|
108
109
|
* @inheritDoc
|
|
109
110
|
*/
|
|
110
111
|
_ol_source_VectorTile_.prototype.getTile = function(z, x, y, pixelRatio, projection) {
|
|
111
|
-
var tileCoordKey =
|
|
112
|
+
var tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y);
|
|
112
113
|
if (this.tileCache.containsKey(tileCoordKey)) {
|
|
113
114
|
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
|
|
114
115
|
} else {
|
package/structs/lrucache.js
CHANGED
|
@@ -113,6 +113,34 @@ _ol_structs_LRUCache_.prototype.get = function(key) {
|
|
|
113
113
|
};
|
|
114
114
|
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Remove an entry from the cache.
|
|
118
|
+
* @param {string} key The entry key.
|
|
119
|
+
* @return {T} The removed entry.
|
|
120
|
+
*/
|
|
121
|
+
_ol_structs_LRUCache_.prototype.remove = function(key) {
|
|
122
|
+
var entry = this.entries_[key];
|
|
123
|
+
_ol_asserts_.assert(entry !== undefined, 15); // Tried to get a value for a key that does not exist in the cache
|
|
124
|
+
if (entry === this.newest_) {
|
|
125
|
+
this.newest_ = /** @type {ol.LRUCacheEntry} */ (entry.older);
|
|
126
|
+
if (this.newest_) {
|
|
127
|
+
this.newest_.newer = null;
|
|
128
|
+
}
|
|
129
|
+
} else if (entry === this.oldest_) {
|
|
130
|
+
this.oldest_ = /** @type {ol.LRUCacheEntry} */ (entry.newer);
|
|
131
|
+
if (this.oldest_) {
|
|
132
|
+
this.oldest_.older = null;
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
entry.newer.older = entry.older;
|
|
136
|
+
entry.older.newer = entry.newer;
|
|
137
|
+
}
|
|
138
|
+
delete this.entries_[key];
|
|
139
|
+
--this.count_;
|
|
140
|
+
return entry.value_;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
|
|
116
144
|
/**
|
|
117
145
|
* @return {number} Count.
|
|
118
146
|
*/
|
|
@@ -165,6 +193,15 @@ _ol_structs_LRUCache_.prototype.peekLastKey = function() {
|
|
|
165
193
|
};
|
|
166
194
|
|
|
167
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Get the key of the newest item in the cache. Throws if the cache is empty.
|
|
198
|
+
* @return {string} The newest key.
|
|
199
|
+
*/
|
|
200
|
+
_ol_structs_LRUCache_.prototype.peekFirstKey = function() {
|
|
201
|
+
return this.newest_.key_;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
|
|
168
205
|
/**
|
|
169
206
|
* @return {T} value Value.
|
|
170
207
|
*/
|
package/tilecache.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _ol_ from './index.js';
|
|
2
2
|
import _ol_structs_LRUCache_ from './structs/lrucache.js';
|
|
3
|
+
import _ol_tilecoord_ from './tilecoord.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @constructor
|
|
@@ -31,4 +32,23 @@ _ol_TileCache_.prototype.expireCache = function(usedTiles) {
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Prune all tiles from the cache that don't have the same z as the newest tile.
|
|
39
|
+
*/
|
|
40
|
+
_ol_TileCache_.prototype.pruneExceptNewestZ = function() {
|
|
41
|
+
if (this.getCount() === 0) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
var key = this.peekFirstKey();
|
|
45
|
+
var tileCoord = _ol_tilecoord_.fromKey(key);
|
|
46
|
+
var z = tileCoord[0];
|
|
47
|
+
this.forEach(function(tile) {
|
|
48
|
+
if (tile.tileCoord[0] !== z) {
|
|
49
|
+
this.remove(_ol_tilecoord_.getKey(tile.tileCoord));
|
|
50
|
+
tile.dispose();
|
|
51
|
+
}
|
|
52
|
+
}, this);
|
|
53
|
+
};
|
|
34
54
|
export default _ol_TileCache_;
|
package/tilecoord.js
CHANGED
|
@@ -31,6 +31,26 @@ _ol_tilecoord_.getKeyZXY = function(z, x, y) {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Get the key for a tile coord.
|
|
36
|
+
* @param {ol.TileCoord} tileCoord The tile coord.
|
|
37
|
+
* @return {string} Key.
|
|
38
|
+
*/
|
|
39
|
+
_ol_tilecoord_.getKey = function(tileCoord) {
|
|
40
|
+
return _ol_tilecoord_.getKeyZXY(tileCoord[0], tileCoord[1], tileCoord[2]);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get a tile coord given a key.
|
|
46
|
+
* @param {string} key The tile coord key.
|
|
47
|
+
* @return {ol.TileCoord} The tile coord.
|
|
48
|
+
*/
|
|
49
|
+
_ol_tilecoord_.fromKey = function(key) {
|
|
50
|
+
return key.split('/').map(Number);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
|
|
34
54
|
/**
|
|
35
55
|
* @param {ol.TileCoord} tileCoord Tile coord.
|
|
36
56
|
* @return {number} Hash.
|