-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTracksTimeLine.vue
188 lines (158 loc) · 4.7 KB
/
TracksTimeLine.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<template>
<div id="tracks-timeline">
<!-- A div with the same width as TimeRange -->
<!--div class="container-flex maindiv position-absolute left-0 right-0" style="user-select: none; right: 0; bottom: 120px; z-index: 1; opacity: 1; left: 130px"-->
<div class="tracksContainer" ref="tracksContainer">
<div class="trackMark" :class="{active: ff.selected}" @click="onTrackClicked" :id="ff.properties.id" :key="ff.properties.id" v-for="ff in features" :style="setFeatureStyle(ff)">
⬤
</div>
</div>
</div>
</template>
<script>
// REQUIERES palette.js
// Import components here
export default {
name: "tracks-timeline",
created(){
this.portOrder= {
"Sant Carles de la Ràpita": 9,
"L'Ametlla de Mar": 8,
"Tarragona": 7,
"Vilanova i la Geltrú": 6,
"Barcelona": 5,
"Arenys de Mar": 4,
"Blanes": 3,
"Palamós": 2,
"L'Escala": 1,
"Roses": 0,
};
},
mounted () {
},
data () {
return {
startDate: new Date(2018, 7, 21),
endDate: new Date(),
features: [],
}
},
methods: {
// INTERNAL METHODS
setFeatureStyle: function(ff){
// Current date
let currDate = new Date(ff.properties.info.Date);
// Visibility
let visible = currDate > this.startDate && currDate < this.endDate;
// Left position according to start and end date
let leftPercentage = -1 + 100*(currDate.getTime() - this.startDate.getTime()) / (this.endDate.getTime() - this.startDate.getTime());
// Limit on the sides to avoid overflow
leftPercentage = Math.min(97, leftPercentage);
leftPercentage = Math.max(0, leftPercentage);
// Opacity on the edges
let opacity = 0.5;
if (leftPercentage < 10)
opacity *= leftPercentage/10;
else if (leftPercentage > 90)
opacity *= (100-leftPercentage)/10;
// Port
let port = ff.properties.info.Port;
// Top position according to port
let top = this.portOrder[port];
// Color according to port from palette.js
let colorPort = palette ? palette[port].color : [0, 255,0];
if (visible){
return {
color: 'rgba(' + colorPort + ', 1.0)',
left: leftPercentage + '%',
top: (8 + top*5) + '%',
opacity: opacity,
'-webkit-text-stroke-width': '0.5px',
'-webkit-text-stroke-color': 'black',
transition: 'left 0.3s, opacity 0.5s',
}
// If it is not visible, hide it
} else {
return {
color: 'rgba(' + colorPort + ', 1.0)',
left: leftPercentage + '%',//'0%',
top: (8 + top*5) + '%',
opacity: 0,
}
}
},
onTrackClicked: function(event){
let id = event.target.id;
//this.showSelectedTrack(id); // It is already called from Map.vue
this.$emit('clickTrackMark', id);
},
// PUBLIC METHODS
// Set the geojson features
setFeatures: function(inFeatures){
this.features = inFeatures;
},
// Set start and end dates
setStartEndDates: function(sDate, eDate){
this.startDate.setTime(sDate.getTime());
this.endDate.setTime(eDate.getTime());
//this.features.pop();
this.features.push([]); // TODO: FIX TRICK, DIRTY HACK. FORCES setFeaturesStyle() in Vue
this.features.pop();
},
// Show selected track
showSelectedTrack: function(id){
this.features.forEach(ff => {
if (ff.properties.info.Id == id){
ff.selected = true;
} else
ff.selected = false;
});
},
// Hides the selected track (none selected)
hideSelectedTrack: function(){
this.features.forEach(ff => {
ff.selected = false;
});
}
},
components: {
},
computed: {
}
}
</script>
<style scoped>
#tracks-timeline {
position: relative;
width: calc(100% - 130px);
height:30px;
}
.tracksContainer {
height:100%;
left: 130px;
position: relative;
border-radius: 1rem;
user-select: none;
background: linear-gradient(90deg, rgba(160, 215, 242 ,0) 0%, rgba(160, 215, 242,0.8) 10%, rgba(160, 215, 242,0.8) 90%, rgba(160, 215, 242, 0) 100%);
box-shadow: 0 -1px 2px rgba(160, 215, 242,0.8);
}
.trackMark {
position: absolute;
font-size: 0.5rem;
cursor: pointer;
}
@keyframes selectedTrackAnimation {
0% { text-shadow: 0px 0px 4px black; }
50% { text-shadow: 0px 0px 0px black; }
100% { text-shadow: 0px 0px 4px black; }
}
.trackMark.active {
font-size: 1rem;
opacity: 1 !important;
z-index: 1;
margin-top: -6.5px;
margin-left: -4px;
text-shadow: 0px 0px 4px black;
animation: selectedTrackAnimation 1s infinite;
}
</style>