Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gridlayer opacity flicker fix #3671

Merged
merged 1 commit into from
Jul 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixes #3652 by container opacity approach
  • Loading branch information
w8r committed Jul 24, 2015
commit 5e32cd190c253d928c8f21e5332a4a0823ec68cf
32 changes: 32 additions & 0 deletions debug/map/tile-opacity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<title>Leaflet debug page</title>

<link rel="stylesheet" href="../../dist/leaflet.css" />

<link rel="stylesheet" href="../css/screen.css" />

<script type="text/javascript" src="../../build/deps.js"></script>
<script src="../leaflet-include.js"></script>
</head>
<body>

<div id="map" style="width: 800px; height: 600px; border: 1px solid #ccc"></div>

<script type="text/javascript">
var map = new L.Map('map');
var nexrad = new L.TileLayer.WMS("http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi", {
layers: 'nexrad-n0r-900913',
format: 'image/png',
transparent: true,
attribution: "Weather data &copy; 2011 IEM Nexrad",
opacity: 0.4
});

var bounds = new L.LatLngBounds(new L.LatLng(32, -126), new L.LatLng(50, -64));

map.addLayer(nexrad).fitBounds(bounds);
</script>
</body>
</html>
10 changes: 5 additions & 5 deletions src/layer/tile/GridLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ L.GridLayer = L.Layer.extend({

_updateOpacity: function () {
if (!this._map) { return; }
var opacity = this.options.opacity;

// IE doesn't inherit filter opacity properly, so we're forced to set it on tiles
if (!L.Browser.ielt9 && !this._map._fadeAnimated) {
L.DomUtil.setOpacity(this._container, opacity);
if (L.Browser.ielt9 || !this._map._fadeAnimated) {
return;
}

L.DomUtil.setOpacity(this._container, this.options.opacity);

var now = +new Date(),
nextFrame = false,
willPrune = false;
Expand All @@ -173,11 +173,11 @@ L.GridLayer = L.Layer.extend({
if (!tile.current || !tile.loaded) { continue; }

var fade = Math.min(1, (now - tile.loaded) / 200);

L.DomUtil.setOpacity(tile.el, fade);
if (fade < 1) {
L.DomUtil.setOpacity(tile.el, opacity * fade);
nextFrame = true;
} else {
L.DomUtil.setOpacity(tile.el, opacity);
if (tile.active) { willPrune = true; }
tile.active = true;
}
Expand Down