Cesium JS API
AppearanceArcGisMapServerImageryProviderArcGISTiledElevationTerrainProviderArcTypeAssociativeArrayAxisAxisAlignedBoundingBoxbarycentricCoordinatesBillboardBillboardCollectionBillboardGraphicsBillboardVisualizerbinarySearchbinarySearchComparatorBingMapsGeocoderServiceBingMapsImageryProviderBingMapsStyleBlendEquationBlendFunctionBlendingStateBlendOptionBoundingRectangleBoundingSphereBoxEmitterBoxGeometryBoxGeometryUpdaterBoxGraphicsBoxOutlineGeometrybuildModuleUrlCallbackPropertyCameraCameraEventAggregatorCameraEventTypeCartesian2Cartesian3Cartesian4CartographicCartographicGeocoderServiceCatmullRomSplineCesium3DTileCesium3DTileColorBlendModeCesium3DTileContentCesium3DTileFeatureCesium3DTilePointFeatureCesium3DTilesetCesium3DTilesetGraphicsCesium3DTilesetVisualizerCesium3DTileStyleCesium3DTilesVoxelProviderCesiumTerrainProviderCesiumWidgetCheckerboardMaterialPropertyCircleEmitterCircleGeometryCircleOutlineGeometryClassificationPrimitiveClassificationTypeClippingPlaneClippingPlaneCollectionClockClockRangeClockStepcloneCloudCollectionCloudTypeColorColorBlendModeColorGeometryInstanceAttributeColorMaterialPropertycombineComponentDatatypeCompositeEntityCollectionCompositeMaterialPropertyCompositePositionPropertyCompositePropertyCompressedTextureBufferConditionsExpressionConeEmitterConstantPositionPropertyConstantPropertyConstantSplineContextOptionsCoplanarPolygonGeometryCoplanarPolygonOutlineGeometryCornerTypeCorridorGeometryCorridorGeometryUpdaterCorridorGraphicsCorridorOutlineGeometrycreateElevationBandMaterialcreateElevationBandMaterialBandcreateElevationBandMaterialEntrycreateGuidcreateOsmBuildingscreateTangentSpaceDebugPrimitivecreateWorldImagerycreateWorldTerrainCreditCreditDisplayCubicRealPolynomialCullFaceCullingVolumeCumulusCloudCustomDataSourceCustomHeightmapTerrainProviderCustomShaderCustomShaderModeCustomShaderTranslucencyModeCylinderGeometryCylinderGeometryUpdaterCylinderGraphicsCylinderOutlineGeometryCzmlDataSourceDataSourceDataSourceClockDataSourceCollectionDataSourceDisplayDebugAppearanceDebugCameraPrimitiveDebugModelMatrixPrimitiveDefaultProxydefaultValuedefinedDepthFunctiondestroyObjectDeveloperErrorDirectionalLightDirectionUpDiscardEmptyTileImagePolicyDiscardMissingTileImagePolicyDistanceDisplayConditionDistanceDisplayConditionGeometryInstanceAttributeEasingFunctionEllipseGeometryEllipseGeometryUpdaterEllipseGraphicsEllipseOutlineGeometryEllipsoidEllipsoidGeodesicEllipsoidGeometryEllipsoidGeometryUpdaterEllipsoidGraphicsEllipsoidOutlineGeometryEllipsoidRhumbLineEllipsoidSurfaceAppearanceEllipsoidTangentPlaneEllipsoidTerrainProviderEntityEntityClusterEntityCollectionEntityViewEventEventHelperexcludesReverseAxisexportKmlexportKmlModelCallbackexportKmlResultKmlexportKmlResultKmzExpressionExtrapolationTypeFeatureDetectionFogformatErrorFrameRateMonitorFrustumGeometryFrustumOutlineGeometryFullscreenGeocoderServiceGeocodeTypeGeographicProjectionGeographicTilingSchemeGeoJsonDataSourceGeometryGeometryAttributeGeometryAttributesGeometryFactoryGeometryInstanceGeometryInstanceAttributeGeometryPipelineGeometryUpdaterGeometryVisualizergetAbsoluteUrigetBaseUrigetExtensionFromUriGetFeatureInfoFormatgetFilenameFromUrigetImagePixelsgetTimestampGlobeGlobeTranslucencyGoogleEarthEnterpriseImageryProviderGoogleEarthEnterpriseMapsProviderGoogleEarthEnterpriseMetadataGoogleEarthEnterpriseTerrainDataGoogleEarthEnterpriseTerrainProviderGpxDataSourceGregorianDateGridImageryProviderGridMaterialPropertyGroundGeometryUpdaterGroundPolylineGeometryGroundPolylinePrimitiveGroundPrimitiveHeadingPitchRangeHeadingPitchRollHeadingPitchRollValuesHeightmapEncodingHeightmapTerrainDataHeightReferenceHermitePolynomialApproximationHermiteSplineHilbertOrderHorizontalOriginI3SDataProviderI3SFeatureI3SFieldI3SGeometryI3SLayerI3SNodeImageBasedLightingImageMaterialPropertyImageryLayerImageryLayerCollectionImageryLayerFeatureInfoImageryProviderImageryTypesincludesReverseAxisIndexDatatypeIntersectIntersections2DIntersectionTestsIntervalIonIonGeocoderServiceIonImageryProviderIonResourceIonWorldImageryStyleisLeapYearIso8601JulianDateKeyboardEventModifierKmlCameraKmlDataSourceKmlFeatureDataKmlLookAtKmlTourKmlTourFlyToKmlTourWaitLabelLabelCollectionLabelGraphicsLabelStyleLabelVisualizerLagrangePolynomialApproximationLeapSecondLightLightingModelLinearApproximationLinearSplineMapboxImageryProviderMapboxStyleImageryProviderMapMode2DMapProjectionMaterialMaterialAppearanceMaterialSupportMaterialPropertyMathMatrix2Matrix3Matrix4mergeSortmergeSortComparatorMetadataClassMetadataClassPropertyMetadataComponentTypeMetadataEnumMetadataEnumValueMetadataSchemaMetadataTypeModelModelAnimationModelAnimationCollectionModelAnimationLoopModelFeatureModelGraphicsModelNodeModelVisualizerMoonMorphWeightSplineNearFarScalarNeverTileDiscardPolicyNodeTransformationPropertyobjectToQueryOccluderOpenCageGeocoderServiceOpenStreetMapImageryProviderOrientedBoundingBoxOrthographicFrustumOrthographicOffCenterFrustumPackableForInterpolationParticleParticleBurstParticleEmitterParticleSystemPathGraphicsPathVisualizerPeliasGeocoderServicePerInstanceColorAppearancePerspectiveFrustumPerspectiveOffCenterFrustumPinBuilderPixelDatatypePixelFormatPlanePlaneGeometryPlaneGeometryUpdaterPlaneGraphicsPlaneOutlineGeometryPointCloudShadingPointGraphicspointInsideTrianglePointPrimitivePointPrimitiveCollectionPointVisualizerPolygonGeometryPolygonGeometryUpdaterPolygonGraphicsPolygonHierarchyPolygonOutlineGeometryPolylinePolylineArrowMaterialPropertyPolylineCollectionPolylineColorAppearancePolylineDashMaterialPropertyPolylineGeometryPolylineGeometryUpdaterPolylineGlowMaterialPropertyPolylineGraphicsPolylineMaterialAppearancePolylineOutlineMaterialPropertyPolylineVisualizerPolylineVolumeGeometryPolylineVolumeGeometryUpdaterPolylineVolumeGraphicsPolylineVolumeOutlineGeometryPositionPropertyPositionPropertyArrayPostProcessStagePostProcessStageCollectionPostProcessStageCompositePostProcessStageLibraryPostProcessStageSampleModePrimitivePrimitiveCollectionPrimitiveTypePropertyPropertyArrayPropertyBagProxyQuadraticRealPolynomialQuantizedMeshTerrainDataQuarticRealPolynomialQuaternionQuaternionSplinequeryToObjectQueueRayreadyPromiseRectangleRectangleGeometryRectangleGeometryUpdaterRectangleGraphicsRectangleOutlineGeometryReferenceFrameReferencePropertyremoveExtensionRequestRequestErrorEventRequestSchedulerRequestStateRequestTypeResourceRuntimeErrorSampledPositionPropertySampledPropertysampleTerrainsampleTerrainMostDetailedSceneSceneModeSceneTransformsScreenSpaceCameraControllerScreenSpaceEventHandlerScreenSpaceEventTypeshaderDefinesshaderMaximumIntersectionsLengthshaderUniformsShadowMapShadowModeShowGeometryInstanceAttributeSimon1994PlanetaryPositionsSimplePolylineGeometrySingleTileImageryProviderSkyAtmosphereSkyBoxSphereEmitterSphereGeometrySphereOutlineGeometrySphericalSplineSplitDirectionStencilFunctionStencilOperationSteppedSplineStripeMaterialPropertyStripeOrientationStyleExpressionsubdivideArraySunSunLightTaskProcessorTerrainDataTerrainProviderTextureMagnificationFilterTextureMinificationFilterTextureUniformTileAvailabilityTileCoordinatesImageryProviderTileDiscardPolicyTileMapServiceImageryProviderTileProviderErrorTilingSchemeTimeDynamicImageryTimeDynamicPointCloudTimeIntervalTimeIntervalCollectionTimeIntervalCollectionPositionPropertyTimeIntervalCollectionPropertyTimeStandardTransformsTranslationRotationScaleTridiagonalSystemSolverTrustedServersUniformSpecifierUniformTypeUrlTemplateImageryProviderVaryingTypeVelocityOrientationPropertyVelocityVectorPropertyVertexFormatVerticalOriginVideoSynchronizerViewportQuadVisibilityVisualizerVoxelPrimitiveVoxelProviderVoxelShapeTypeVRTheWorldTerrainProviderWallGeometryWallGeometryUpdaterWallGraphicsWallOutlineGeometryWebGLConstantsWebGLOptionsWebMapServiceImageryProviderWebMapTileServiceImageryProviderWebMercatorProjectionWebMercatorTilingSchemeWindingOrderwriteTextToCanvasAnimationAnimationViewModelBaseLayerPickerBaseLayerPickerViewModelCesium3DTilesInspectorCesium3DTilesInspectorViewModelCesiumInspectorCesiumInspectorViewModelClockViewModelCommandcreateCommandFullscreenButtonFullscreenButtonViewModelGeocoderGeocoderViewModelHomeButtonHomeButtonViewModelInfoBoxInfoBoxViewModelNavigationHelpButtonNavigationHelpButtonViewModelPerformanceWatchdogPerformanceWatchdogViewModelProjectionPickerProjectionPickerViewModelProviderViewModelSceneModePickerSceneModePickerViewModelSelectionIndicatorSelectionIndicatorViewModelSvgPathBindingHandlerTimelineToggleButtonViewModelViewerviewerCesium3DTilesInspectorMixinviewerCesiumInspectorMixinviewerDragDropMixinviewerPerformanceWatchdogMixinviewerVoxelInspectorMixinVoxelInspectorVoxelInspectorViewModelVRButtonVRButtonViewModel

