Mapray Cloudのデータを表示する - 3D Dataset -
Mapray Cloudに保存されているデータを表示してみます。
第1章でアップロードしたデータを表示してみます。
まずは、3Dデータです。
3DデータはMapray Cloudでは3DDatasetと呼ばれます。
Mapray Cloud APIの利用
Mapray Cloudに容易にアクセスするためのAPI、mapray.cloud.CloudApiV2
を用意しています。APIリファレンスこれを使ってMapray
Cloudにアクセスします。
mapray.cloud.CloudApiV2
はAccessTokenとAPIKeyが使えますが、ハンズオンではシンプルなAPIKeyを利用します。
Warning
mapray.cloud.CloudApiV1
は互換性維持のために残されているので、今から使うのであればV2を推奨します
DataのID
Mapray Cloudに保存されているデータは全てIDで管理されています。
例えば、3D Datasetの場合は、Mapray Cloudの3D Dataset Dashboardで確認することができます。

以下のプログラムの
をご自分の表示したい3D DatasetのIDで置き換えます。
ここでは、Mapray Cloudのシーンで学習したDUCKのデータを表示してみましょう。
Mapray CloudでDUCKのモデルのIDを調べて下さい。
3D Datasetのダウンロードと表示
mapray.cloud.CloudApiV2.get3DDatasetAsResource
を使うと、ID番号で自動的にmapray.Resource
としてデータをダウンロードします。
実際はデータはmapray.Dataset3DResource
型で取得されており、mapray.Resource
で抽象化されています。
これをmapray.SceneLoader
を使って、Sceneとして読み込みます。
Scene
Mapray Cloudのシーンで学習したように、MaprayはSceneという概念でデジタルツインデータを扱います。
mapray.SceneLoader
が、まさにこのSceneデータをロードする関数です。
この後で順次説明しますが、maprayJSはSceneとしてデータをロードするAPIと、個別のデータを呼び出すAPIの2種類があります。
Sceneで扱えるデータと個別データを呼び出すAPIは、データタイプで違いがあります。
Sceneで扱えるデータ
Entityで定義されているデータです。3D DatasetはModelEntity
ですので、Sceneで扱うことができます。
Note
現在のSceneでは扱えるデータが限定的になっています。将来はSceneで個別のデータAPIが用意されているデータも統一的に扱えるようになります。
個別のデータAPI
個別のデータAPIが用意されているのは、Entity以外のすべてのデータです。
- PointCloud
- Building
- 2D Dataset(GeoJSON)
- Vector Tiles
- Image Layer
- DEM Layer
SceneLoader
mapray.SceneLoader
でデータがロードされると、onEntity
コールバックでイベントを取得できます。
そこで、mapray.addEntity
でEntityをシーンに追加します。
これで、データがメモリ上にロードされます。
その前に、Mapray CloudのシーンでもDUCKのデフォルトの高さが海抜0mでした。
そのため、東京タワーの地面の下に埋まっています。
ここで、以下のように、東京タワーの上部にDUCKを移動して、さらにスケールを変更します。
entity.setPosition( new mapray.GeoPoint( 139.7454316, 35.658584, 351 ) );
entity.setScale( [ 20, 20, 20 ] );
その後、データの位置にカメラを移動したいため、mapray.Entity.getBounds()
でデータ位置を取得して、
mapray.StandardUIViewer.startFlyCamera
を用いて、カメラを移動しています。
これで、シーンで編集した状態がmaprayJSのAPIで再現できました。
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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://resource.mapray.com/mapray-js/v0.9.6/mapray.min.js"></script>
<script src="https://resource.mapray.com/ui/v0.9.6/maprayui.min.js"></script>
<link rel="stylesheet" href="https://resource.mapray.com/styles/v1/mapray.css">
<style>
html, body, div#mapray-container { margin: 0; padding: 0; height: 100%; }
</style>
</head>
<body>
<div id="mapray-container"></div>
</body>
<script>
// Set up your apikey, which can be created in Mapray Cloud.
const apikey = "<YOUR_MAPRAY_API_KEY>";
const BaseMapType = {
PHOTO: 'photo',
STANDARD: 'standard'
};
const TimeType = {
DAYTIME: 'daytime',
NIGHTTIME: 'nighttime'
};
const CloudData = {
threeD: "<YOUR_3D_DATASET_ID>" // 3D DatasetのID
}
class CustomViewer extends maprayui.StandardUIViewer {
constructor(container, apikey, options = {}) {
super(container, apikey, options);
this.elapsedTime = 0; // Pin作成時間計算用
this.latValue = 0;
this.totalTime = 0; // 起動からの累積時間
this._render_mode = mapray.Viewer.RenderMode.SURFACE; // 描画モードをセット
this._base_map_url = BaseMapType.PHOTO; // 現在のベースマップ
this._time_type = TimeType.DAYTIME; // 現在の時間タイプ
this._maprayApi = new mapray.cloud.CloudApiV2({
tokenType: mapray.cloud.CloudApi.TokenType.API_KEY,
token: apikey
});
// Imageレイヤ=を追加
this.addLayer( {
type: mapray.Layer.Type.IMAGE,
image_provider: new mapray.StandardImageProvider({ url: "https://opentiles.mapray.com/xyz/night-satellite/", min_level: 0, max_level: 8 }),
opacity: 1.0,
draw_type: mapray.ImageLayer.DrawType.NIGHT,
} );
}
/** @override */
onUpdateFrame( delta_time ) {
super.onUpdateFrame( delta_time );
this.totalTime += delta_time;
this.elapsedTime += delta_time;
if ( this.elapsedTime > 3.0 && this.totalTime < 15.0 ) {
const pin = new mapray.PinEntity( this.viewer.scene );
pin.altitude_mode = mapray.AltitudeMode.CLAMP;
pin.addPin( new mapray.GeoPoint( 138.71934, 35.36 + this.latValue, 3780 ), { size: 15 } );
pin.setBGColor([1.0, 0.5, 0.0]);
this.addEntity( pin );
this.elapsedTime = 0;
this.latValue += 0.005;
}
const viewer = this.viewer;
if ( viewer.render_mode !== this._render_mode ) {
viewer.render_mode = this._render_mode;
}
if ( this._time_type === TimeType.NIGHTTIME ) {
const sun_xy_degree = -45;
const sun_z_degree = 36.0;
uiviewer.viewer.sun.setSunDirection( [ Math.cos(Math.PI/180.0 * sun_xy_degree), Math.sin(Math.PI/180.0 * sun_xy_degree), Math.sin(Math.PI/180.0 * sun_z_degree) ] );
const moon_xy_degree = 135;
const moon_z_degree = 36.0;
uiviewer.viewer.moon.setMoonDirection( [ Math.cos(Math.PI/180.0 * moon_xy_degree), Math.sin(Math.PI/180.0 * moon_xy_degree), Math.sin(Math.PI/180.0 * moon_z_degree) ] );
uiviewer.viewer.moonVisualizer.setRadius(5);
} else {
const sun_xy_degree = 135
const sun_z_degree = 36.0;
uiviewer.viewer.sun.setSunDirection( [ Math.cos(Math.PI/180.0 * sun_xy_degree), Math.sin(Math.PI/180.0 * sun_xy_degree), Math.sin(Math.PI/180.0 * sun_z_degree) ] );
const moon_xy_degree = -45;
const moon_z_degree = 36.0;
uiviewer.viewer.moon.setMoonDirection( [ Math.cos(Math.PI/180.0 * moon_xy_degree), Math.sin(Math.PI/180.0 * moon_xy_degree), Math.sin(Math.PI/180.0 * moon_z_degree) ] );
uiviewer.viewer.moonVisualizer.setRadius(5);
}
}
/** @override */
onKeyDown( event ) {
switch ( event.key ) {
case "m": case "M": {
this._render_mode = (
this._render_mode === mapray.Viewer.RenderMode.SURFACE ?
mapray.Viewer.RenderMode.WIREFRAME :
mapray.Viewer.RenderMode.SURFACE
);
} break;
case "s": case "S": {
this._base_map_url = (
this._base_map_url === BaseMapType.PHOTO ?
BaseMapType.STANDARD :
BaseMapType.PHOTO
);
let image_provider;
if ( this._base_map_url === BaseMapType.PHOTO ) {
image_provider = new mapray.StandardImageProvider( {
url: "https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/",
format: ".jpg",
min_level: 0,
max_level: 18
} );
} else {
image_provider = new mapray.StandardImageProvider( {
url: "https://cyberjapandata.gsi.go.jp/xyz/std/",
format: ".png",
min_level: 2,
max_level: 18
} );
}
this.viewer.setImageProvider( image_provider, true );
} break;
case "t": case "T": {
this._time_type = (
this._time_type === TimeType.DAYTIME ?
TimeType.NIGHTTIME :
TimeType.DAYTIME
);
}
break;
case "d": case "D": {
this.get3DDataset();
} break;
default: {
super.onKeyDown( event );
}
}
}
async get3DDataset() {
const datasetId = CloudData.threeD;
const resource = this._maprayApi.get3DDatasetAsResource( datasetId );
const loader = new mapray.SceneLoader( this.viewer.scene, resource, {
onEntity: ( loader, entity, feature ) => {
// Since the resource is a 3D dataset, the entity will be an instance of the ModelEntity class.
// When onEntity is specified, you need to manually add the entity.
entity.setPosition( new mapray.GeoPoint( 139.7454316, 35.658584, 351 ) );
entity.setScale( [ 20, 20, 20 ] );
this.addEntity( entity );
// Move the camera to the model's location.
const bounds = entity.getBounds();
const length = bounds.getLatitudeDistance();
this.startFlyCamera({
time: 3.0,
iscs_end: bounds.getCenter(),
end_altitude: 300,
end_from_lookat: 500
});
}
});
await loader.load();
}
}
const uiviewer = new CustomViewer( "mapray-container", apikey, {
atmosphere: new mapray.Atmosphere(),
sun_visualizer: new mapray.SunVisualizer( 32 ),
moon_visualizer: new mapray.MoonVisualizer( 'https://resource.mapray.com/assets/images/moon.jpg' ),
star_visualizer: new mapray.StarVisualizer( 'https://resource.mapray.com/assets/data/star75.json', 'https://resource.mapray.com/assets/images/starmap_512n2.jpg' ),
});
uiviewer.viewer.atmosphere.setRayleigh(0.01);
uiviewer.viewer.atmosphere.setMie(0.001);
uiviewer.setCameraPosition({
longitude: 142.0,
latitude: 20.0,
height: 2500000
});
uiviewer.setLookAtPosition({
longitude: 138.729802,
latitude: 35.363965,
height: 3000
});
</script>
</html>
|