Merge pull request #3513 from Leaflet/tile-opacity
Fixes #3431, GridLayer.setOpacity() behaviour on active tiles.
This commit is contained in:
commit
3676e94e0f
44
debug/tests/tile-opacity.html
Normal file
44
debug/tests/tile-opacity.html
Normal file
@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Leaflet debug page</title>
|
||||
|
||||
<link rel="stylesheet" href="../../dist/leaflet.css" />
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<link rel="stylesheet" href="../css/screen.css" />
|
||||
|
||||
<script type="text/javascript" src="../../build/deps.js"></script>
|
||||
<script src="../leaflet-include.js"></script>
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
The opacity of the "toner" layer should pulse nicely, even when dragging/zooming the map around with new tiles.
|
||||
<div id="map" class="map"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var mapopts = {
|
||||
center: [35, -122],
|
||||
zoom : 5
|
||||
};
|
||||
|
||||
var map = L.map('map', mapopts);
|
||||
|
||||
var watercolorUrl = 'http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg';
|
||||
var watercolor = L.tileLayer(watercolorUrl, {maxZoom: 18, attribution: 'Map by Stamen, map data OpenStreetMap'}).addTo(map);
|
||||
|
||||
var tonerUrl = 'http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.jpg';
|
||||
var toner = L.tileLayer(tonerUrl, {maxZoom: 18, attribution: ''}).addTo(map);
|
||||
|
||||
window.setInterval(function(){
|
||||
// Sine function, phase shifts one radian every sec.
|
||||
var opacity = 0.6 + 0.4 * Math.sin(Date.now() / 1000);
|
||||
toner.setOpacity(opacity);
|
||||
}, 200);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -155,11 +155,12 @@ L.GridLayer = L.Layer.extend({
|
||||
}
|
||||
|
||||
var now = +new Date(),
|
||||
nextFrame = false;
|
||||
nextFrame = false,
|
||||
willPrune = false;
|
||||
|
||||
for (var key in this._tiles) {
|
||||
var tile = this._tiles[key];
|
||||
if (!tile.current || !tile.loaded || tile.active) { continue; }
|
||||
if (!tile.current || !tile.loaded) { continue; }
|
||||
|
||||
var fade = Math.min(1, (now - tile.loaded) / 200);
|
||||
if (fade < 1) {
|
||||
@ -167,11 +168,13 @@ L.GridLayer = L.Layer.extend({
|
||||
nextFrame = true;
|
||||
} else {
|
||||
L.DomUtil.setOpacity(tile.el, opacity);
|
||||
if (tile.active) { willPrune = true; }
|
||||
tile.active = true;
|
||||
this._pruneTiles();
|
||||
}
|
||||
}
|
||||
|
||||
if (willPrune) { this._pruneTiles(); }
|
||||
|
||||
if (nextFrame) {
|
||||
L.Util.cancelAnimFrame(this._fadeFrame);
|
||||
this._fadeFrame = L.Util.requestAnimFrame(this._updateOpacity, this);
|
||||
|
Loading…
Reference in New Issue
Block a user