ScreenSpaceCameraController

介绍

ScreenSpaceCameraController是CesiumJS中的摄像机控制器,可以通过鼠标和触摸屏交互来控制场景中的摄像机。

使用方法

要使用ScreenSpaceCameraController,请在Cesium Viewer对象上调用screenSpaceCameraController属性。例如:

var viewer = new Cesium.Viewer('cesiumContainer');
viewer.screenSpaceCameraController.enableTranslate = true;

属性

ScreenSpaceCameraController具有以下属性:

Property: enableRotate

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用旋转操作。

Property: enableTranslate

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用平移操作。

Property: enableZoom

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用缩放操作。

Property: enableTilt

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用倾斜操作。

Property: enableLook

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用查看(Look)操作。

Property: minimumZoomDistance

  • 类型: Number
  • 默认值: 0.0
  • 描述: 可缩放的最小距离。

Property: maximumZoomDistance

  • 类型: Number
  • 默认值: Infinity
  • 描述: 可缩放的最大距离。

Property: maximumPickingDistance

  • 类型: Number
  • 默认值: Number.POSITIVE_INFINITY
  • 描述: 可选的最大距离。

Property: minimumCollisionTerrainHeight

  • 类型: Number
  • 默认值: 0.0
  • 描述: 当与地形碰撞时,可通过相机离地面的最小距离来避免穿透地形。

