Skip to content

Commit 95957e0

Browse files
committed
start nouislider
1 parent 0f5238f commit 95957e0

File tree

4 files changed

+87
-43
lines changed

4 files changed

+87
-43
lines changed

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"mapbox-gl": "^2.15.0",
3232
"mapboxgl-timeline": "^1.0.2",
3333
"mapillary-js": "4.1.2",
34+
"nouislider": "^15.7.1",
3435
"nuxt": "^2.17.2",
3536
"vue": "^2.7.16",
3637
"vue-google-charts": "^1.1.0",

pages/index.vue

+74-42
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,7 @@
2929
<div class="mapboxgl-ctrl-timeline__label">
3030
<input v-model="from" type="datetime-local">
3131
</div>
32-
<input
33-
ref="sliderInput"
34-
v-model="currentTime"
35-
class="mapboxgl-ctrl-timeline__slider"
36-
type="range"
37-
:min="min"
38-
:max="max"
39-
:style="`background-image: url('${sliderBackground}');`"
40-
>
32+
<div ref="noUiSlider" class="mapboxgl-ctrl-timeline__slider" :style="`background-image: url('${sliderBackground}');`" style="border: 0" />
4133
<div class="mapboxgl-ctrl-timeline__label">
4234
<input v-model="to" type="datetime-local">
4335
</div>
@@ -82,6 +74,8 @@ import mapboxgl from 'mapbox-gl'
8274
import { Viewer } from 'mapillary-js'
8375
import { parse } from 'wellknown'
8476
import flip from '@turf/flip'
77+
import * as noUiSlider from 'nouislider'
78+
import 'nouislider/dist/nouislider.css'
8579
import { closest, green } from '@/utils'
8680
import StyleSwitcher from '@/components/style-switcher.vue'
8781
import { getImage, init } from '@/utils/mapillary'
@@ -158,6 +152,9 @@ export default {
158152
}
159153
},
160154
watch: {
155+
/* currentTime (value) {
156+
this.$refs.noUiSlider.noUiSlider.set([value])
157+
}, */
161158
geofences () {
162159
const features = featureCollection(
163160
this.geofences
@@ -180,8 +177,8 @@ export default {
180177
if (this.i > 1 && map.getSource('route')) {
181178
map.getSource('route').setData(lineString(this.path.slice(0, this.i)))
182179
}
183-
if (this.model) {
184-
const model = get3dModel(this.device.category)
180+
if (this.path[this.i]) {
181+
const model = get3dModel(this.device && this.device.category)
185182
overlay.setProps({
186183
layers: [new ScenegraphLayer({
187184
id: model,
@@ -199,24 +196,17 @@ export default {
199196
sizeMinPixels: model.sizeMinPixels || 12
200197
})]
201198
})
199+
if (this.follow) {
200+
const camera = map.getFreeCameraOptions()
201+
camera.position = mapboxgl.MercatorCoordinate.fromLngLat(
202+
[this.route[this.i].longitude, this.route[this.i].latitude - (maxLatitudeDistance / this.playSpeed)],
203+
this.cameraAltitude
204+
)
205+
camera.lookAtPoint(this.path[this.i])
206+
map.setFreeCameraOptions(camera)
207+
}
208+
this.checkImage()
202209
}
203-
if (this.follow) {
204-
const camera = map.getFreeCameraOptions()
205-
camera.position = mapboxgl.MercatorCoordinate.fromLngLat(
206-
[this.route[this.i].longitude, this.route[this.i].latitude - (maxLatitudeDistance / this.playSpeed)],
207-
this.cameraAltitude
208-
)
209-
camera.lookAtPoint(this.path[this.i])
210-
map.setFreeCameraOptions(camera)
211-
}
212-
if (this.cockpit) {
213-
const camera = map.getFreeCameraOptions()
214-
camera.position = mapboxgl.MercatorCoordinate.fromLngLat(
215-
[this.route[this.i].longitude, this.route[this.i].latitude])
216-
camera.setPitchBearing(180, this.route[this.i].course)
217-
map.setFreeCameraOptions(camera)
218-
}
219-
this.checkImage()
220210
},
221211
path () {
222212
this.loading = false
@@ -227,6 +217,13 @@ export default {
227217
this.updateSliderBackground()
228218
init(bounds, this.path, map)
229219
this.checkImage()
220+
this.$refs.noUiSlider.noUiSlider.updateOptions({
221+
range: {
222+
min: this.min,
223+
max: this.max
224+
}
225+
})
226+
this.$refs.noUiSlider.noUiSlider.set([this.min, this.max])
230227
}
231228
},
232229
playing () {
@@ -336,7 +333,7 @@ export default {
336333
}
337334
},
338335
mounted () {
339-
new ResizeObserver(this.updateSliderBackground).observe(this.$refs.sliderInput)
336+
new ResizeObserver(this.updateSliderBackground).observe(this.$refs.noUiSlider)
340337
this.loading = true
341338
map = new mapboxgl.Map({
342339
container: 'map', // container ID
@@ -361,6 +358,25 @@ export default {
361358
accessToken: process.env.MAPILLARY_ACCESS_TOKEN,
362359
container: this.$refs.mapillaryViewer
363360
})
361+
noUiSlider.create(this.$refs.noUiSlider,
362+
{
363+
start: [this.min, this.max],
364+
connect: true,
365+
tooltips: [
366+
{ to: value => new Date(value).toLocaleString() },
367+
{ to: value => new Date(value).toLocaleString() }
368+
],
369+
pips: {
370+
mode: 'positions',
371+
values: [0, 50, 100],
372+
format: { to: value => new Date(value).toLocaleString() }
373+
},
374+
range: {
375+
min: this.min || 0,
376+
max: this.max || 0
377+
}
378+
})
379+
this.$refs.noUiSlider.noUiSlider.on('update', ([from, to]) => { this.currentTime = to })
364380
},
365381
methods: {
366382
styleImageMissing (e) {
@@ -372,14 +388,20 @@ export default {
372388
},
373389
checkImage () {
374390
const i = this.i
375-
const image = getImage(this.path[i], this.route[i].course)
376-
if (image.id && this.imgId !== image.id && this.imgTime !== 'loading...') {
377-
this.imgTime = 'loading...'
378-
this.imgId = image.id
379-
viewer.moveTo(image.id)
380-
.then(() => { this.imgTime = new Date(this.route[i].fixTime).toLocaleString() })
381-
.catch((e) => { this.imgTime = e.message })
382-
// viewer.setCenter(this.route[this.i].course)
391+
if (this.route[i]) {
392+
const image = getImage(this.path[i], this.route[i].course)
393+
if (image.id && this.imgId !== image.id && this.imgTime !== 'loading...') {
394+
this.imgTime = 'loading...'
395+
this.imgId = image.id
396+
viewer.moveTo(image.id)
397+
.then(() => {
398+
this.imgTime = new Date(this.route[i].fixTime).toLocaleString()
399+
})
400+
.catch((e) => {
401+
this.imgTime = e.message
402+
})
403+
// viewer.setCenter(this.route[this.i].course)
404+
}
383405
}
384406
},
385407
styleChanged (style) {
@@ -408,7 +430,7 @@ export default {
408430
status = 0
409431
}
410432
})
411-
this.drawLine(context, linePosition, this.$refs.sliderInput.clientWidth, -1)
433+
this.drawLine(context, linePosition, this.$refs.noUiSlider.clientWidth, -1)
412434
this.sliderBackground = canvas.toDataURL()
413435
}
414436
},
@@ -420,13 +442,13 @@ export default {
420442
1: green,
421443
2: '#F9B218'
422444
}[status]
423-
context.lineWidth = 10
424-
context.moveTo(start, 4)
425-
context.lineTo(end, 4)
445+
context.lineWidth = 20
446+
context.moveTo(start, 10)
447+
context.lineTo(end, 10)
426448
context.stroke()
427449
},
428450
getEndIndex (date) {
429-
return this.$refs.sliderInput.clientWidth * (new Date(date) - this.min) / (this.max - this.min)
451+
return this.$refs.noUiSlider.clientWidth * (new Date(date) - this.min) / (this.max - this.min)
430452
},
431453
newColoredLine (p, context, currentLinePosition, currentStatus) {
432454
const end = this.getEndIndex(p.fixTime)
@@ -548,4 +570,14 @@ export default {
548570
height: 32px !important;
549571
background-color: red;
550572
}
573+
.noUi-horizontal .noUi-tooltip {bottom: -150%;}
574+
.noUi-connect {
575+
background: rgba(0,0,0,0.4);
576+
}
577+
.noUi-pips {
578+
position: absolute;
579+
color: #999;
580+
text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
581+
582+
}
551583
</style>

store/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const actions = {
3636
const from = new Date(state.from || query.get('from') || new Date().getTime() - 1000 * 60 * 60 * 24).toISOString()
3737
const to = new Date(state.to || query.get('to') || new Date().getTime() + 1000 * 60 * 60 * 24).toISOString()
3838
await dispatch('getUserData')
39-
const device = state.devices.find(d => d.id === parseInt(query.get('deviceId'))) || state.devices[0]
39+
const device = state.devices.filter(d => d).find(d => d.id === parseInt(query.get('deviceId'))) || state.devices[0]
4040
const _route = await this.$axios.$get(`/reports/route?deviceId=${device.id}&from=${from}&to=${to}`)
4141
const route = prettify(_route, 1)
4242
if (!state.from) { commit('SET_FROM', from) }

0 commit comments

Comments
 (0)