-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenergyMapper.js
154 lines (113 loc) · 4.94 KB
/
energyMapper.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
var mainGoogleMap;
function myMap() {
// let centerLatLong = new google.maps.LatLng(61.1181, -149.756667); // Defualt center hardcoded to Mitchell House
let centerLatLong = new google.maps.LatLng(61.166492, -149.872976)
let mapProp= {
center:centerLatLong,
zoom:10,
};
let map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
mainGoogleMap = map;
// let myCity = new google.maps.Circle({
// center:centerLatLong,
// radius:2000,
// strokeColor:"#0000FF",
// strokeOpacity:0.8,
// strokeWeight:2,
// fillColor:"#0000FF",
// fillOpacity:0.4
// });
// myCity.setMap(map);
PlotSensorData();
}
function BuildingEnergyMapPoint (buildingId, gMapMarker, buildingData) {
this.buildingId = buildingId;
this.gMapMarker = gMapMarker; // google.maps.Marker
this.buildingData = buildingData;
}
let allMapPoints; // array of BuildingEnergyMapPoint
async function PlotSensorData() {
console.log("Testing parsing data...");
allMapPoints = new Array();
try {
let data = await getAllSensors()
// filter for just gas meters
data = data.filter(sensor => /.+_\d\d\d\d\d\d\d\d$/.test(sensor.sensor_id))
let map = this.mainGoogleMap;
for (let dataCount = 0; dataCount < data.length; dataCount++) {
// console.log("Data is: " + data[dataCount].buildings[0].name);
let sensorData = data[dataCount];
let buildingsData = sensorData.buildings;
for (let buildingCount = 0; buildingCount < buildingsData.length; buildingsData++) {
let building = buildingsData[buildingCount];
let buildingId = building.bldg_id;
let newMapPointObj = null;
for (let i = 0; i < allMapPoints.length; i++) {
if (allMapPoints[i].buildingId == buildingId) {
newMapPointObj = allMapPoints[i];
}
}
if (newMapPointObj == null) {
let buildingPos = new google.maps.LatLng(building.latitude, building.longitude);
// console.log("Data is: " + building.name + " id: " + building.bldg_id + " lat: " + building.latitude + " long: " + building.longitude);
let sensorRadiusCircle = new google.maps.Circle({
center:buildingPos,
radius:500,
strokeColor:"#0000FF",
strokeOpacity:0.5,
strokeWeight:2,
fillColor:"#0000FF",
fillOpacity:0.2,
map:map
});
sensorRadiusCircle.setMap(map);
let marker = new google.maps.Marker(
{
position: buildingPos
// ,animation:google.maps.Animation.BOUNCE
}
);
marker.setMap(mainGoogleMap);
newMapPointObj = new BuildingEnergyMapPoint(buildingId, marker, building);
allMapPoints.push(newMapPointObj);
google.maps.event.addListener(marker, 'click', function() {
console.log("Did click building id: " + newMapPointObj.buildingData.bldg_id);
let infowindow = new google.maps.InfoWindow({
// content:("<b>" + newMapPointObj.buildingData.name + "</b><br><h2><i>Hi!</i></h2><div style=\"width:400px;height:100px;\"></div>")
content:("<b>" + newMapPointObj.buildingData.name + "</b><br>Sensors: " + newMapPointObj.sensors.length)
});
infowindow.open(map,marker);
// ZoomMapInOnBuildingId(building.bldg_id);
});
}
if (newMapPointObj.sensors == null) {
newMapPointObj.sensors = new Array();
}
newMapPointObj.sensors.push(sensorData);
}
}
}
catch (err) {
console.log(err)
}
}
function ZoomMapInOnBuildingId(buildingId) {
let buildingMapPoint = null;
for (let i = 0; i < allMapPoints.length; i++) {
if (allMapPoints[i].buildingId == buildingId) {
// newMapPointObj = allMapPoints[i];
buildingMapPoint = allMapPoints[i];
}
}
if (buildingMapPoint != null) {
let map = this.mainGoogleMap;
let marker = buildingMapPoint.marker;
var pos = new google.maps.LatLng(buildingMapPoint.buildingData.latitude, buildingMapPoint.buildingData.longitude);
map.setZoom(13);
map.setCenter(pos);
// window.setTimeout(function() {map.setZoom(pos);},3000);
}
else {
console.log("Didn't find a building with id: " + buildingId);
}
}