コンテンツにスキップ

Switch the level of detail of PLATEAU buildings

Switching the PLATEAU Taito buildings between LOD1, LOD2 with and without textures, and LOD3.

plateau_switch_lod.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Switch the level of detail of PLATEAU buildings</title>
  <meta property="og:description" content="Switching the PLATEAU Taito buildings between LOD1, LOD2 with and without textures, and LOD3." />
  <script src="./v0.10.7/mapray.min.js"></script>
  <script src="./v0.10.7/maprayui.min.js"></script>
  <link rel="stylesheet" href="./v0.10.7/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: 300px;
        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 fieldset {
        border: none;
        padding: 0;
        margin: 0 0 10px;
    }
    .map-overlay-inner fieldset:last-child {
        margin: 0;
    }
    .map-overlay-inner label {
        display: block;
        font-weight: bold;
        margin: 0 0 5px;
    }
    .map-overlay-inner select, .map-overlay-inner input[type=range] {
        width: 100%;
    }
  </style>
</head>
<body>
<div id="mapray-container"></div>
<div class="map-overlay top">
    <div class="map-overlay-inner">
        <fieldset>
            <label>Level of detail</label>
            <label style="font-weight: normal"><input type="radio" name="lod" value="lod1"> LOD1 (boxes)</label>
            <label style="font-weight: normal"><input type="radio" name="lod" value="lod2_nt"> LOD2 (roofs), no texture</label>
            <label style="font-weight: normal"><input type="radio" name="lod" value="lod2" checked> LOD2 (roofs), textured</label>
            <label style="font-weight: normal"><input type="radio" name="lod" value="lod3_nt"> LOD3 (openings), no texture</label>
        </fieldset>
    </div>
</div>
</body>
</html>
<script>
  // Switches the Taito buildings between LOD1, LOD2 with and without textures, and LOD3. Each LOD is a separate tileset.
  const LODS = {
      lod1: "https://assets.cms.plateau.reearth.io/assets/98/c5ff8d-d6b4-40fb-8ef9-fcca1407f9c0/13106_taito-ku_city_2025_citygml_1_op_bldg_3dtiles_lod1/tileset.json",
      lod2_nt: "https://assets.cms.plateau.reearth.io/assets/89/471b74-c5ca-4673-afaa-c194d18b5c8c/13106_taito-ku_city_2025_citygml_1_op_bldg_3dtiles_lod2_no_texture/tileset.json",
      lod2: "https://assets.cms.plateau.reearth.io/assets/75/76c6bc-df54-4bf4-a869-b513526b5bd2/13106_taito-ku_city_2025_citygml_1_op_bldg_3dtiles_lod2/tileset.json",
      lod3_nt: "https://assets.cms.plateau.reearth.io/assets/d1/6b9ee6-d3b7-4ab5-8391-b9a6f4833385/13106_taito-ku_city_2025_citygml_1_op_bldg_3dtiles_lod3_no_texture/tileset.json",
  };

  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() )
    } );
  // Around Asakusa in Tokyo JP
  uiviewer.setCameraPosition({
    longitude: 139.7955,
    latitude: 35.7085,
    height: 500
  });
  // Senso-ji
  uiviewer.setLookAtPosition({
    longitude: 139.7967,
    latitude: 35.7148,
    height: 30
  });

  let scene = null;

  // A scene shows one tileset, so a different LOD is a new scene. The old scene is removed first.
  function showLod( name ) {
      if ( scene ) {
          uiviewer.viewer.b3d_collection.removeScene( scene );
      }
      // PLATEAU Taito-ku buildings (OGC 3D Tiles 1.1: glTF content with EXT_structural_metadata)
      const provider = new mapray.StandardTiles3DProvider({
        url: LODS[name]
      }, {
        // PLATEAU tiles carry no copyright string, so credit the dataset as the PLATEAU terms of use require (Public Data License 1.0, compatible with CC BY 4.0).
        attributions: [ "出典:「3D都市モデル(Project PLATEAU)台東区(2025年度)」(国土交通省)" ]
      });
      scene = uiviewer.viewer.b3d_collection.createTiles3DScene( provider, {
          show_attributions: true,
          vertical_offset: -37   // ellipsoidal height to elevation (geoid undulation around Tokyo)
      } );
  }

  for ( const radio of document.querySelectorAll( 'input[name="lod"]' ) ) {
      radio.addEventListener( 'change', event => showLod( event.target.value ) );
  }
  showLod( document.querySelector( 'input[name="lod"]:checked' ).value );
</script>

Info

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