Cesium JS API
AppearanceArcGisMapServerImageryProviderArcGISTiledElevationTerrainProviderArcTypeAssociativeArrayAxisAxisAlignedBoundingBoxbarycentricCoordinatesBillboardBillboardCollectionBillboardGraphicsBillboardVisualizerbinarySearchbinarySearchComparatorBingMapsGeocoderServiceBingMapsImageryProviderBingMapsStyleBlendEquationBlendFunctionBlendingStateBlendOptionBoundingRectangleBoundingSphereBoxEmitterBoxGeometryBoxGeometryUpdaterBoxGraphicsBoxOutlineGeometrybuildModuleUrlCallbackPropertyCameraCameraEventAggregatorCameraEventTypeCartesian2Cartesian3Cartesian4CartographicCartographicGeocoderServiceCatmullRomSplineCesium3DTileCesium3DTileColorBlendModeCesium3DTileContentCesium3DTileFeatureCesium3DTilePointFeatureCesium3DTilesetCesium3DTilesetGraphicsCesium3DTilesetVisualizerCesium3DTileStyleCesium3DTilesVoxelProviderCesiumTerrainProviderCesiumWidgetCheckerboardMaterialPropertyCircleEmitterCircleGeometryCircleOutlineGeometryClassificationPrimitiveClassificationTypeClippingPlaneClippingPlaneCollectionClockClockRangeClockStepcloneCloudCollectionCloudTypeColorColorBlendModeColorGeometryInstanceAttributeColorMaterialPropertycombineComponentDatatypeCompositeEntityCollectionCompositeMaterialPropertyCompositePositionPropertyCompositePropertyCompressedTextureBufferConditionsExpressionConeEmitterConstantPositionPropertyConstantPropertyConstantSplineContextOptionsCoplanarPolygonGeometryCoplanarPolygonOutlineGeometryCornerTypeCorridorGeometryCorridorGeometryUpdaterCorridorGraphicsCorridorOutlineGeometrycreateElevationBandMaterialcreateElevationBandMaterialBandcreateElevationBandMaterialEntrycreateGuidcreateOsmBuildingscreateTangentSpaceDebugPrimitivecreateWorldImagerycreateWorldTerrainCreditCreditDisplayCubicRealPolynomialCullFaceCullingVolumeCumulusCloudCustomDataSourceCustomHeightmapTerrainProviderCustomShaderCustomShaderModeCustomShaderTranslucencyModeCylinderGeometryCylinderGeometryUpdaterCylinderGraphicsCylinderOutlineGeometryCzmlDataSourceDataSourceDataSourceClockDataSourceCollectionDataSourceDisplayDebugAppearanceDebugCameraPrimitiveDebugModelMatrixPrimitiveDefaultProxydefaultValuedefinedDepthFunctiondestroyObjectDeveloperErrorDirectionalLightDirectionUpDiscardEmptyTileImagePolicyDiscardMissingTileImagePolicyDistanceDisplayConditionDistanceDisplayConditionGeometryInstanceAttributeEasingFunctionEllipseGeometryEllipseGeometryUpdaterEllipseGraphicsEllipseOutlineGeometryEllipsoidEllipsoidGeodesicEllipsoidGeometryEllipsoidGeometryUpdaterEllipsoidGraphicsEllipsoidOutlineGeometryEllipsoidRhumbLineEllipsoidSurfaceAppearanceEllipsoidTangentPlaneEllipsoidTerrainProviderEntityEntityClusterEntityCollectionEntityViewEventEventHelperexcludesReverseAxisexportKmlexportKmlModelCallbackexportKmlResultKmlexportKmlResultKmzExpressionExtrapolationTypeFeatureDetectionFogformatErrorFrameRateMonitorFrustumGeometryFrustumOutlineGeometryFullscreenGeocoderServiceGeocodeTypeGeographicProjectionGeographicTilingSchemeGeoJsonDataSourceGeometryGeometryAttributeGeometryAttributesGeometryFactoryGeometryInstanceGeometryInstanceAttributeGeometryPipelineGeometryUpdaterGeometryVisualizergetAbsoluteUrigetBaseUrigetExtensionFromUriGetFeatureInfoFormatgetFilenameFromUrigetImagePixelsgetTimestampGlobeGlobeTranslucencyGoogleEarthEnterpriseImageryProviderGoogleEarthEnterpriseMapsProviderGoogleEarthEnterpriseMetadataGoogleEarthEnterpriseTerrainDataGoogleEarthEnterpriseTerrainProviderGpxDataSourceGregorianDateGridImageryProviderGridMaterialPropertyGroundGeometryUpdaterGroundPolylineGeometryGroundPolylinePrimitiveGroundPrimitiveHeadingPitchRangeHeadingPitchRollHeadingPitchRollValuesHeightmapEncodingHeightmapTerrainDataHeightReferenceHermitePolynomialApproximationHermiteSplineHilbertOrderHorizontalOriginI3SDataProviderI3SFeatureI3SFieldI3SGeometryI3SLayerI3SNodeImageBasedLightingImageMaterialPropertyImageryLayerImageryLayerCollectionImageryLayerFeatureInfoImageryProviderImageryTypesincludesReverseAxisIndexDatatypeIntersectIntersections2DIntersectionTestsIntervalIonIonGeocoderServiceIonImageryProviderIonResourceIonWorldImageryStyleisLeapYearIso8601JulianDateKeyboardEventModifierKmlCameraKmlDataSourceKmlFeatureDataKmlLookAtKmlTourKmlTourFlyToKmlTourWaitLabelLabelCollectionLabelGraphicsLabelStyleLabelVisualizerLagrangePolynomialApproximationLeapSecondLightLightingModelLinearApproximationLinearSplineMapboxImageryProviderMapboxStyleImageryProviderMapMode2DMapProjectionMaterialMaterialAppearanceMaterialSupportMaterialPropertyMathMatrix2Matrix3Matrix4mergeSortmergeSortComparatorMetadataClassMetadataClassPropertyMetadataComponentTypeMetadataEnumMetadataEnumValueMetadataSchemaMetadataTypeModelModelAnimationModelAnimationCollectionModelAnimationLoopModelFeatureModelGraphicsModelNodeModelVisualizerMoonMorphWeightSplineNearFarScalarNeverTileDiscardPolicyNodeTransformationPropertyobjectToQueryOccluderOpenCageGeocoderServiceOpenStreetMapImageryProviderOrientedBoundingBoxOrthographicFrustumOrthographicOffCenterFrustumPackableForInterpolationParticleParticleBurstParticleEmitterParticleSystemPathGraphicsPathVisualizerPeliasGeocoderServicePerInstanceColorAppearancePerspectiveFrustumPerspectiveOffCenterFrustumPinBuilderPixelDatatypePixelFormatPlanePlaneGeometryPlaneGeometryUpdaterPlaneGraphicsPlaneOutlineGeometryPointCloudShadingPointGraphicspointInsideTrianglePointPrimitivePointPrimitiveCollectionPointVisualizerPolygonGeometryPolygonGeometryUpdaterPolygonGraphicsPolygonHierarchyPolygonOutlineGeometryPolylinePolylineArrowMaterialPropertyPolylineCollectionPolylineColorAppearancePolylineDashMaterialPropertyPolylineGeometryPolylineGeometryUpdaterPolylineGlowMaterialPropertyPolylineGraphicsPolylineMaterialAppearancePolylineOutlineMaterialPropertyPolylineVisualizerPolylineVolumeGeometryPolylineVolumeGeometryUpdaterPolylineVolumeGraphicsPolylineVolumeOutlineGeometryPositionPropertyPositionPropertyArrayPostProcessStagePostProcessStageCollectionPostProcessStageCompositePostProcessStageLibraryPostProcessStageSampleModePrimitivePrimitiveCollectionPrimitiveTypePropertyPropertyArrayPropertyBagProxyQuadraticRealPolynomialQuantizedMeshTerrainDataQuarticRealPolynomialQuaternionQuaternionSplinequeryToObjectQueueRayreadyPromiseRectangleRectangleGeometryRectangleGeometryUpdaterRectangleGraphicsRectangleOutlineGeometryReferenceFrameReferencePropertyremoveExtensionRequestRequestErrorEventRequestSchedulerRequestStateRequestTypeResourceRuntimeErrorSampledPositionPropertySampledPropertysampleTerrainsampleTerrainMostDetailedSceneSceneModeSceneTransformsScreenSpaceCameraControllerScreenSpaceEventHandlerScreenSpaceEventTypeshaderDefinesshaderMaximumIntersectionsLengthshaderUniformsShadowMapShadowModeShowGeometryInstanceAttributeSimon1994PlanetaryPositionsSimplePolylineGeometrySingleTileImageryProviderSkyAtmosphereSkyBoxSphereEmitterSphereGeometrySphereOutlineGeometrySphericalSplineSplitDirectionStencilFunctionStencilOperationSteppedSplineStripeMaterialPropertyStripeOrientationStyleExpressionsubdivideArraySunSunLightTaskProcessorTerrainDataTerrainProviderTextureMagnificationFilterTextureMinificationFilterTextureUniformTileAvailabilityTileCoordinatesImageryProviderTileDiscardPolicyTileMapServiceImageryProviderTileProviderErrorTilingSchemeTimeDynamicImageryTimeDynamicPointCloudTimeIntervalTimeIntervalCollectionTimeIntervalCollectionPositionPropertyTimeIntervalCollectionPropertyTimeStandardTransformsTranslationRotationScaleTridiagonalSystemSolverTrustedServersUniformSpecifierUniformTypeUrlTemplateImageryProviderVaryingTypeVelocityOrientationPropertyVelocityVectorPropertyVertexFormatVerticalOriginVideoSynchronizerViewportQuadVisibilityVisualizerVoxelPrimitiveVoxelProviderVoxelShapeTypeVRTheWorldTerrainProviderWallGeometryWallGeometryUpdaterWallGraphicsWallOutlineGeometryWebGLConstantsWebGLOptionsWebMapServiceImageryProviderWebMapTileServiceImageryProviderWebMercatorProjectionWebMercatorTilingSchemeWindingOrderwriteTextToCanvasAnimationAnimationViewModelBaseLayerPickerBaseLayerPickerViewModelCesium3DTilesInspectorCesium3DTilesInspectorViewModelCesiumInspectorCesiumInspectorViewModelClockViewModelCommandcreateCommandFullscreenButtonFullscreenButtonViewModelGeocoderGeocoderViewModelHomeButtonHomeButtonViewModelInfoBoxInfoBoxViewModelNavigationHelpButtonNavigationHelpButtonViewModelPerformanceWatchdogPerformanceWatchdogViewModelProjectionPickerProjectionPickerViewModelProviderViewModelSceneModePickerSceneModePickerViewModelSelectionIndicatorSelectionIndicatorViewModelSvgPathBindingHandlerTimelineToggleButtonViewModelViewerviewerCesium3DTilesInspectorMixinviewerCesiumInspectorMixinviewerDragDropMixinviewerPerformanceWatchdogMixinviewerVoxelInspectorMixinVoxelInspectorVoxelInspectorViewModelVRButtonVRButtonViewModel

