コンテンツにスキップ

Switch a raster tile source

Switch a third-party raster source to the map.

switch_raster_tile_source.html
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Switch a raster tile source</title>
        <meta property="og:description" content="Switch a third-party raster source to the map." />
        <script src="./v0.10.1/mapray.min.js"></script>
        <script src="./v0.10.1/maprayui.min.js"></script>
        <link rel="stylesheet" href="./v0.10.1/mapray.css">
        <style>
            body {margin: 0; padding: 0;}
            html, body, div#mapray-container { height: 100%; }
            .map-overlay { 
                font: 12px/20px "Robot", sans-serif;
                position: absolute;
                width: 200px;
                top: 0;
                left: 0;
                padding: 10px;
            }
            .map-overlay .map-overlay-inner {
                background-color: #fff;
                color: #000;
                box-shadow: 0 1px 2px rgba(0,0,0,0.1);
                border-radius: 3px;
                padding: 10px;
                margin-bottom: 10px;
            }
            .map-overlay-inner .select-fieldset {
                display: block;
            }
            .map-overlay-inner fieldset {
                display: flex;
                justify-content: space-between;
                border: none;
            }
            .map-overlay-inner .select-fieldset label {
                display: block;
                margin-bottom: 5px;
            }
            .map-overlay-inner label {
                font-weight: 700;
                margin-right: 10px;
            }
        </style>
    </head>
    <body>
        <div id="mapray-container"></div>
        <div class="map-overlay top">
            <div class="map-overlay-inner">
            <fieldset class="select-fieldset">
                <label for="rasterPreset">Select raster tiles</label>
                <select id="rasterPreset" name="rasterPreset">
                    <option value="std">Standard</option>
                    <option value="pale">Pale</option>
                    <option value="english">English</option>
                    <option value="photo" selected>Seamless Photo</option>
                </select>
            </fieldset>
            </div>
        </div>
    </body>
</html>

<script>
    const cloudApi = new mapray.cloud.CloudApiV2({
        tokenType: mapray.cloud.CloudApi.TokenType.ACCESS_TOKEN,
        token: "<YOUR_MAPRAY_ACCESS_TOKEN>"
    });

    // The StandardUIView in the ui package includes mouse-based camera manipulation.
    const uiviewer = new maprayui.StandardUIViewer( "mapray-container", { 
        dem_provider: new mapray.StandardDemProvider( cloudApi.getDefaultDemAsResource() )
    } );


    uiviewer.setCameraPosition({
    longitude: 138.73011944,
    latitude: 35.35539722,
    height: 1000000
  });

  uiviewer.setLookAtPosition({
    longitude: 138.73133611,
    latitude:  35.35990555,
    height: 3776
  });

  document
    .getElementById('rasterPreset')
    .addEventListener('change', function () {
        console.log(this.value);

        let imageProvider = null;
        switch (this.value) {
            case "std":
                imageProvider = new mapray.StandardImageProvider( {
                    url: "https://cyberjapandata.gsi.go.jp/xyz/std/",
                    format: ".png",
                    min_level: 2,
                    max_level: 18
                } );
                break;
            case "pale":
                imageProvider = new mapray.StandardImageProvider( {
                    url: "https://cyberjapandata.gsi.go.jp/xyz/pale/",
                    format: ".png",
                    min_level: 2,
                    max_level: 18
                });
                break;
            case "english":
                imageProvider = new mapray.StandardImageProvider( {
                    url: "https://cyberjapandata.gsi.go.jp/xyz/english/",
                    format: ".png",
                    min_level: 0,
                    max_level: 11
                } );
                break;
            case "photo":
                imageProvider = new mapray.StandardImageProvider({
                    url: "https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/",
                    format: ".jpg",
                    min_level: 0,
                    max_level: 18
                });
                break;
        }
        uiviewer.viewer.setImageProvider( imageProvider, true );
    });


</script>

Info

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