-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
398 lines (329 loc) · 12.2 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="description" content="Cesiumを使った日野市オープンデータ可視化のサンプルです" />
<meta property="og:image" content="data/hinoshi.png"
/>
<meta property="og:description" content="Cesiumを使った日野市オープンデータ可視化のサンプルです" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>日野市オープンデータ可視化</title>
<link rel="alternate" href="http://hiroshima.archiving.jp/index_en.html" hreflang="en" />
<link rel="SHORTCUT ICON" href="http://shinsai.mapping.jp/favicon.ico">
<style>
@import url(Cesium/Widgets/widgets.css);
</style>
<link rel="stylesheet" type="text/css" media="all" href="./css/style.css" />
<link rel="stylesheet" type="text/css" media="all" href="./css/menubutton.css" />
<script src="js/jquery-2.1.3.min.js"></script>
<script src="js/slidein.js"></script>
<script src="js/slidein2.js"></script>
<script src="Cesium/Cesium.js"></script>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js"></script>
</head>
<body>
<div class="geocode">
<form action="javascript:geocode()" class="textbox" />
<input id="inputtext" class="textbox" type="text" value="" placeholder="地名で検索"/>
</form>
</div>
<div id="svNotAvailable" onclick="fadeInOut(svNotAvailable,0)"></div>
<div id="blackOut">
<img class="loading" src="data/loading.gif">
</div>
<div id="cesiumContainer"></div>
<div id="button" class="general-button">
<div class="button-content">
<span class="icon-font">menu</span>
</div>
</div>
<div id="button2" class="general-button" onclick="help();">
<div class="button-content">
<span class="icon-font">help</span>
</div>
</div>
<div id="button3" class="general-button">
<div class="button-content">
<span class="icon-font">paramater</span>
</div>
</div>
<div id="button4" class="general-button" onclick="streetView();">
<div class="button-content">
<span class="icon-font">car</span>
</div>
</div>
<div id="buttonGeo" class="general-button" onclick="flyToMyLocation();">
<div class="button-content">
<span class="icon-font">geo</span>
</div>
</div>
<div id="slide_menu"></div>
<div id="slide_menu2"></div>
<div id="streetView_wrapper">
<div id="streetView"></div>
<button class="btn" onclick="fadeInOut(streetView_wrapper,0)">×</button>
</div>
<script>
//スワイプによるスクロール禁止
var cesiumDiv = document.getElementById("cesiumContainer");
function preventScroll(event) {
event.preventDefault();
}
cesiumDiv.addEventListener("gesturestart", preventScroll, false);
cesiumDiv.addEventListener("gesturechange", preventScroll, false);
cesiumDiv.addEventListener("gestureend", preventScroll, false);
//各種DIV
var blackOutDiv = document.getElementById("blackOut");
var streetViewWrapper = document.getElementById("streetView_wrapper");
var svNotAvailable = document.getElementById("svNotAvailable");
//SVエラーメッセージレイヤを隠す
$(function() {
$(svNotAvailable).hide();
$('#button4').hide();
});
//視点作成配列
function viewPoints(_label, _lat, _lng, _heading, _pitch, _range) {
this.label = _label;
this.lat = _lat;
this.lng = _lng;
this.heading = _heading;
this.pitch = _pitch;
this.range = _range;
}
var viewPointsArray=[];
viewPointsArray[0]=new viewPoints("首都大",35.661,139.3657347,0,-45,1000);
viewPointsArray[1]=new viewPoints("日野市",35.654,139.394,0,-89,15000);
viewPointsArray[2]=new viewPoints("初期視点",35.654,139.394,0,-35,5000);
//視点メニュー作成
var viewPointChangeMenu = document.getElementById('slide_menu');
var dropDownList = "";
for (var i=0; i<viewPointsArray.length; i++) {
dropDownList = dropDownList + '<li><a href="#" onclick = "changeViewPoint(' + i + ',' + '3.0);return false;">' + viewPointsArray[i].label + '</a></li>';
}
var viewPointChangeMenuHtml = '<ul class="viewpoint">' + dropDownList + '</ul>';
viewPointChangeMenu.innerHTML = viewPointChangeMenuHtml;
//KML配列作成
function kmlData(_label, _url) {
this.label = _label;
this.url = _url;
}
var kmlDataArray=[];
kmlDataArray[0]=new kmlData("避難所",'data/kml/hinanjo.kml');
kmlDataArray[1]=new kmlData("避難場所",'data/kml/hinanbasyo.kml');
//オーバレイ配列を用意
var overlayDataArray=[];
var openStreetMap = [];
//ビューア初期化
var viewer = new Cesium.Viewer('cesiumContainer',{
imageryProvider : new Cesium.ArcGisMapServerImageryProvider({
url : '//server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
enablePickFeatures : false
}),
navigationHelpButton : false,
navigationInstructionsInitiallyVisible : false,
geocoder:false,
timeline: false,
animation: false,
sceneModePicker:false,
baseLayerPicker:false,
scene3DOnly : true
});
//地形メッシュを設定
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
url : '//assets.agi.com/stk-terrain/world',
requestWaterMask : true,
requestVertexNormals : true
});
viewer.terrainProvider = cesiumTerrainProviderMeshes;
//地形を強調する際は値を変更
viewer.terrainExaggeration = 1.0;
//フォグ
var fog = new Cesium.Fog();
fog.density = 0.0005;
fog.screenSpaceErrorFactor = 100.0;
//起動シークエンス
$(function() {
$('.cesium-widget-credits').css('display', 'none');
});
fadeInOut(blackOutDiv,0);
var layers = viewer.scene.imageryLayers;
setTimeout('groundZero()',1000);
function groundZero(){
changeViewPoint(1,3);
openStreetMapLayer();
setTimeout('landing()',4000);
}
function landing(){
changeViewPoint(2,3);
setTimeout('fadeInOut(blackOutDiv,1)',3000);
setTimeout('loadKml()',3000);
}
//KMLロード関数
function loadKml(){
var i = 0;
var load = setInterval(function(){
var promise = Cesium.KmlDataSource.load(kmlDataArray[i].url);
promise.then(function(dataSource) {
viewer.dataSources.add(dataSource);
}).otherwise(function(error){
alert('KMLデータが読み込めません');
});
i++;
if (i == kmlDataArray.length){
clearInterval(load);
setClickEvent();
setTimeout('fadeInOut(blackOutDiv,0)',3000);
}
}, 200);
}
//地図オーバレイ関数
function openStreetMapLayer (){
openStreetMap = layers.addImageryProvider(new Cesium.createOpenStreetMapImageryProvider());
//OSMの明度を下げる
openStreetMap.brightness = 0.7;
//OSMの不透明度をデフォルト0に
openStreetMap.alpha = 0;
//オーバーレイ配列作成関数
function overlayData(_label, _value, _overlayObj, _id) {
this.label = _label;
this.value = _value;
this.overlayObj = _overlayObj;
this.id = _id;
}
overlayDataArray[0]=new overlayData("現在の地図",0,openStreetMap,"range01");
var overlayList = "";
for (var i=0; i<overlayDataArray.length; i++) {
overlayList = overlayList + '<p class="slide_label">' + overlayDataArray[i].label + '</p><input id="' + overlayDataArray[i].id + '" type="range" min="0" max="33" value="' + overlayDataArray[i].value * 0.33 + '" step="1" oninput="transParent(' + i + ');"/>';
}
var overlayListMenu = document.getElementById('slide_menu2');
overlayListMenu.innerHTML = overlayList;
}
//OSM透明度を変更する関数
function transParent (layer){
var id = overlayDataArray[layer].id;
var overlay = overlayDataArray[layer].overlayObj;
var slider = document.getElementById(id);
if (slider.value == 0){
overlay.show = false;
} else{
overlay.show = true;
overlay.alpha = slider.value * 0.03;
}
}
//視点移動する関数
function changeViewPoint(num, delay) {
var newLat = viewPointsArray[num].lat;
var newLng = viewPointsArray[num].lng;
var newHeading = Cesium.Math.toRadians(viewPointsArray[num].heading);
var newPitch = Cesium.Math.toRadians(viewPointsArray[num].pitch);
var newRange = viewPointsArray[num].range;
var center = Cesium.Cartesian3.fromDegrees(newLng, newLat);
var boundingSphere = new Cesium.BoundingSphere(center, newRange);
var headingPitchRange = new Cesium.HeadingPitchRange(newHeading, newPitch, newRange);
viewer.camera.constrainedAxis = Cesium.Cartesian3.UNIT_Z;
viewer.camera.flyToBoundingSphere(boundingSphere,{
duration : delay,
offset : headingPitchRange,
easingFunction: Cesium.EasingFunction.CUBIC_IN_OUT
});
}
//ジオコード関数
function geocode() {
var geocoder = new google.maps.Geocoder();
var input = document.getElementById('inputtext').value;
geocoder.geocode(
{ address:input },
function( results, status ) {
if( status == google.maps.GeocoderStatus.OK ) {
var viewportObj = results[0].geometry.viewport;
var southNorth = viewportObj[Object.keys(viewportObj)[0]];
var westEast = viewportObj[Object.keys(viewportObj)[1]];
var south = southNorth[Object.keys(southNorth)[0]];
var north = southNorth[Object.keys(southNorth)[1]];
var west = westEast[Object.keys(westEast)[0]];
var east = westEast[Object.keys(westEast)[1]];
var rectangle = Cesium.Rectangle.fromDegrees(west, south, east, north);
viewer.camera.flyTo({
destination : rectangle,
easingFunction: Cesium.EasingFunction.CUBIC_IN_OUT
});
} else {
alert('見つかりません');
}
}
);
}
//ダブルクリックでストビューを表示する関数
function setClickEvent(){
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(click) {
var pickedObject = viewer.scene.pick(click.position);
if (Cesium.defined(pickedObject) && (pickedObject != "")) {
var position = pickedObject.primitive._position;
console.log (position);
var cart = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
var latlng = new google.maps.LatLng(Cesium.Math.toDegrees(cart.latitude), Cesium.Math.toDegrees(cart.longitude));
var sv = new google.maps.StreetViewService();
sv.getPanoramaByLocation(latlng, 50,
function (data, status) {
//ストリートビュー未対応エリアの場合
if (status != google.maps.StreetViewStatus.OK) {
svNotAvailable.innerHTML = '<p class="errorMessage">この場所のストリートビューは利用できません</p>';
fadeInOut(svNotAvailable,1);
setTimeout('fadeInOut(svNotAvailable,0)',1500);
}
else{
streetViewWrapper.style.display = "block";
fadeInOut(streetViewWrapper,1);
var svp = new google.maps.StreetViewPanorama(
document.getElementById("streetView"),{
position : latlng
});
}
var newHeading = Cesium.Math.toRadians(0);
var newPitch = Cesium.Math.toRadians(-85);
var newRange = 500;
var center = position;
var boundingSphere = new Cesium.BoundingSphere(center, 1000);
var headingPitchRange = new Cesium.HeadingPitchRange(newHeading, newPitch, newRange);
viewer.camera.flyToBoundingSphere(boundingSphere,{
duration : 1,
offset : headingPitchRange,
easingFunction: Cesium.EasingFunction.CUBIC_IN_OUT
});
});
}
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
}
//現在地へ移動する関数
function flyToMyLocation() {
function fly(position) {
viewer.camera.flyTo({
destination : Cesium.Cartesian3.fromDegrees(position.coords.longitude, position.coords.latitude, 750.0),
easingFunction: Cesium.EasingFunction.CUBIC_IN_OUT
});
}
navigator.geolocation.getCurrentPosition(fly);
}
//ヘルプ
function help(){
window.open('http://labo.wtnv.jp/');
}
//DIVのフェードイン・アウト 関数
function fadeInOut(layer,param) {
if (param == 0){
$(function() {
$(layer).fadeOut("slow");
});
viewer.trackedEntity = undefined;
} else {
$(function() {
$(layer).fadeIn("slow");
});
}
}
</script>
</body>
</html>