-
Notifications
You must be signed in to change notification settings - Fork 1
/
flow-layer.js
83 lines (76 loc) · 2.45 KB
/
flow-layer.js
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
import L from 'leaflet'
import 'leaflet-velocity'
import 'leaflet-velocity/dist/leaflet-velocity.css'
import { createColorMap } from 'weacast-core/client'
import { ForecastLayer } from './forecast-layer'
let FlowLayer = ForecastLayer.extend({
initialize (api, options) {
// FIXME : make this dynamic, ie relative mode based on min/max when data are set
this.colorMap = createColorMap(options)
// Merge options with default for undefined ones
const layerOptions = Object.assign({
displayValues: true,
displayOptions: {
velocityType: 'Wind',
position: 'bottomright',
emptyString: 'No wind data',
angleConvention: 'bearingCW',
speedUnit: 'kt'
},
minVelocity: this.colorMap.domain()[0],
maxVelocity: this.colorMap.domain()[1],
velocityScale: 0.01, // modifier for particle animations, arbitrarily defaults to 0.005
colorScale: (this.options.invertScale ? this.colorMap.colors().reverse() : this.colorMap.colors()),
data: null // data will be requested on-demand
}, options)
let layer = L.velocityLayer(layerOptions)
ForecastLayer.prototype.initialize.call(this, api, layer, options)
// Format in leaflet-velocity layer data model
this.uFlow = {
header: {
parameterCategory: 2,
parameterNumber: 2
},
data: []
}
this.vFlow = {
header: {
parameterCategory: 2,
parameterNumber: 3
},
data: []
}
},
setData (data) {
if (data.length > 1) {
this.uFlow.data = data[0].data
this.vFlow.data = data[1].data
this.baseLayer.setData([this.uFlow, this.vFlow])
ForecastLayer.prototype.setData.call(this, data)
} else {
this.uFlow.data = []
this.vFlow.data = []
this.hasData = false
this.baseLayer.setData([this.uFlow, this.vFlow])
}
},
setForecastModel (model) {
// Format in leaflet-velocity layer data model
let modelHeader = {
nx: model.size[0],
ny: model.size[1],
lo1: model.origin[0],
la1: model.origin[1],
dx: model.resolution[0],
dy: model.resolution[1]
}
Object.assign(this.uFlow.header, modelHeader)
Object.assign(this.vFlow.header, modelHeader)
ForecastLayer.prototype.setForecastModel.call(this, model)
}
})
L.weacast.FlowLayer = FlowLayer
L.weacast.flowLayer = function (api, options) {
return new L.weacast.FlowLayer(api, options)
}
export { FlowLayer }