-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
108 lines (85 loc) · 3.14 KB
/
index.js
File metadata and controls
108 lines (85 loc) · 3.14 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
/*
* Copyright (C) 2017-2020 HERE Europe B.V.
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
//cd harp.gl-example && npm start and connect to http://localhost:8080
import { GeoCoordinates } from "@here/harp-geoutils";
import { View } from "./View";
import { IFCLoader } from 'three/examples/jsm/loaders/IFCLoader';
import { MultiStageTimer } from "@here/harp-mapview";
const app = new View({
canvas: document.getElementById("map")
});
const mapView = app.mapView;
// make map full-screen
mapView.resize(window.innerWidth, window.innerHeight);
// react on resize events from the browser.
window.addEventListener("resize", () => {
mapView.resize(window.innerWidth, window.innerHeight);
});
// center the camera to Manchester
mapView.lookAt({ target: new GeoCoordinates(53.545, -2.128), zoomLevel: 17, tilt: 40 });
// make sure the map is rendered
mapView.update();
// Setup of IFC loader and import custom model with click event
const ifcLoader = new IFCLoader();
window.addEventListener("dblclick", (evt) => {
ifcLoader.load("Duplex_A_20110907.ifc", (ifcmodel) => {
ifcmodel.traverse((child) => (child.renderOrder = 10000));
ifcmodel.renderOrder = 10000;
ifcmodel.rotateX(Math.PI / 2);
ifcmodel.rotateY(Math.PI / 1.7);
//Assign the coordinates to the IFC
const geoPosition = mapView.getGeoCoordinatesAt(evt.pageX, evt.pageY);
ifcmodel.anchor = geoPosition;
mapView.mapAnchors.add(ifcmodel);
});
});
//--------------------- Domestic Energy Performance Certificates API ----------------------
var myHeaders = new Headers();
myHeaders.append("Authorization", "Your-Token");
myHeaders.append('Accept', 'application/json');
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
// get data filtered by local authority
fetch("https://epc.opendatacommunities.org/api/v1/domestic/search?local-authority=E08000003", requestOptions)
.then(response => response.text())
.then(function(result) {
console.log(result);
const data = JSON.parse(result);
// data.rows.forEach(function(element) {
// console.log(element["energy-consumption-current"]);
// let energy = element["energy-consumption-current"];
// document.getElementById("energy-consumption").innerHTML = "Current energy consumption: " + energy;
// });
let energy = data.rows[0]["energy-consumption-current"];
document.getElementById("energy-consumption").innerHTML = "Current energy consumption: " + energy;
console.log(energy);
})
.catch(error => console.log('error', error));
//Pop-up window
const modal = document.querySelector('#my-modal');
const modalBtn = document.querySelector('#modal-btn');
const closeBtn = document.querySelector('.close');
// Events
modalBtn.addEventListener('click', openModal);
closeBtn.addEventListener('click', closeModal);
window.addEventListener('click', outsideClick);
// Open
function openModal() {
modal.style.display = 'block';
}
// Close
function closeModal() {
modal.style.display = 'none';
}
// Close If Outside Click
function outsideClick(e) {
if (e.target == modal) {
modal.style.display = 'none';
}
}