Skip to content

Commit

Permalink
auto advance config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikel Maron authored and Mikel Maron committed Nov 18, 2022
1 parent 096294b commit 6e08b03
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ Note: items in bold are **required**.

`projection`: Set the Map object's [projection parameter](https://docs.mapbox.com/mapbox-gl-js/example/projections/) to create a map with a non-Mercator projection.. (Optional)

`auto`: Enables automatic advancement through the chapters. (Optional)

`title`: The title of the overall story. (Optional)

`subtitle`: A subtitle for the story. (Optional)
Expand Down
1 change: 1 addition & 0 deletions src/config.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var config = {
inset: true,
theme: 'dark',
use3dTerrain: false, //set true for enabling 3D maps.
auto: false,
title: 'The Title Text of this Story',
subtitle: 'A descriptive and interesting subtitle to draw in the reader',
byline: 'By a Digital Storyteller',
Expand Down
16 changes: 15 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,12 @@
progress: true
})
.onStepEnter(async response => {
var chapter = config.chapters.find(chap => chap.id === response.element.id);
var current_chapter = config.chapters.findIndex(chap => chap.id === response.element.id);
var chapter = config.chapters[current_chapter];

response.element.classList.add('active');
map[chapter.mapAnimation || 'flyTo'](chapter.location);

// Incase you do not want to have a dynamic inset map,
// rather want to keep it a static view but still change the
// bbox as main map move: comment out the below if section.
Expand Down Expand Up @@ -374,6 +377,12 @@
});
});
}
if (config.auto) {
var next_chapter = (current_chapter + 1) % config.chapters.length;
map.once('moveend', () => {
document.querySelectorAll('[data-scrollama-index="' + next_chapter.toString() + '"]')[0].scrollIntoView();
});
}
})
.onStepExit(response => {
var chapter = config.chapters.find(chap => chap.id === response.element.id);
Expand All @@ -382,6 +391,11 @@
chapter.onChapterExit.forEach(setLayerOpacity);
}
});


if (config.auto) {
document.querySelectorAll('[data-scrollama-index="0"]')[0].scrollIntoView();
}
});

//Helper functions for insetmap
Expand Down

0 comments on commit 6e08b03

Please sign in to comment.