Skip to content

Instantly share code, notes, and snippets.

@maptastik
Last active December 21, 2018 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maptastik/0cff68292a836bb986e6ee0275b7c434 to your computer and use it in GitHub Desktop.
Save maptastik/0cff68292a836bb986e6ee0275b7c434 to your computer and use it in GitHub Desktop.
JavaScript functions for fading layers using various map APIs
function fadeInLayerLeaflet(lyr, startOpacity, finalOpacity, opacityStep, delay) {
let opacity = startOpacity;
let timer = setTimeout(function changeOpacity() {
if (opacity < finalOpacity) {
lyr.setStyle({
opacity: opacity,
fillOpacity: opacity
});
opacity = opacity + opacityStep
}
timer = setTimeout(changeOpacity, delay);
}, delay)
}
function fadeInLayerOL3(lyr, startOpacity, finalOpacity, opacityStep, delay) {
let opacity = startOpacity;
let timer = setTimeout(function changeOpacity() {
if (opacity < finalOpacity) {
lyr.setProperties({
opacity: opacity
});
opacity = opacity + opacityStep
}
timer = setTimeout(changeOpacity, delay);
}, delay)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment