This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
274 lines (228 loc) · 8.27 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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css">
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src='https://unpkg.com/[email protected]/dist/mapillary.min.js'></script>
<link href='https://unpkg.com/[email protected]/dist/mapillary.min.css' rel='stylesheet' />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<style>
.relative {
position: relative;
}
.absolute {
position: absolute;
left: 0px;
top: 0px;
}
#mly {
width: 100%;
height: 480px;
}
#mapcontainer {
width: 100%;
height: 480px;
}
</style>
</head>
<body>
<nav class="navbar navbar-dark bg-primary mb-2">
<h1 class="navbar-brand">Measure height of the object</h1>
<form class="form-inline text-light">
Mapillary 360 URL:
<div class="input-group">
<input type="url" class="form-control" id="mapillaryurl" value="https://www.mapillary.com/app/?lat=37.48691666666667&lng=139.92978333333338&z=17&pKey=JQJrg5HaJ4Q0QvYCP-L9GQ&focus=photo&x=0.7402020403448308&y=0.5212907903987006&zoom=0">
<div class="input-group-append">
<button type="button" class="btn btn-secondary" value="Open" onclick="loadMapillary()">
Open
</button>
</div>
</div>
</form>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-lg-4 bg-white">
<div id="photo">
<p>(1) Measure Angle</p>
<div id='mly'></div>
</div>
</div>
<div class="col-lg-4 bg-white">
<div id="map">
<p>(2) Measure Distance</p>
<div id='mapcontainer'></div>
</div>
</div>
<div class="col-lg-4 bg-white">
<div id="calc">
<p>(3) Get Height</p>
<p>
<form name="calcform" onsubmit="return false"
oninput="result.value = Number(distance.value) * Math.tan(Number(theta.value)*Math.PI/180);" />
<ul>
<li>Distance: <input type="number" name="distance" id="distance"> m
<li>Angle: <input type="number" name="theta" id="theta"> deg
<li class="alert-success font-weight-bold"><code class="">Height[m] = Distance *
tan(Angle*π/180)<span name="result_text"><br /> =
<u><output name="result"></output> m</u></span></code>
</ul>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script src="leaflet.rotatedMarker.js"></script>
<script>
const client_id = 'NEh3V0ZjaE1fT1Nkdk9jMnJlSGNQQTo1NzRiNDEwZmM3MzZhNmIw';
let mly;
let map;
let camera_marker;
let target_marker;
let distance_line;
init();
function init(){
initPhoto();
initMap();
drawGrid();
}
function initPhoto(){
mly = new Mapillary.Viewer(
'mly',
client_id,
// photo id
null,
{
component: {
cover: false,
tag: true,
},
});
mly.on(Mapillary.Viewer.nodechanged, function(node) {
console.log("Mapillary.js node changed:", node.key);
const latLon = node.latLon;
map.setView(latLon, 18);
camera_marker.setLatLng(latLon).addTo(map);
});
mly.on(Mapillary.Viewer.povchanged, function(node) {
mly.getPointOfView().then((pov) => {
//camera_marker.addTo(map)
camera_marker.setRotationAngle(pov.bearing);
});
});
var tagComponent = mly.getComponent("tag");
tagComponent.changeMode(Mapillary.TagComponent.TagMode.CreateRect);
var createdIndex = 0;
tagComponent.on(Mapillary.TagComponent.TagComponent.geometrycreated, function(geometry) {
function updateAngle(tag, geometry){
const rect = tag.geometry._rect;
const dy = Math.abs(rect[1]-rect[3]);
const angle = dy*180;
tag.setOptions({text: `${Math.round(angle)} deg`});
document.getElementById("theta").value = angle;
document.calcform.oninput();
}
var id = "id-" + createdIndex++;
var tag = new Mapillary.TagComponent.OutlineTag(id, geometry, { editable: true, text: "", lineColor: 0x0000ff, textColor: 0x0000ff});
updateAngle(tag, geometry);
var onTagGeometryChanged = function(tag) {
updateAngle(tag, geometry);
console.log(tag.id, tag.geometry._rect);
};
tag.on(Mapillary.TagComponent.OutlineTag.geometrychanged, onTagGeometryChanged);
tagComponent.add([tag]);
});
}
function initMap(){
//地図を表示するdiv要素のidを設定
map = L.map('mapcontainer');
//地図の中心とズームレベルを指定
map.setView([0, 0], 1);
//表示するタイルレイヤのURLとAttributionコントロールの記述を設定して、地図に追加する
const osmLayer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: "(C)<a href='https://www.openstreetmap.org/copyright' target='_blank'>OpenStreetMap contributors</a>",
maxZoom: 21,
maxNativeZoom: 19,
minZoom: 1,
//maxBounds: [[35.47, 139.62], [35.45, 139.64]],
}).addTo(map);
map.options.singleClickTimeout = 250;
map.on('click',function ( e ) {
target_marker.setLatLng(e.latlng).addTo(map);
} );
const sampleIcon = L.icon({
iconUrl: 'icon.png',
iconRetinaUrl: 'icon.png',
iconSize: [50, 50],
iconAnchor: [25, 25],
popupAnchor: [25, -25],
className: "marker_icon",
});
camera_marker = L.marker([0,0], { icon: sampleIcon, rotationAngle: 45, draggable: true });
camera_marker.on('move',function(event){
showDistance();
});
target_marker = L.marker([0,0], { draggable: true });
target_marker.on('move',function(event){
showDistance();
});
distance_line = L.polyline([]);
}
function showDistance(){
const [distance, phi] = getDistancePhi(camera_marker.getLatLng(), target_marker.getLatLng());
if (distance < 1000) {
document.getElementById("distance").value = distance;
document.calcform.oninput();
distance_line.setLatLngs([camera_marker.getLatLng(), target_marker.getLatLng()]).addTo(map);
}
else {};
}
var loadMapillary = function(){
var murl = document.getElementById("mapillaryurl").value;
const [,lat,lon,mid] = murl.match(/lat=(-?\d[0-9.]*).*&lng=(-?\d[0-9.]*).*pKey=([^&]*)&/);
mly.moveToKey(mid);
}
function drawGrid(){
let tagComponent = mly.getComponent("tag");
let tag_number = 0;
for (let angle = -80; angle < 90; angle += 5){
const div_number = 10;
for (let i = 0; i < div_number; i++){
let rect = [i/div_number, (-angle+90)/180, (i+1)/div_number, (-angle+90)/180];
let rectGeometry = new Mapillary.TagComponent.RectGeometry(rect);
let rectTag = new Mapillary.TagComponent.OutlineTag('tag-' + tag_number, rectGeometry, { lineWidth: 2, text: angle});
tagComponent.add([rectTag]);
tag_number++;
}
}
/*
var rect = [0.68, 0.51, 0.72, 0.56];
var rectGeometry = new Mapillary.TagComponent.RectGeometry(rect);
var rectTag = new Mapillary.TagComponent.OutlineTag('rectTag', rectGeometry, { text: "stop sign"});
tagComponent.add([rectTag]);
*/
window.addEventListener("resize", function() { mly.resize(); });
}
const R = 6378100;
function getDistancePhi(base, target){
const x1 = rad(base.lng);
const y1 = rad(base.lat);
const x2 = rad(target.lng);
const y2 = rad(target.lat);
const dx = x2 - x1;
const distance = R * Math.acos(Math.sin(y1)*Math.sin(y2) + Math.cos(y1)*Math.cos(y2)*Math.cos(dx));
const phi = 90 - deg(Math.atan2( Math.cos(y1)*Math.tan(y2) - Math.sin(y1)*Math.cos(dx), Math.sin(dx)));
return [distance, phi];
}
function rad(deg){
return deg/180*Math.PI;
}
function deg(rad){
return rad/Math.PI*180;
}
</script>
</body>
</html>