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 Organization Token, which can be created in Mapray Cloud.
const accessToken = "<YOUR_MAPRAY_ACCESS_TOKEN>";
// The StandardUIView in the ui package includes mouse-based camera manipulation.
const uiviewer = new maprayui.StandardUIViewer( "mapray-container", accessToken, {
dem_provider: new mapray.StandardDemProvider( {
prefix: "https://tiles.mapray.com/dem/",
headers: { Authorization: "Bearer " + accessToken }
} )
} );
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: accessToken,
tokenType: mapray.cloud.CloudApi.TokenType.ACCESS_TOKEN,
});
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_ACCESS_TOKEN>を、あなたのMapray CloudのアカウントのOrganization Tokenに置き換えるまで、期待通りに動作しません。