Property: minimumCollisionObjectHeight

  • 类型: Number
  • 默认值: Number.NEGATIVE_INFINITY
  • 描述: 当碰撞到3D对象时,可通过相机离3D对象的最小距离来避免穿透3D对象。

Property: minimumTrackBallHeight

  • 类型: Number
  • 默认值: 0.0
  • 描述: 当启用Trackball模式时,可通过相机高度来限制旋转。

Property: enableCollisionDetection

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用碰撞检测。开启时可以避免穿透地形和3D对象。

Property: enableLookAround

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用查看周围操作。开启后,按住鼠标右键可以改变相机朝向,而不改变相机位置。

Property: enableDistanceReset

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用距离重置。开启后,双击鼠标左键可以重置相机距离。

Property: enableCompass

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用方向指示。开启后,可以显示方向指示器。

Property: enableZoomOut

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用缩小操作。

Property: enableZoomIn

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用放大操作。

Property: enableRotateLeft

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用向左旋转操作。

Property: enableRotateRight

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用向右旋转操作。

Property: enableRotateUp

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用向上旋转操作。

Property: enableRotateDown

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用向下旋转操作。

Property: enableTiltLeft

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用向左倾斜操作。

Property: enableTiltRight

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用向右倾斜操作。

Property: enableTiltUp

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用向上倾斜操作。

Property: enableTiltDown

  • 类型: Boolean
  • 默认值: true
  • 描述: 是否启用向下倾斜操作。

Property: minimumPickingTerrainHeight

  • 类型: Number
  • 默认值: Number.NEGATIVE_INFINITY
  • 描述: 当使用相机拾取地形时,可通过选择距离地面的最小距离来避免拾取地形。

