-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.html
executable file
·120 lines (92 loc) · 2.39 KB
/
plugin.html
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
<sounding>
<h3>This is my plugin (not official Windy's graph)</h3>
<div id="sounding-chart"></div>
<section>
<span data-ref="tcon"></span>
<span data-ref="ccl"></span>
<span data-ref="lcl"></span>
</section>
<section>
<span data-ref="model"></span>
<span data-ref="alt"></span>
<span data-ref="modelAlt"></span>
</section>
<div class="iconfont clickable-size" data-ref="zoom"></div>
<script>
// Windy's core modules
import rs from '@windy/rootScope'
import map from '@windy/map'
import store from '@windy/store'
import pluginDataLoader from '@windy/pluginDataLoader'
import _ from '@windy/utils'
// Our own modules
import graph from './soundingGraph.mjs'
const options = {
key: 'RxcwkWO2XWsfEbdidcsskbyWqhToAwLx'
, plugin: 'windy-plugin-examples'
}
const load = pluginDataLoader(options)
var marker = null
// Called when opened
this.onopen = latLonObject => {
let lat, lon
// Opening from other location than contextmenu
if(!latLonObject) {
const c = map.getCenter()
lat = c.lat
lon = c.lng
} else {
lat = latLonObject.lat
lon = latLonObject.lon
}
const leafletCoords = { lng: lon, lat }
, { x,y } = map.latLngToLayerPoint(leafletCoords)
let product = store.get('product')
if(!rs.isMobile ) {
this.node.style.position = 'absolute'
this.node.style.left = `${ x - 15 }px`
this.node.style.top = `${ y + 15 }px`
} else {
let height = this.node.clientHeight
map.center({lat,lon}, false )
.panBy( [ 0, - 0.5 * height + 50 ] )
}
if( marker ) {
marker.setLatLng( leafletCoords )
} else {
marker = L.marker( leafletCoords,
{ icon: map.myMarkers.pulsatingIcon,
zIndexOffset: -300 }
).addTo(map)
}
// Load d3 library from external source
if(!( 'd3' in window ) ) {
_.loadScript('https://unpkg.com/[email protected]/dist/d3.min.js')
.then( () => initAndLoad(lat,lon) )
} else {
initAndLoad(lat,lon)
}
this.node.oncontextmenu
= this.node.ondblclick
= this.node.onclick = ev => ev.stopPropagation()
}
const initAndLoad = (lat,lon) => {
const dataOptions = {
model: 'gfs'
, lat
, lon
}
graph.init( this.refs )
load('airData', dataOptions).then( (airData) => {
graph.load(lat,lon, airData.data)
})
}
// Called when closed
this.onclose = () => {
if( marker ) {
map.removeLayer( marker )
marker = null
}
}
</script>
</sounding>