Skip to content

Commit

Permalink
Fade steps alpha interpolation, fix #486
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 committed Jan 20, 2018
1 parent b429736 commit 23f4808
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Improved theme styles [#479](https://github.com/mapsforge/vtm/pull/479)
- Map fractional zoom [#487](https://github.com/mapsforge/vtm/issues/487)
- Render theme fallback internal resources [#477](https://github.com/mapsforge/vtm/issues/477)
- Fix FadeStep alpha interpolation [#486](https://github.com/mapsforge/vtm/issues/486)
- Fix libGDX flickering [#148](https://github.com/mapsforge/vtm/issues/148) [#149](https://github.com/mapsforge/vtm/issues/149)
- JTS (LocationTech) [#484](https://github.com/mapsforge/vtm/issues/484)
- Many other minor improvements and bug fixes
Expand Down
12 changes: 7 additions & 5 deletions vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,23 @@ public class BitmapTileLayer extends TileLayer {

public static class FadeStep {
public final double scaleStart, scaleEnd;
public final double zoomStart, zoomEnd;
public final float alphaStart, alphaEnd;

public FadeStep(int zoomStart, int zoomEnd, float alphaStart, float alphaEnd) {
this.scaleStart = 1 << zoomStart;
this.scaleEnd = 1 << zoomEnd;
this.zoomStart = zoomStart;
this.zoomEnd = zoomEnd;
this.alphaStart = alphaStart;
this.alphaEnd = alphaEnd;
}

public FadeStep(double scaleStart, double scaleEnd, float alphaStart, float alphaEnd) {
this.scaleStart = scaleStart;
this.scaleEnd = scaleEnd;
this.zoomStart = Math.log(scaleStart) / Math.log(2);
this.zoomEnd = Math.log(scaleEnd) / Math.log(2);
this.alphaStart = alphaStart;
this.alphaEnd = alphaEnd;
}
Expand Down Expand Up @@ -110,7 +115,7 @@ private void setFade(MapPosition pos) {
return;
}

float alpha = 0f;
float alpha = mBitmapAlpha;
for (FadeStep f : fade) {
if (pos.scale < f.scaleStart || pos.scale > f.scaleEnd)
continue;
Expand All @@ -119,11 +124,8 @@ private void setFade(MapPosition pos) {
alpha = f.alphaStart;
break;
}
double range = f.scaleEnd - f.scaleStart;
float a = (float) ((pos.scale - f.scaleStart) / range);
a = FastMath.clamp(a, 0f, 1f);
// interpolate alpha between start and end
alpha = (1 - a) * f.alphaStart + a * f.alphaEnd;
alpha = (float) (f.alphaStart + (pos.getZoom() - f.zoomStart) * (f.alphaEnd - f.alphaStart) / (f.zoomEnd - f.zoomStart));
break;
}

Expand Down

0 comments on commit 23f4808

Please sign in to comment.