コンテンツにスキップ

Load a GeoJSON file with properties

Load a GeoJSON file with properties

load_geojson_property.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Load a GeoJSON file with properties</title>
  <meta property="og:description" content="Load a GeoJSON file with properties" />
  <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%; }
  </style>
</head>

<body>
<div id="mapray-container"></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: 139.529127,
  latitude: 35.677033,
  height: 100000
});

uiviewer.setLookAtPosition({
  longitude: 139.529127,
  latitude: 35.677033,
  height: 0
});




// Load 2D dataset from Mapray Cloud
const resource = cloudApi.getDatasetAsResource( "5117215938445312" );

const loader = new mapray.GeoJSONLoader( uiviewer.viewer.scene, resource, {

  // callback for selecting fill color
  getFillColor: function(json) {
    // Change color based on population density
    if ( json.properties && json.properties.POP2010 ) {
      const pop2010 = json.properties.POP2010;

      if (pop2010 > 20000) {
        return [1.0, 0.0, 0.0, 0.5];
      }
      else if (pop2010 > 15000) {
        return [1.0, 0.3, 0.0, 0.5];
      }
      else if (pop2010 > 10000) {
        return [1.0, 0.6, 0.0, 0.5];
      }
      else {
        return [1.0, 1.0, 0.0, 0.5];
      }
    }
    return [0.0, 0.0, 0.0, 0.5];
  },

  // callback for selecting Altitude Mode
  getAltitudeMode: function() {
    return mapray.AltitudeMode.CLAMP;
  },

});

loader.load();


</script>

Info

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