1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
getProjectedArea (positions) { const { Cartographic, Math: CesiumMath } = Cesium let array = [] for (let i = 0, len = positions.length; i < len; i++) { let cartographic = Cartographic.fromCartesian(positions[i]) let longitude = CesiumMath.toDegrees(cartographic.longitude).toFixed(6) let latitude = CesiumMath.toDegrees(cartographic.latitude).toFixed(6) array.push({ x: longitude, y: latitude }) } let arrs = [] let tems = [] arrs.push(tems) for (let i = 0, len = array.length; i < len; i++) { tems.push([array[i].x, array[i].y]) } let polygons = { type: 'FeatureCollection', features: [ { type: 'Feature', properties: {}, geometry: { type: 'Polygon', coordinates: arrs } }, { type: 'Feature', properties: {}, geometry: { type: 'Polygon', coordinates: [[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]] } } ] } return area(polygons) },
getSurfaceArea (positions) { if (positions.length < 3) { return 0 } const { Cartesian3, EllipsoidTangentPlane, Ellipsoid, Math: CesiumMath, PolygonGeometryLibrary, PolygonHierarchy, VertexFormat } = Cesium const perPositionHeight = true const tangentPlane = EllipsoidTangentPlane.fromPoints( positions, Ellipsoid.WGS84 ) const polygons = PolygonGeometryLibrary.polygonsFromHierarchy( new PolygonHierarchy(positions), tangentPlane.projectPointsOntoPlane.bind(tangentPlane), !perPositionHeight, Ellipsoid.WGS84 )
const geom = PolygonGeometryLibrary.createGeometryFromPositions( Ellipsoid.WGS84, polygons.polygons[0], CesiumMath.RADIANS_PER_DEGREE, perPositionHeight, VertexFormat.POSITION_ONLY )
if (geom.indices.length % 3 !== 0 || geom.attributes.position.values.length % 3 !== 0) { return 0 } const coords = [] for (let i = 0; i < geom.attributes.position.values.length; i += 3) { coords.push( new Cartesian3( geom.attributes.position.values[i], geom.attributes.position.values[i + 1], geom.attributes.position.values[i + 2] ) ) } let area = 0 for (let i = 0; i < geom.indices.length; i += 3) { const ind1 = geom.indices[i] const ind2 = geom.indices[i + 1] const ind3 = geom.indices[i + 2]
const a = Cartesian3.distance(coords[ind1], coords[ind2]) const b = Cartesian3.distance(coords[ind2], coords[ind3]) const c = Cartesian3.distance(coords[ind3], coords[ind1])
const s = (a + b + c) / 2.0 area += Math.sqrt(s * (s - a) * (s - b) * (s - c)) } return area }
|