Property: tiltEventTypes

  • 类型: Array
  • 默认值: [Cesium.CameraEventType.LEFT_DRAG, Cesium.CameraEventType.PINCH]
  • 描述: 支持导致倾斜的事件类型。

Property: rotateEventTypes

  • 类型: Array
  • 默认值: [Cesium.CameraEventType.LEFT_DRAG, Cesium.CameraEventType.PINCH]
  • 描述: 支持导致旋转的事件类型。

Property: translateEventTypes

  • 类型: Array
  • 默认值: [Cesium.CameraEventType.RIGHT_DRAG]
  • 描述: 支持导致平移的事件类型。

Property: zoomEventTypes

  • 类型: Array
  • 默认值: [Cesium.CameraEventType.WHEEL, Cesium.CameraEventType.PINCH]
  • 描述: 支持导致缩进的事件类型。

Property: lookEventTypes

  • 类型: Array
  • 默认值: [Cesium.CameraEventType.RIGHT_DRAG]
  • 描述: 支持导致相机看着某个位置的事件类型。

方法

ScreenSpaceCameraController具有以下方法:

Method: lookAt

  • 描述: 将相机看向指定位置和方向。
  • 参数:
    • destination: 待查看位置的Cartesian3,或与direction一起用于确定目标轴向的Matrix4。
    • offset: 相机与目标位置的偏移量。默认为Cesium.Cartesian3.ZERO
    • orientation: 相机的方向角。默认为Cesium.Matrix4.IDENTITY
  • 返回值: 无。

Method: getPickRay

  • 描述: 获取从摄像机的位置出发穿过特定屏幕位置的射线。
  • 参数:
    • windowPosition: 屏幕位置。
  • 返回值: 一个新的Ray对象。

事件

ScreenSpaceCameraController定义了以下事件:

Event: tiltStart

  • 类型: Event
  • 描述: 开始朝向旋转事件。

Event: tiltEnd

  • 类型: Event
  • 描述: 结束朝向旋转事件。

Event: rotateStart

  • 类型: Event
  • 描述: 开始旋转事件。

Event: rotateEnd

  • 类型: Event
  • 描述: 结束旋转事件。

Event: translateStart

  • 类型: Event
  • 描述: 开始平移事件。

Event: translateEnd

  • 类型: Event
  • 描述: 结束平移事件。

Event: zoomStart

  • 类型: Event
  • 描述: 开始缩放事件。

Event: zoomEnd

  • 类型: Event
  • 描述: 结束缩放事件。

Event: lookStart

  • 类型: Event
  • 描述: 开始查看事件。

Event: lookEnd

  • 类型: Event
  • 描述: 结束查看事件。

Event: activate

  • 类型: Event
  • 描述: 当控制器被激活时发出的事件。

Event: deactivate

  • 类型: Event
  • 描述: 当控制器被停用时发出的事件。

示例

以下是一个使用ScreenSpaceCameraController的简单示例:

var viewer = new Cesium.Viewer('cesiumContainer');

viewer.screenSpaceCameraController.rotateEventTypes = [Cesium.CameraEventType.RIGHT_DRAG];
viewer.screenSpaceCameraController.translateEventTypes = [Cesium.CameraEventType.LEFT_DRAG];
viewer.screenSpaceCameraController.zoomEventTypes = [Cesium.CameraEventType.MOUSE_WHEEL, Cesium.CameraEventType.PINCH];

viewer.screenSpaceCameraController.enableTranslate = true;
viewer.screenSpaceCameraController.enableZoom = true;
viewer.screenSpaceCameraController.enableTilt = true;
viewer.screenSpaceCameraController.enableRotate = true;

viewer.screenSpaceCameraController.tiltEventTypes = [Cesium.CameraEventType.RIGHT_DRAG, Cesium.CameraEventType.PINCH, Cesium.CameraEventType.LEFT_DRAG];
viewer.screenSpaceCameraController.rotateEventTypes = [Cesium.CameraEventType.RIGHT_DRAG, Cesium.CameraEventType.PINCH];
viewer.screenSpaceCameraController.translateEventTypes = [Cesium.CameraEventType.RIGHT_DRAG];

viewer.screenSpaceCameraController.changed.addEventListener(function() {
    console.log("Camera changed.");
});

viewer.camera.setView({
    destination: Cesium.Cartesian3.fromDegrees(-122.4194, 37.7749, 10000.0)
});

在这个例子中,我们将rotateEventTypes设置为RIGHT_DRAG,将translateEventTypes设置为LEFT_DRAG,将zoomEventTypes设置为MOUSE_WHEELPINCH,以使这些事件触发相应的控制器操作。我们还启用了平移、缩放、倾斜和旋转控制器,设置了支持倾斜和旋转的事件类型,并注册了一个回调函数,以便在相机状态更改时记录消息。最后,我们设置了相机的初始视图并创建了一个新的Cesium Viewer。