core/components/NavigationBar.js

/*
 * 组件-导航
 * @Author: jianlei wang
 * @Date: 2023-09-08 22:45:52
 * @Last Modified by: jianlei wang
 * @Last Modified time: 2024-03-28 15:25:04
 */

import { Cesium } from '../../../namespace'
import CesiumNavigation from 'cesium-navigation-es6'

const DEF_OPTION = {
  // 默认视角
  // defaultResetView: Cartographic.fromDegrees(113.318977, 23.114155, 20000),
  //相机方向
  orientation: { pitch: Cesium.Math.toRadians(-45) },
  //相机延时
  // duration = 4, //默认为3s
  // 用于启用或禁用罗盘。true是启用罗盘,false是禁用罗盘。默认值为true。如果将选项设置为false,则罗盘将不会添加到地图中。
  enableCompass: true,
  // 用于启用或禁用缩放控件。true是启用,false是禁用。默认值为true。如果将选项设置为false,则缩放控件将不会添加到地图中。
  enableZoomControls: true,
  // 用于启用或禁用距离图例。true是启用,false是禁用。默认值为true。如果将选项设置为false,距离图例将不会添加到地图中。
  enableDistanceLegend: false,
  // 用于启用或禁用指南针外环。true是启用,false是禁用。默认值为true。如果将选项设置为false,则该环将可见但无效。
  enableCompassOuterRing: true, //修改重置视图的tooltip
  resetTooltip: '重置视图',
  // 修改放大按钮的tooltip
  zoomInTooltip: '放大',
  // 修改缩小按钮的tooltip
  zoomOutTooltip: '缩小',
}
/**
 * 导航组件类
 * @class
 */
class NavigationBar {
  /**
   * 构造函数
   * @param {Object} viewer 地图场景对象
   */
  constructor(viewer) {
    this._viewer = viewer
    this._show = false
  }
  /**
   * 控制导航组件显隐
   * @type {Boolean}
   */
  set show(show) {
    if (this._show === show) return
    show ? this._initNavigation() : this._removeNavigation()
    this._show = show
  }
  _initNavigation() {
    this._navigationBar = new CesiumNavigation(this._viewer, DEF_OPTION)
  }
  _removeNavigation() {
    this._navigationBar && this._navigationBar.destroy()
  }
}
export default NavigationBar