-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrphaned_Wells.js
163 lines (144 loc) · 5.33 KB
/
Orphaned_Wells.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
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
function loadJSON(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'Orphaned_Wells.json', true); // Replace 'my_data' with the path to your file
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
}
};
xobj.send(null);
}
const options = {
// Required: API key
key: 'scLWW3eRjVaw4Oehb6WBobcQLQtbqRI4',
verbose: true,
lat: 54.6,
lon: -115,
zoom: 5,
hourFormat: '24h',
overlay: 'wind',
// acTime: 'next3d',
// numDirection: false,
// timestamp:Date.now(),
};
// Initialize Windy API
windyInit(options, windy => {
const {broadcast, map, store, utils} = windy;
// const sites = {};
const markers = {};
const licenses = {};
store.set('overlay', 'wind');
store.set('level', '100m');
// const winds = {};
function wellStyle(intensity) {
// var zm = map.getZoom();
var hue = "hsl("+(90+270*intensity)+", 80%, 50%)";
return {
fillColor: hue,//"#ff6666",
fillOpacity: intensity*0.9,
color: "#00000a",
opacity: 0.5,
radius: 4,
weight: 1,
}
}
function wellSelectedStyle() {
return {
fillColor: "#ff6666",
fillOpacity: 1,
color: "#B04173",
radius: 7,
}
}
function wellOnEachFeature(feature, layer){
layer.on({
click: function(e) {
if (selection) {
resetStyles();
}
e.target.setStyle(wellSelectedStyle());
selection = e.target;
selectedLayer = wellLayer;
// Insert some HTML with the feature name
buildSummaryLabel(feature);
L.DomEvent.stopPropagation(e);
// stop click event from being propagated further
}
});
}
function resetStyles(){
if (selectedLayer === wellLayer) selection.setStyle(wellStyle());
}
loadJSON(function(response){
var orphanWells = JSON.parse(response);
for (const well of orphanWells.features) {
let lat = well.geometry.coordinates[1];
let lon = well.geometry.coordinates[0];
let latlon = lat + ' ' + lon;
let license = well.properties.Licence;
const marker = L.circleMarker([lat, lon], wellStyle(0)).addTo(map);
markers[latlon] = marker;
licenses[latlon] = license;
}
});
function getLatLon(latLon) {
const parts = latLon.split(' ');
return {lat: +parts[0], lon: +parts[1]};
}
function updateMarker(latlon, wind) {
let windspd = wind.wind.toFixed(1);
var intense;
var power;
if (windspd < 3.0) {
intense = 0.;
power = 0.;
} else if (windspd > 24.0) {
intense = 0.;
power = 0.;
} else {
let rise = 4200*jStat.weibull.cdf(windspd,8,4.4);
let fall = -680*windspd+17500;
power = Math.min(rise, 4200, fall);
intense = power/4200;
}
markers[latlon].setStyle(wellStyle(intense));
let tooltip = '<div style="min-width: 50px;">License: '+ licenses[latlon]+'<br>' + windspd+ ' m/s; ' + (power/1000).toFixed(1) + ' MW </div>';
markers[latlon].bindPopup(tooltip);
return power;
}
function redraw() {
W.tileInterpolator.createFun(interpolate => {
let totalPower = 0;
let numTurbines = 0;
// var popup = null;
for (const latlon in markers) {
if (map.getBounds().contains(getLatLon(latlon))) {
let wind;
if (store.get('overlay') == 'wind') {
//If the displaed overlay is 'wind' then use it.
const data = interpolate(getLatLon(latlon));
wind = utils.wind2obj(data);
totalPower += updateMarker(latlon, wind);
numTurbines += 1;
}
}
}
document.getElementById('windOut').innerHTML = "With a 4.2 MW " + "<a href='https://www.vestas.com/en/products/4-mw-platform/v150-4_2_mw'>Vestas turbine</a>" + " at each well on the map, they would be generating "+ (totalPower/1000).toFixed(0)+ " MW, with an average output of " +(totalPower/numTurbines/1000).toFixed(1) + " MW";
document.documentElement.style.setProperty('--timing',4200/(totalPower/numTurbines).toFixed(3));
// document.querySelector('.blades').style.timing = 8000/(totalPower/1000).toFixed(0);
// const popLoc = map.getCenter();
// if (popup) {
// popup.setLatLng(popLoc);
// popup.update();
// } else {
// popup = L.popup()
// .setLatLng(popLoc)
// .setContent('Total power: '+ (totalPower/1000).toFixed(0) +' MW')
// .openOn(map);
// }
})
}
broadcast.on("redrawFinished", redraw);
});