コンテンツにスキップ

Scene

ここでは、 Mapray Cloud で作成した Scene を表示する例を示します。 Mapray Cloud の Scene は、複数の Dataset をまとめて管理し、表示するための枠組みです。 これにより、さまざまな Dataset が一つの Scene として表示できます。

Scene の作成

詳細は Mapray Cloud のドキュメント を参照してください。

サンプルコード

CloudApiV2 の getSceneAsResource メソッドに、表示したい シーン ID を指定することで、Mapray Cloud からリソースを取得できます。 このリソースを SceneLoader のコンストラクタに指定して、 loader を作成し loader.load() を呼び出すことで、作成した Scene が表示されます。

 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
<!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>
</html>

<script>
    async function main() {
        // Set up your apikey, which can be created in Mapray Cloud.
        const apikey = "<YOUR_MAPRAY_API_KEY>";

        // The StandardUIViewer in the ui package includes mouse-based camera manipulation.
        const uiviewer = new maprayui.StandardUIViewer( "mapray-container", apikey);

        // Wait for the initialization process to complete.
        await uiviewer.viewer.init_promise;

        const maprayApi = new mapray.cloud.CloudApiV2({
            tokenType: mapray.cloud.CloudApi.TokenType.API_KEY,
            token: apikey
        });

        const datasetId = "5117624279105536";
        const resource = maprayApi.getSceneAsResource( datasetId );

        const loader = new mapray.SceneLoader( uiviewer.viewer.scene, resource );
        await loader.load();

        uiviewer.setCameraPosition({
            longitude: 134.997514,
            latitude: 35.002871,
            height: 250
        });

        uiviewer.setLookAtPosition({
            longitude: 135.001073,
            latitude: 34.997352,
            height: 65
        });
    }

    main();
</script>

Info

このサンプルコードは、<YOUR_MAPRAY_API_KEY>を、あなたのMapray CloudのアカウントのAPI Keyに置き換えるまで、期待通りに動作しません。

Info

datasetIdは、あなたがアップロードしたデータセットのIDに置き換えて下さい。