-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGeneralInformation.vue
186 lines (166 loc) · 5.49 KB
/
GeneralInformation.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
<template>
<div class="map" :id="map.id" />
</template>
<script>
import { addEpicenter, createMap, id, removeEpicenter, setView, addFeltReports } from '@/map_functions'
import { numberDeclension } from '@/helpers/number'
import apiSettings from '@/settings/api'
export default {
props: ['event', 'tab'],
data() {
return {
coordinates: [],
markersGroup: null,
map: {
epicenter: null,
id: null,
object: null,
pga: []
}
}
},
methods: {
syncFeltReportData: function(event) {
if (this.event.nearestCity.data.feltReportAnalysis || this.event.felt_reports_count) {
this.$http.get(apiSettings.endpointEventMeasuredIntensityAggregations(this.event.id))
.then(response => {
this.addData(event.data.data, response.data.feltReports)
})
.catch(error => {
console.log(error)
this.addData(event.data.data)
})
} else {
this.addData(event.data.data)
}
},
addData: function(data, feltReports = []) {
let legendData = `
<table>
<thead>
<tr>
<th>ШСИ</th>
<th></th>
<th>%g</th>
</tr>
</thead>
<tbody>`
Object.keys(data).forEach((key) => {
const lineColor = this.pgaLineColor(key)
const pga = window.L.polygon(data[key].data, { color: lineColor, weigh: 2 })
this.map.pga.push(pga)
pga.addTo(this.map.object)
const nextRange = data[parseInt(key) + 1]
let intensityLegendValue = this.pgaToIntensity(data[key].range)
let pgaLegendValue = data[key].range
let intensityPopupRange = intensityLegendValue - 0.2
let pgaPopupRange = data[key].range
if (nextRange) {
intensityPopupRange += ` - ${this.pgaToIntensity(nextRange.range)}`
pgaPopupRange += ` - ${nextRange.range}`
} else {
intensityLegendValue += `+`
pgaLegendValue += `+`
pgaPopupRange += `+`
}
legendData += `
<tr>
<td align="right">${intensityLegendValue}</td>
<td><i style="background: ${lineColor}; margin-left: 8px;"></i></td>
<td>${pgaLegendValue}</td>
</tr>`
const popupMessage = `
Пиковое ускорение грунта: ${pgaPopupRange}%g <br>
Интенсивность по ШСИ-2017: ${intensityPopupRange} ${numberDeclension(intensityLegendValue, ['балл', 'балла', 'баллов'])}
`
pga.bindPopup(popupMessage)
})
if (feltReports.length) {
this.markersGroup = addFeltReports(this.map.object, feltReports, this.map.object._controls)
}
// Show map legend just once.
if (!this.$el.querySelector('.map-legend')) {
let pgaLegend = window.L.control({ position: 'bottomright' })
pgaLegend.onAdd = (map) => {
const div = window.L.DomUtil.create('div', 'map-legend')
div.innerHTML += legendData + `</tbody></table>`
return div
}
pgaLegend.addTo(this.map.object)
}
this.putEpicenter()
},
createMap: function() {
this.map.object = createMap(this.map.id, this.coordinates)
},
fetchData: function()
{
if (!this.event.has_pga_data) {
return this.putEpicenter()
}
this.$http.get(apiSettings.endpointEventPga(this.event.id))
.then(response => {
this.syncFeltReportData(response)
})
.catch(error => {
console.log(error)
this.putEpicenter()
})
},
initialize: function() {
this.map.id = id(this.event.id, this.tab)
this.coordinates = [this.event.locValues.data.lat, this.event.locValues.data.lon]
},
pgaLineColor: function(index) {
const colors = ['#fff5f0', '#fee0d2', '#fcbba1', '#fc9272', '#fb6a4a', '#ef3b2c', '#cb181d', '#a50f15', '#67000d']
return colors[index - 1]
},
pgaToIntensity: function(pga) {
switch (pga) {
case '0.175': return 2.5
case '0.28': return 3
case '0.7': return 4
case '1.75': return 5
case '4.4': return 6
case '11.0': return 7
case '28.0': return 8
case '70.0': return 9
case '110.0': return 9.5
}
},
putEpicenter: function() {
this.map.epicenter = addEpicenter(this.map.object, this.coordinates)
},
removeData: function() {
// Remove PGA polylines.
this.map.pga.forEach(layer => { this.map.object.removeLayer(layer) })
if (this.markersGroup) {
this.map.object.removeLayer(this.markersGroup)
this.map.object._controls.removeLayer(this.markersGroup)
}
},
resetMap: function() {
removeEpicenter(this.map.object, this.map.epicenter)
this.removeData()
setView(this.map.object, this.coordinates)
}
},
created() {
this.initialize()
},
mounted() {
this.createMap()
this.fetchData()
},
watch: {
event: function(data) {
this.initialize()
this.resetMap()
this.fetchData()
}
}
}
</script>
<style lang="scss">
@import '~scss/event_map';
</style>