The slidemapper plugin for Leaflet is very useful, but when building large slideshows, it can be annoying that there is no easy way to link to specific slides. For example, you might want to create a table of contents or link from the last slide back to the first. Fortunately, there's a way to move to specific slides, instead of just advancing or moving back by 1. We'll use jQuery to do this. We already have jQuery loaded for slidemapper.
Specify Where Links Will Go
$mySlideMap code in your html file, you can create a list of links that you will later add to the slides. Generally, this will be the last thing in the
<script> tag at the end of the body.
For example, in the sample code from the slidemapper example, the
<script> initially contains:
$mySlideMap = $('#slideshow-container')
At the end of the script, let's add a link to the first slide and a link to the last slide. The jQuery we use allows any code with a specific class to be transformed into a link. We can combine that with the slidemapper move method to create links to specific slides.
$mySlideMap.slideMapper('move', 0, true);
$mySlideMap.slideMapper('move', EXAMPLEDATA.length - 1, true);
Add the Links
Next, we need to actually include the links in the slides. The links references will go in the data file. In the example, the file is named data.js.
Here's a link to the last slide from the first slide:
// intro marker
marker: [42.516846, -70.898499],
center: [40.423, -98.7372],
html: '<table style="margin:0 40px; padding:10px"><tr>' +
'<td><img src="http://placehold.it/300x180&text=Map+Stuff"/></td>' +
'<td style="padding-left:10px">' +
'<h1>SlideMapper FTW!</h1>' +
'<p>This is a demo of the different sorts of slides you can setup using slidemapper.</p>' +
'<p><a class="end">Skip to the end.</a></p>' +
popup: 'So it begins!'
And here's a link from the last slide to the first slide:
// empty slide
html: '<div style="margin:0 40px; padding:20px 10px">' +
'<h2>The End</h2>' +
'<p><a class="toc">Return to Table of Contents.</a></p>' +
Because of the unusual way these links are made using jQuery, we should probably add some css to make them look like links. I added the following css to the
<head>, but you can add any css to the head or as a separate stylesheet.
And now you have an easy way to navigate through a long slidemapper deck. You could even create a table of contents at the beginning and then link back to that from each slide.
The full code is available in a gist.