Skip to content

Commit a7e7c62

Browse files
committed
Allow usage of arrows to select data in WMTS viewer #278
1 parent 95cbf7e commit a7e7c62

File tree

1 file changed

+58
-8
lines changed

1 file changed

+58
-8
lines changed

src/components/maps/WebServiceMixin.vue

+58-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
return {
1717
WMTSCapabilities: {},
1818
timeline: null,
19+
times: []
1920
}
2021
},
2122
methods: {
@@ -93,10 +94,10 @@ export default {
9394
defaultDate = new Date(options.dimensions.TIME);
9495
}
9596
96-
let times = this.getWMTSTimes(capabilities, layer);
97-
if (times.length) {
98-
let min = new Date(times[0]);
99-
let max = new Date(times[times.length -1]);
97+
this.times = this.getWMTSTimes(capabilities, layer);
98+
if (this.times.length) {
99+
let min = new Date(this.times[0]);
100+
let max = new Date(this.times[this.times.length-1]);
100101
if (!minDate || min < minDate) {
101102
minDate = min;
102103
}
@@ -124,7 +125,15 @@ export default {
124125
maxDate: maxDate
125126
});
126127
let run;
128+
let toDate = (date) => {
129+
return [
130+
date.getFullYear(),
131+
("0" + (date.getMonth() + 1)).slice(-2),
132+
("0" + date.getDate()).slice(-2)
133+
].join('-');
134+
};
127135
this.timeline.on('scroll', function(e) {
136+
console.log(e);
128137
if (!e.date || e.date > maxDate || e.date < minDate) {
129138
return;
130139
}
@@ -133,13 +142,14 @@ export default {
133142
}
134143
run = window.setTimeout(() => {
135144
try {
136-
let date = e.date.toISOString().substr(0, 10);
145+
console.log(e.date);
146+
let date = toDate(e.date);
147+
console.log(date);
137148
source.updateDimensions({
138149
TIME: date
139150
});
140151
let btns = document.getElementsByClassName('timeline-date-label');
141152
btns[0].innerText = date;
142-
btns[0].disabled = true;
143153
} catch (error) {
144154
console.log(error);
145155
}
@@ -148,12 +158,52 @@ export default {
148158
});
149159
this.map.addControl(this.timeline);
150160
161+
this.timeline.addButton({
162+
className: 'timeline-prev-label',
163+
title: 'Go to previous date',
164+
html: '<',
165+
handleClick: () => {
166+
console.log(this.timeline.getDate());
167+
console.log(this.times);
168+
}
169+
});
151170
this.timeline.addButton({
152171
className: 'timeline-date-label',
153172
title: `The date that is shown on the map for the collection '${title}'`,
154-
html: 'No date'
173+
html: 'No date',
174+
handleClick: () => {
175+
let date = this.timeline.getDate();
176+
let newDate = toDate(date);
177+
while (typeof newDate === 'string') {
178+
newDate = prompt("Please specify the date (format: YYYY-MM-DD) you want to go to:", newDate);
179+
if (typeof newDate !== 'string') {
180+
return;
181+
}
182+
let match = newDate.match(/^\s*(\d{1,4})-(\d{2})-(\d{2})\s*$/);
183+
if (match) {
184+
let parts = match.slice(1, 4).map(x => parseInt(x, 10));
185+
date.setFullYear(parts[0]);
186+
date.setMonth(parts[1] - 1);
187+
date.setDate(parts[2]);
188+
console.log(date);
189+
this.timeline.setDate(date);
190+
console.log(this.timeline.getDate());
191+
return;
192+
}
193+
}
194+
}
155195
});
156-
this.timeline.setDate(defaultDate);
196+
this.timeline.addButton({
197+
className: 'timeline-next-label',
198+
title: 'Go to next label',
199+
html: '>',
200+
handleClick: () => {
201+
console.log(this.timeline.getDate());
202+
203+
}
204+
});
205+
206+
this.timeline.setDate(defaultDate, {anim: false});
157207
}
158208
159209
let group = new LayerGroup({

0 commit comments

Comments
 (0)