-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
155 lines (130 loc) · 3.86 KB
/
index.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
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
<!DOCTYPE html>
<html>
<head>
<title>OSM Buildings</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
#map {
width: 100%;
height: 100%;
}
.control {
position: absolute;
left: 0;
z-index: 1000;
}
.control.tilt {
top: 0;
}
.control.rotation {
top: 45px;
}
.control.zoom {
top: 90px;
}
.control.zoom button{
font-weight: normal;
}
.control button {
width: 30px;
height: 30px;
margin: 15px 0 0 15px;
border: 1px solid #999999;
background: #ffffff;
opacity: 0.6;
border-radius: 5px;
box-shadow: 0 0 5px #666666;
font-weight: bold;
text-align: center;
}
.control button:hover {
opacity: 1;
cursor: pointer;
}
</style>
<link rel="stylesheet" href="css/OSMBuildings.css">
<script src="js/OSMBuildings.js"></script>
</head>
<body>
<div id="map"></div>
<div class="control tilt">
<button class="dec">↙</button>
<button class="inc">↗</button>
</div>
<div class="control rotation">
<button class="inc">↶</button>
<button class="dec">↷</button>
</div>
<div class="control zoom">
<button class="dec">-</button>
<button class="inc">+</button>
</div>
<script>
const osmb = new OSMBuildings({
container: 'map',
zoom: 16,
minZoom: 16,
maxZoom: 19,
position: { latitude: 52.52000, longitude: 13.41000 },
state: true, // stores map position/rotation in url
attribution: '© 3D <a href="https://osmbuildings.org/copyright/">OSM Buildings</a>'
});
osmb.addMapTiles(
'https://api.mapbox.com/styles/v1/osmbuildings/cjt9gq35s09051fo7urho3m0f/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1Ijoib3NtYnVpbGRpbmdzIiwiYSI6IjNldU0tNDAifQ.c5EU_3V8b87xO24tuWil0w',
{
attribution: '© Data <a href="https://openstreetmap.org/copyright/">OpenStreetMap</a> · © Map <a href="https://mapbox.com/">Mapbox</a>'
}
);
osmb.addGeoJSONTiles('https://{s}.data.osmbuildings.org/0.2/anonymous/tile/{z}/{x}/{y}.json');
osmb.addOBJ(`${location.protocol}//${location.hostname}/${location.pathname}../data/Fernsehturm.obj`, { latitude:52.52000, longitude:13.41000 }, { id:'Fernsehturm', scale:2, color:'#ff0000', altitude:0, rotation:51 });
//***************************************************************************
// on pointer up
osmb.on('pointerup', e => {
// if none, remove any previous selection and return
if (!e.features) {
osmb.highlight(feature => {});
return;
}
// store id's from seleted items...
const featureIDList = e.features.map(feature => feature.id);
// ...then is is faster: set highlight color for matching features
osmb.highlight(feature => {
if (featureIDList.indexOf(feature.id) > -1) {
return '#ffffff';
}
});
});
//***************************************************************************
const controlButtons = document.querySelectorAll('.control button');
controlButtons.forEach(button => {
button.addEventListener('click', e => {
const parentClassList = button.parentNode.classList;
const direction = button.classList.contains('inc') ? 1 : -1;
let increment, property;
if (parentClassList.contains('tilt')) {
property = 'Tilt';
increment = direction*10;
}
if (parentClassList.contains('rotation')) {
property = 'Rotation';
increment = direction*10;
}
if (parentClassList.contains('zoom')) {
property = 'Zoom';
increment = direction*1;
}
if (property) {
osmb['set'+ property](osmb['get'+ property]()+increment);
}
});
});
</script>
</body>
</html>