HeightmapTerrainData

HeightmapTerrainData 对象用于表示由高程图创建的地形数据。

从高程图创建地形数据

要创建由高程图创建的地形数据,您需要提供一个符合以下规定的数组。

  • 高程地形数据数组应该是一维的,包含了列出每个列和行的高程数据的值。数组应该是网格上沿行排列的,从左到右,并沿列排列,从上到下。
  • 行和列可以是任何长度,但必须是相同的长度。
  • 大多数情况下,高程数据应该包含浮点值。但是,当使用高度数据源时,数据值必须在0到255的范围内。
  • 当高程数据使用一个缩放因子时,它的数据类型必须为无符号短整型(即16位的整数)。
var terrainData = new Cesium.HeightmapTerrainData({
    buffer : new Uint8Array(heightmapData),
    width : width,
    height : height,
    childTileMask : 1,
    structure : structure
});

属性

按需加载

  • HeightmapTerrainData.mesh
    • 类型:TerrainMesh
    • 如果 TerrainProvider 需要按需进行加载,这将尝试返回4 x 4矩形地形网格。

共享terrain块

  • HeightmapTerrainData.buffer
    • 类型:Uint8Array
    • 表示高度值的数组。如果该数组是一个无符号短整型(16位),则 表示的高度值的范围为0到65535.否则则表示范围为0到255
  • HeightmapTerrainData.width
    • 类型:Number -width表示数组中每行的高程值数。
  • HeightmapTerrainData.height
    • 类型:Number -height表示数组中每列的高程值数。
  • HeightmapTerrainData.childTileMask
    • 类型:Number
    • childTileMask 是地形网格的测量级别和几何精度级别的基础。 这些网格的边长是通过将父级网格分为二等份获得的。childTileMask是一个按位与,其中每个位在层级4^n上设置/清除。
  • HeightmapTerrainData.structure
    • 类型:HeightmapTerrainStructure
    • 表示可以在其上定义低分辨率子区域的高程结构。

