コンテンツにスキップ

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="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>
    body {margin: 0; padding: 0;}
    html, body, div#mapray-container { height: 100%; }
  </style>
</head>

<body>
<div id="mapray-container"></div>
</body>
</html>

<script>
// Set up your access token, which can be created in Mapray Cloud.
const apikey = "<YOUR_MAPRAY_API_KEY>";

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

uiviewer.setCameraPosition({
  longitude: 139.529127,
  latitude: 35.677033,
  height: 100000
});

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

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

const resource = cloudApi.getDatasetAsResource([5117215938445312]);
const loader = new mapray.GeoJSONLoader(uiviewer.viewer.scene, resource, {
  getFillColor: getPolulationDensityColor,
  getAltitudeMode: () => { return mapray.AltitudeMode.CLAMP },
});

loader.load();


function getPolulationDensityColor(d) {
  let color = [0.0, 0.0, 0.0, 0.5];

  // Change color based on population density
  if (d.properties && d.properties.POP2010) {
    const pop2010 = d.properties.POP2010;

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

  return color;
}

</script>

Info

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