-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFleetView.js
More file actions
243 lines (216 loc) · 17.1 KB
/
FleetView.js
File metadata and controls
243 lines (216 loc) · 17.1 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import loadScript from "./reusable/loadScript.js";
const plugin = ({ box, widgets }) => {
widgets.register("Map", (box) => {
loadScript(box.window, `https://maps.googleapis.com/maps/api/js?key=AIzaSyC3LEcjTvyxYu1urM8qrGtZc_a5eNlPdW0`)
.then(() => {
const rectangleCoordinates = [
{
"lat": 47.93330662389945,
"lng": 6.8981571326644175
},
{
"lat": 53.08277351361783,
"lng": 13.195127235586439
},
]
const container = document.createElement("div")
container.setAttribute("style", `display:flex; height: 100%; width: 100%;`)
box.injectNode(container)
const rectCenter = new box.window.google.maps.LatLngBounds(rectangleCoordinates[0], rectangleCoordinates[1]).getCenter()
const map = new box.window.google.maps.Map(container, {
zoom: 6.3,
center: rectCenter,
mapTypeId: 'terrain'
});
new box.window.google.maps.Rectangle({
strokeColor: '#0000FF',
strokeOpacity: 0.3,
strokeWeight: 2,
fillColor: '#0000FF',
fillOpacity: 0.05,
map,
bounds: {
north: rectangleCoordinates[1].lat,
south: rectangleCoordinates[0].lat,
east: rectangleCoordinates[1].lng,
west: rectangleCoordinates[0].lng,
},
});
// Create an object to store the markers by vehicleId
const vehicleMarkers = {}
// Fetch vehicle coordinates and add markers to map
fetch('https://fleetsim.onrender.com/vehicle/all/coordinates')
.then(response => response.json())
.then(vehicleCoordinates => {
// For each vehicle, create a marker on the map
for (let vehicleId in vehicleCoordinates) {
let coordinates = vehicleCoordinates[vehicleId];
// Store market in markers object
vehicleMarkers[vehicleId] = new box.window.google.maps.Marker({
position: { lat: coordinates.latitude, lng: coordinates.longitude },
map: map,
icon: {
path: "M -53.582954,-415.35856 C -67.309015,-415.84417 -79.137232,-411.40275 -86.431515,-395.45159 L -112.76807,-329.50717 C -131.95714,-324.21675 -140.31066,-310.27864 -140.75323,-298.84302 L -140.75323,-212.49705 L -115.44706,-212.49705 L -115.44706,-183.44029 C -116.67339,-155.74786 -71.290042,-154.67757 -70.275134,-183.7288 L -69.739335,-212.24976 L 94.421043,-212.24976 L 94.956841,-183.7288 C 95.971739,-154.67759 141.39631,-155.74786 140.16998,-183.44029 L 140.16998,-212.49705 L 165.43493,-212.49705 L 165.43493,-298.84302 C 164.99236,-310.27864 156.63886,-324.21677 137.44977,-329.50717 L 111.11322,-395.45159 C 103.81894,-411.40272 91.990714,-415.84414 78.264661,-415.35856 L -53.582954,-415.35856 z M -50.57424,-392.48409 C -49.426163,-392.49037 -48.215854,-392.45144 -46.988512,-392.40166 L 72.082372,-392.03072 C 82.980293,-392.28497 87.602258,-392.03039 92.236634,-381.7269 L 111.19565,-330.61998 L -86.30787,-330.86727 L -67.554927,-380.61409 C -64.630656,-390.57231 -58.610776,-392.44013 -50.57424,-392.48409 z M -92.036791,-305.02531 C -80.233147,-305.02529 -70.646071,-295.47944 -70.646071,-283.6758 C -70.646071,-271.87217 -80.233147,-262.28508 -92.036791,-262.28508 C -103.84043,-262.28508 -113.42751,-271.87216 -113.42751,-283.6758 C -113.42751,-295.47946 -103.84043,-305.02531 -92.036791,-305.02531 z M 117.91374,-305.02531 C 129.71738,-305.02533 139.26324,-295.47944 139.26324,-283.6758 C 139.26324,-271.87216 129.71738,-262.28508 117.91374,-262.28508 C 106.1101,-262.28507 96.523021,-271.87216 96.523021,-283.6758 C 96.523021,-295.47944 106.1101,-305.02531 117.91374,-305.02531 z M 103.2216,-333.14394 L 103.2216,-333.14394 z M 103.2216,-333.14394 C 103.11577,-333.93673 102.96963,-334.55679 102.80176,-335.21316 C 101.69663,-339.53416 100.2179,-342.16153 97.043938,-345.3793 C 93.958208,-348.50762 90.488134,-350.42644 86.42796,-351.28706 C 82.4419,-352.13197 45.472822,-352.13422 41.474993,-351.28706 C 33.885682,-349.67886 27.380491,-343.34759 25.371094,-335.633 C 25.286417,-335.3079 25.200722,-334.40363 25.131185,-333.2339 L 103.2216,-333.14394 z M 64.176391,-389.01277 C 58.091423,-389.00227 52.013792,-385.83757 48.882186,-379.47638 C 47.628229,-376.92924 47.532697,-376.52293 47.532697,-372.24912 C 47.532697,-368.02543 47.619523,-367.53023 48.822209,-364.99187 C 50.995125,-360.40581 54.081354,-357.67937 59.048334,-355.90531 C 60.598733,-355.35157 62.040853,-355.17797 64.86613,-355.27555 C 68.233081,-355.39187 68.925861,-355.58211 71.703539,-356.95492 C 75.281118,-358.72306 77.90719,-361.35074 79.680517,-364.96188 C 80.736152,-367.11156 80.820083,-367.68829 80.820085,-372.0392 C 80.820081,-376.56329 80.765213,-376.87662 79.470596,-379.50637 C 76.3443,-385.85678 70.261355,-389.02327 64.176391,-389.01277 z",
fillColor: '#2563eb',
fillOpacity: 1,
anchor: new box.window.google.maps.Point(12, -290),
strokeWeight: 0,
scale: .1,
rotation: 0
},
clickable: true
});
vehicleMarkers[vehicleId].addListener('click', () => {
window.location.href = `/model/RBWCkwGkZqqfh6Dv3gMf/library/prototype/ZZ5wU5IDDPN6hDURdZrd/view/run?vehicleId=${vehicleId}`
})
}
});
// Every 5 seconds, fetch the new coordinates and update the vehicle markers
setInterval(async () => {
const response = await fetch("https://fleetsim.onrender.com/vehicle/all/coordinates")
const vehicleCoordinates = await response.json();
Object.keys(vehicleCoordinates).forEach(vehicleId => {
const coordinates = vehicleCoordinates[vehicleId];
vehicleMarkers[vehicleId].setPosition({ lat: coordinates.latitude, lng: coordinates.longitude });
})
}, 5000);
// Create an object to store the markers by chargestationId
const chargestationMarkers = {}
// Fetch chargestation coordinates and add markers to map
fetch('https://fleetsim.onrender.com/chargestation/all/coordinates')
.then(response => response.json())
.then(chargestationCoordinates => {
// For each vehicle, create a marker on the map
for (let chargestationId in chargestationCoordinates) {
let coordinates = chargestationCoordinates[chargestationId];
// Store market in markers object
chargestationMarkers[chargestationId] = new box.window.google.maps.Marker({
position: { lat: coordinates.latitude, lng: coordinates.longitude },
map: map,
clickable: true
});
chargestationMarkers[chargestationId].addListener('click', () => {
window.location.href = `/model/JUczdpLduBR24kMeMpyC/library/prototype/TX73uJZmwGVy3a4M3jaY/view/run?chargestationId=${chargestationId}`
})
}
});
// Every 5 seconds, fetch the new coordinates and update the chargestation markers
setInterval(async () => {
const response = await fetch("https://fleetsim.onrender.com/chargestation/all/coordinates")
const chargestationCoordinates = await response.json();
Object.keys(chargestationCoordinates).forEach(chargestationId => {
const coordinates = chargestationCoordinates[chargestationId];
chargestationMarkers[chargestationId].setPosition({ lat: coordinates.latitude, lng: coordinates.longitude });
})
}, 5000);
})
})
///////// Maps for Dev /////////
widgets.register("MapDev", (box) => {
loadScript(box.window, `https://maps.googleapis.com/maps/api/js?key=AIzaSyC3LEcjTvyxYu1urM8qrGtZc_a5eNlPdW0`)
.then(() => {
const rectangleCoordinates = [
{
lat: 49.1427,
lng: 9.2109
},
{
lat: 50.1109,
lng: 8.6821
}
]
const container = document.createElement("div")
container.setAttribute("style", `display:flex; height: 100%; width: 100%;`)
box.injectNode(container)
const rectCenter = new box.window.google.maps.LatLngBounds(rectangleCoordinates[0], rectangleCoordinates[1]).getCenter()
const map = new box.window.google.maps.Map(container, {
zoom: 6.3,
center: rectCenter,
mapTypeId: 'terrain'
});
new box.window.google.maps.Rectangle({
strokeColor: '#0000FF',
strokeOpacity: 0.3,
strokeWeight: 2,
fillColor: '#0000FF',
fillOpacity: 0.05,
map,
bounds: {
north: rectangleCoordinates[1].lat,
south: rectangleCoordinates[0].lat,
east: rectangleCoordinates[1].lng,
west: rectangleCoordinates[0].lng,
},
});
// Create an object to store the markers by vehicleId
const vehicleMarkers = {}
// Fetch vehicle coordinates and add markers to map
fetch('https://fleetsim.onrender.com/vehicle/all/coordinates')
.then(response => response.json())
.then(vehicleCoordinates => {
// For each vehicle, create a marker on the map
for (let vehicleId in vehicleCoordinates) {
let coordinates = vehicleCoordinates[vehicleId];
// Store market in markers object
vehicleMarkers[vehicleId] = new box.window.google.maps.Marker({
position: { lat: coordinates.latitude, lng: coordinates.longitude },
map: map,
icon: {
path: "M -53.582954,-415.35856 C -67.309015,-415.84417 -79.137232,-411.40275 -86.431515,-395.45159 L -112.76807,-329.50717 C -131.95714,-324.21675 -140.31066,-310.27864 -140.75323,-298.84302 L -140.75323,-212.49705 L -115.44706,-212.49705 L -115.44706,-183.44029 C -116.67339,-155.74786 -71.290042,-154.67757 -70.275134,-183.7288 L -69.739335,-212.24976 L 94.421043,-212.24976 L 94.956841,-183.7288 C 95.971739,-154.67759 141.39631,-155.74786 140.16998,-183.44029 L 140.16998,-212.49705 L 165.43493,-212.49705 L 165.43493,-298.84302 C 164.99236,-310.27864 156.63886,-324.21677 137.44977,-329.50717 L 111.11322,-395.45159 C 103.81894,-411.40272 91.990714,-415.84414 78.264661,-415.35856 L -53.582954,-415.35856 z M -50.57424,-392.48409 C -49.426163,-392.49037 -48.215854,-392.45144 -46.988512,-392.40166 L 72.082372,-392.03072 C 82.980293,-392.28497 87.602258,-392.03039 92.236634,-381.7269 L 111.19565,-330.61998 L -86.30787,-330.86727 L -67.554927,-380.61409 C -64.630656,-390.57231 -58.610776,-392.44013 -50.57424,-392.48409 z M -92.036791,-305.02531 C -80.233147,-305.02529 -70.646071,-295.47944 -70.646071,-283.6758 C -70.646071,-271.87217 -80.233147,-262.28508 -92.036791,-262.28508 C -103.84043,-262.28508 -113.42751,-271.87216 -113.42751,-283.6758 C -113.42751,-295.47946 -103.84043,-305.02531 -92.036791,-305.02531 z M 117.91374,-305.02531 C 129.71738,-305.02533 139.26324,-295.47944 139.26324,-283.6758 C 139.26324,-271.87216 129.71738,-262.28508 117.91374,-262.28508 C 106.1101,-262.28507 96.523021,-271.87216 96.523021,-283.6758 C 96.523021,-295.47944 106.1101,-305.02531 117.91374,-305.02531 z M 103.2216,-333.14394 L 103.2216,-333.14394 z M 103.2216,-333.14394 C 103.11577,-333.93673 102.96963,-334.55679 102.80176,-335.21316 C 101.69663,-339.53416 100.2179,-342.16153 97.043938,-345.3793 C 93.958208,-348.50762 90.488134,-350.42644 86.42796,-351.28706 C 82.4419,-352.13197 45.472822,-352.13422 41.474993,-351.28706 C 33.885682,-349.67886 27.380491,-343.34759 25.371094,-335.633 C 25.286417,-335.3079 25.200722,-334.40363 25.131185,-333.2339 L 103.2216,-333.14394 z M 64.176391,-389.01277 C 58.091423,-389.00227 52.013792,-385.83757 48.882186,-379.47638 C 47.628229,-376.92924 47.532697,-376.52293 47.532697,-372.24912 C 47.532697,-368.02543 47.619523,-367.53023 48.822209,-364.99187 C 50.995125,-360.40581 54.081354,-357.67937 59.048334,-355.90531 C 60.598733,-355.35157 62.040853,-355.17797 64.86613,-355.27555 C 68.233081,-355.39187 68.925861,-355.58211 71.703539,-356.95492 C 75.281118,-358.72306 77.90719,-361.35074 79.680517,-364.96188 C 80.736152,-367.11156 80.820083,-367.68829 80.820085,-372.0392 C 80.820081,-376.56329 80.765213,-376.87662 79.470596,-379.50637 C 76.3443,-385.85678 70.261355,-389.02327 64.176391,-389.01277 z",
fillColor: '#2563eb',
fillOpacity: 1,
anchor: new box.window.google.maps.Point(12, -290),
strokeWeight: 0,
scale: .1,
rotation: 0
},
clickable: true
});
vehicleMarkers[vehicleId].addListener('click', () => {
window.location.href = `/model/RBWCkwGkZqqfh6Dv3gMf/library/prototype/ZZ5wU5IDDPN6hDURdZrd/view/run?vehicleId=${vehicleId}`
})
}
});
// Every 5 seconds, fetch the new coordinates and update the vehicle markers
setInterval(async () => {
const response = await fetch("https://fleetsim.onrender.com/vehicle/all/coordinates")
const vehicleCoordinates = await response.json();
Object.keys(vehicleCoordinates).forEach(vehicleId => {
const coordinates = vehicleCoordinates[vehicleId];
vehicleMarkers[vehicleId].setPosition({ lat: coordinates.latitude, lng: coordinates.longitude });
})
}, 5000);
// Create an object to store the markers by chargestationId
const chargestationMarkers = {}
// Fetch chargestation coordinates and add markers to map
fetch('https://fleetsim.onrender.com/chargestation/all/coordinates')
.then(response => response.json())
.then(chargestationCoordinates => {
// For each vehicle, create a marker on the map
for (let chargestationId in chargestationCoordinates) {
let coordinates = chargestationCoordinates[chargestationId];
// Store market in markers object
chargestationMarkers[chargestationId] = new box.window.google.maps.Marker({
position: { lat: coordinates.latitude, lng: coordinates.longitude },
map: map,
clickable: true
});
chargestationMarkers[chargestationId].addListener('click', () => {
window.location.href = `/model/JUczdpLduBR24kMeMpyC/library/prototype/TX73uJZmwGVy3a4M3jaY/view/run?chargestationId=${chargestationId}`
})
}
});
// Every 5 seconds, fetch the new coordinates and update the chargestation markers
setInterval(async () => {
const response = await fetch("https://fleetsim.onrender.com/chargestation/all/coordinates")
const chargestationCoordinates = await response.json();
Object.keys(chargestationCoordinates).forEach(chargestationId => {
const coordinates = chargestationCoordinates[chargestationId];
chargestationMarkers[chargestationId].setPosition({ lat: coordinates.latitude, lng: coordinates.longitude });
})
}, 5000);
})
})
////////// End Maps For Dev //////
}
export default plugin