示例

var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
handler.setInputAction(function (movement) {
    var pickRay = viewer.camera.getPickRay(movement.position);

    var intersection = viewer.scene.pickEllipsoid(movement.position, Ellipsoid.WGS84);
    if (intersection) {
        var cartesian = intersection;
        var cartographic = Ellipsoid.WGS84.cartesianToCartographic(cartesian);
        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);
        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);
        var terrainProviderIndex = 0;

        var cartesian = Cesium.Cartographic.fromRadians(
            cartographic.longitude,
            cartographic.latitude,
            0.0);
        var terrainSamplePositions = [cartographic];
        var promise = viewer.terrainProvider.getIntersectedTerrainHeights(terrainSamplePositions);
        Cesium.when(promise, function (updatedPositions) {
            if (Cartesian3.equals(updatedPositions[0], Cesium.Cartesian3.ZERO)) {
                console.log('沙盘演习没有数据');
                return;
            }
            cartographic = Ellipsoid.WGS84.cartesianToCartographic(updatedPositions[0]);
            var height = cartographic.height;
            console.log('Cartographic position: (' + longitudeString + ', ' + latitudeString + ', ' + height + ')');
        }).otherwise(function (error) {
            console.log(error);
        });
    }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

由于Cesium使用高程图创建地形数据,因此地形数据也可能从高程图数据中创建。以下代码片段演示了如何使用高程图数据的方法从地形图片创建地形。

