Cesium GeoJSON update
HTML
<script src="https://cesiumjs.org/Cesium/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="https://cesiumjs.org/Cesium/Build/Cesium/Widgets/widgets.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Turf.js/5.1.5/turf.min.js"></script>
<div id="cesiumContainer"></div>
CSS
html {
height: 100%;
}
body {
padding: 0;
margin: 0;
overflow: hidden;
height: 100%;
}
#cesiumContainer{
height: 100%;
}
JavaScript
const viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider: Cesium.createWorldTerrain(),
});
const centerLatitude = 27.988257;
const centerLongitude = 86.925145;
const size = 0.2;
const cesiumPointsArray = [
centerLongitude + size, centerLatitude + size,
centerLongitude + size, centerLatitude - size,
centerLongitude - size, centerLatitude - size,
centerLongitude - size, centerLatitude + size,
];
const turfPointsArray = [];
for(let i = 0; i < cesiumPointsArray.length; i += 2){
turfPointsArray.push([cesiumPointsArray[i], cesiumPointsArray[i+1]]);
}
turfPointsArray.push([cesiumPointsArray[0], cesiumPointsArray[1]]);
const cesiumPolygon = viewer.entities.add({
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray(cesiumPointsArray),
material : Cesium.Color.BLUE.withAlpha(0.2),
}
});
viewer.zoomTo(viewer.entities);
function getMinAndMaxHeightPointsInPolygon(accuracy) {
return new Promise((reoslve, reject) => {
const polygon = turf.polygon([turfPointsArray]);
let grid = turf.pointGrid(turf.bbox(polygon), accuracy.level, {units: accuracy.units});
let pointsInPolygon = turf.pointsWithinPolygon(grid, polygon);
console.log(pointsInPolygon.features.length);
const pointsWithHeight = Cesium.sampleTerrainMostDetailed(
Cesium.createWorldTerrain(), //viewer.terrainProvider
pointsInPolygon.features.map(point =>
new Cesium.Cartographic.fromDegrees(point.geometry.coordinates[0], point.geometry.coordinates[1]))
);
pointsWithHeight.then(res => reoslve(re))
/* pointsWithHeight.then(res => {
const topHeightPosition = res.reduce((topHeightPosition, currentPosition) =>
!topHeightPosition || currentPosition.height > topHeightPosition.height ? currentPosition : topHeightPosition, undefined);
const minHeightPosition = res.reduce((topHeightPosition, currentPosition) =>
!topHeightPosition || currentPosition.height < topHeightPosition.height ?...