Skip to content

Commit bf279bd

Browse files
committed
document
1 parent 0e736ff commit bf279bd

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const temporalFrames = [
3333
title:'frame1', // shown on control panel
3434
layers:[anyLayer1_1, anyLayer1_2] // set layers you want to show at one frame...
3535
},
36+
{
3637
title:'frame2',
3738
layers:[anyLayer2_1, anyLayer2_2]
3839
},
@@ -46,7 +47,7 @@ const temporalFrames = [
4647
const temporalControl = new TemporalControl(temporalFrames, {
4748
interval: 100, // duration a frame is shown, in miliseconds
4849
position: 'top-left',
49-
performance: true // set when rendering is too slow, but frames which are not current are shown mostly transparent
50+
performance: true // set when rendering is too slow
5051
});
5152
map.addControl(temporalControl);
5253

@@ -55,12 +56,15 @@ temporalControl.prev()
5556
temporalControl.next()
5657
temporalControl.play()
5758
temporalControl.pause()
59+
temporalControl.isPlaying()
60+
temporalControl.isLoopEnabled()
5861
temporalControl.setLoopEnabled(true)
62+
temporalControl.goto(5)
5963
```
6064

6165
### Tips
6266

63-
- In frames, You must set layer-objects corresponding to in map.
64-
- Layers set in frames must be added in map
67+
- Layers set in frames must be added in the map
68+
- In each frames, You have to set layer-objects corresponding to the layers added to the map.
6569
- when `performance: true`, not-current frames are shown as opacity=0.000000000000000000001
6670
- this option may not be neccesary for ordinary usecases

example/raster.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<button id="btn-pause">pause</button>
2828
<button id="btn-play">play</button>
2929
<button id="btn-next">next</button>
30+
<button id="btn-goto">goto 7th frame</button>
3031
</div>
3132
<script type="module" src="./raster.ts"></script>
3233
</body>

example/raster.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,9 @@ nowcast.getTimeData().then((timedata) => {
151151
btnLoop.addEventListener('click', () => {
152152
temporalControl.setLoopEnabled(!temporalControl.isLoopEnabled());
153153
});
154+
155+
const btnGoto = document.getElementById('btn-goto')!;
156+
btnGoto.addEventListener('click', () => {
157+
temporalControl.goto(6);
158+
});
154159
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "maplibre-gl-temporal-control",
33
"type": "module",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"description": "Temporal Control plugin for Maplibre GL JS",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export default class TemporalControl implements IControl {
205205
isPlaying: () => boolean;
206206
isLoopEnabled: () => boolean;
207207
setLoopEnabled: (enabled: boolean) => void;
208+
goto: (index: number) => void;
208209

209210
constructor(temporalFrames: TemporalFrame[], options: Options = {}) {
210211
this.temporalFrames = temporalFrames;
@@ -239,6 +240,12 @@ export default class TemporalControl implements IControl {
239240
this.isPlaying = isPlaying;
240241
this.isLoopEnabled = isLoopEnabled;
241242
this.setLoopEnabled = setLoopEnabled;
243+
this.goto = (idx: number) => {
244+
slider.value = String(
245+
Math.min(this.temporalFrames.length - 1, Math.max(0, idx)),
246+
);
247+
this.refresh();
248+
};
242249
}
243250

244251
onAdd(map: Map) {

0 commit comments

Comments
 (0)