var terrainData = Cesium(HeightmapTerrainData({
    buffer: new Uint8Array(heightmapData),
    width: width,
    height: height,
    childTileMask: 1,
    structure: structure
}));

这可以通过将高程数据像下面展示的示例数据定义到Javascript中来完成。该数组由64x64值构成。要更改网格大小,需要更改其高度图数据的宽度和高度值。

var heights = [
    // row 0
    59, 122, 88, 97, 30, 138, 0, 100, 139, 77, 141, 38, 25, 84, 60, 148,
    105, 8, 15, 24, 148, 49, 99, 145, 156, 88, 137, 98, 73, 32, 61, 13,
    // row 1
    36, 98, 74, 111, 38, 86, 62, 153, 39, 165, 35, 123, 112, 17, 74, 135,
    107, 25, 18, 29, 74, 131, 15, 17, 149, 73, 57, 49, 55, 51, 108, 137,
    // row 2
    1, 41, 58, 34, 16, 2, 99, 142, 12, 134, 7, 149, 36, 35, 140, 130,
    155, 60, 52, 106, 140, 11, 58, 16, 37, 80, 160, 8, 109, 157, 117, 49,
    // row 3
    92, 56, 155, 32, 106, 155, 98, 124, 27, 136, 90, 158, 138, 77, 80, 20,
    141, 43, 76, 145, 99, 135, 73, 6, 104, 49, 132, 54, 134, 122, 165, 94,
    // row 4
    63, 139, 108, 45, 71, 155, 52, 98, 120, 152, 68, 112, 11, 133, 75, 22,
    130, 15, 122, 147, 74, 118, 177, 157, 11, 72, 156, 58, 143, 137, 54, 160,
    // row 5
    97, 138, 7, 130, 2, 118, 31, 124, 139, 131, 24, 153, 140, 113, 120, 31,
    109, 152, 1, 156, 8, 103, 46, 55, 135, 107, 18, 4, 109, 134, 107, 159,
    // row 6
    38, 14, 120, 129, 42, 107, 94, 15, 153, 135, 141, 51, 31, 115, 161, 123,
    142, 145, 15, 46, 155, 51, 134, 136, 36, 88, 165, 156, 61, 91, 56, 83,
    // row 7
    105, 119, 24, 146, 8, 97, 46, 142, 77, 80, 92, 128, 117, 84, 100, 129,
    95, 77, 86, 27, 150, 116, 86, 164, 36, 154, 68, 57, 166, 169, 141, 152,
    // row 8
    25, 100, 12, 153, 91, 93, 134, 105, 62, 53, 87, 93, 148, 9, 45, 124,
    110, 130, 80, 92, 1, 45, 171, 61, 110, 71, 120, 7, 130, 137, 125, 111,
    // row 9
    140, 56, 77, 8, 51, 54, 118, 36, 119, 160, 78, 111, 72, 38, 142, 10,
    127, 139, 135, 107, 5, 67, 47, 61, 107, 14, 61, 18, 135, 44, 157, 132,
    // row 10
    25, 63, 73, 100, 129, 126, 128, 5, 54, 91, 142, 126, 135, 114, 23, 27,
    35, 32, 85, 157, 128, 102, 130, 139, 125, 79, 1, 40, 11, 44, 44, 114,
    // row 11
    147, 122, 128, 132, 17, 175, 112, 132, 80, 106, 98, 54, 44, 98, 159, 97,
    114, 77, 85, 87, 7, 167, 55, 53, 3, 37, 151, 149, 95, 44, 104, 60,
    // row 12
    12, 148, 172, 138, 113, 156, 164, 143, 96, 181, 124, 131, 155, 96, 91, 108,
    122, 74, 12, 18, 63, 19, 11, 33, 5, 156, 95, 138, 123, 150, 3, 75,
    // row 13
    60, 19, 113, 149, 172, 130, 142, 65, 15, 157, 144, 42, 174, 171, 138, 119,
    127, 157, 171, 64, 126, 148, 65, 56, 145, 90, 36, 131, 72, 46, 147, 143,
    // row 14
    55, 89, 76, 98, 111, 85, 172, 111, 104, 159, 95, 168, 167, 170, 174, 53,
    1, 61, 146, 53, 17, 112, 109, 132, 159, 59, 124, 70, 64, 5, 58, 82,
    // row 15
    129, 86, 56, 157, 142, 161, 172, 26, 94, 4, 157, 143, 165, 164, 47, 54,
    127, 77, 129, 177, 105, 93, 48, 46, 103, 151, 10, 80, 12, 82, 92, 68
];

var terrainProvider = new Cesium.CesiumTerrainProvider({
    url: 'https://assets.agi.com/stk-terrain/world',
    requestWaterMask: true,
    requestVertexNormals: true
});

var terrainData = new Cesium.HeightmapTerrainData({
    buffer: new Uint8Array(heights),
    width: 64,
    height: 64,
    childTileMask: 1
});

var entity = viewer.entities.add({
    position: Cesium.Cartesian3.fromDegrees(-75.5847, 40.0397),
    name: '白天模型世界: Philadelphia',
    description: '这是白天模型世界Philadelphia的一个地形示例。'
});
entity.polygon = {
    hierarchy: Cesium.Cartesian3.fromDegreesArray([
        -75.5847, 40.0397,
        -75.5777, 40.0397,
        -75.5777, 40.0467,
        -75.5847, 40.0467
    ]),
    material: Cesium.Color.WHITE.withAlpha(0.7),
    extrudedHeight: 0.0,
    height: 0.0
};

viewer.scene.terrainProvider = terrainProvider;
viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(-75.5847, 40.0397, 5000.0)
});