Skip to content

Compass (Compass Control)

Create and manage compass navigation controls.

Constructor

ts
new ge3d.control.Compass(options?: CompassOptions): Compass

Parameters (CompassOptions)

ParameterTypeDefaultDescription
defaultResetViewCesium.Cartographic | Cesium.Rectangle-Used to set default view control when using reset navigation to reset map view. Accepts values of Cesium.Cartographic and Cesium.Rectangle
enableCompassBoolean | ObjecttrueUsed to enable or disable compass. true enables compass, false disables compass. Default value is true. If option is set to false, compass will not be added to map. Can also pass object for position settings
enableZoomControlsBoolean | ObjecttrueUsed to enable or disable zoom controls. true enables, false disables. Default value is true. If option is set to false, zoom controls will not be added to map. Can also pass object for position settings
enableDistanceLegendBooleantrueUsed to enable or disable distance legend. true enables, false disables. Default value is true. If option is set to false, distance legend will not be added to map
enableCompassOuterRingBooleantrueUsed to enable or disable compass outer ring. true enables, false disables. Default value is true. If option is set to false, the ring will be visible but inactive
resetTooltipString-Modify reset view tooltip
zoomInTooltipString-Modify zoom in button tooltip
zoomOutTooltipString-Modify zoom out button tooltip
compassOuterRingSvgString-Custom compass outer ring SVG
compassRotationMarkerSvgString-Custom compass rotation marker SVG
compassGyroSvgString-Custom compass gyro SVG
resetSvgString-Custom reset button SVG
zoomInSvgString-Custom zoom in button SVG
zoomOutSvgString-Custom zoom out button SVG

Properties

PropertyTypeDescription
_mapCoreBelonging map instance
showBooleanShow/hide state
typeStringControl type
containerHTMLElementCurrent control's DOM object
parentContainerHTMLElementParent container DOM object
parentContainerIdStringParent container DOM object's ID
uuidStringBuilt-in unique identifier ID
stateStateCurrent object's state
isAddedBooleanWhether added to map
idString | NumberObject's id identifier
enabledBooleanSet object's enabled/disabled state

Methods

MethodParametersReturn ValueDescription
destroy(noDel?: boolean)voidDestroy control

Usage Example

javascript
// Create map core
const core = new ge3d.Core("cesiumContainer", {
  scene: {
    center: { lat: 31.839441, lng: 117.153132, alt: 857.4, heading: 5, pitch: -28.3 }
  },
  baseImages: [
    {
      id: 'tdtLayerId',
      name: "Tianditu Imagery",
      type: "tdt",
      layer: "img_d",
      show: true
    }
  ],
  terrain: {
    type: "ion",
    show: true
  }
});

// Set navigation compass configuration
let options = {
  // Enable compass
  enableCompass: {
    background: '#1614146b',
  },
  enableZoomControls: false,
};

// Custom SVG icons
options.compassOuterRingSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100" fill="none"><g opacity="0.16"><circle cx="50" cy="50" r="50" fill="#1F1E1D"/><circle cx="50" cy="50" r="49.5" stroke="white" stroke-opacity="0.6"/></g><circle cx="8" cy="50" r="2" fill="#E0E0E0"/><circle cx="92" cy="50" r="2" fill="#E0E0E0"/><circle cx="50" cy="92" r="2" fill="#E0E0E0"/><circle cx="50" cy="8" r="2" fill="#B39647"/></svg>'

options.compassGyroSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 50 50" fill="none"><g id="compass-inner" fill-rule="nonzero"><circle cx="25" cy="25" r="25" fill="#292928" fill-opacity="0.95"/><path d="M25 9L30 25H20L25 9Z" fill="#B39647"/><path d="M25 41L30 25H20L25 41Z" fill="#CCCCCC"/><circle cx="25" cy="25" r="2" fill="#E0E0E0"/></g></svg>'

// Create and add compass control
const Compass = new ge3d.control.Compass(options)
core.addControl(Compass)

Notes

  1. Need to import CesiumNavigation.umd.js file before using compass control
  2. Can pass objects to set position for enableCompass and enableZoomControls
  3. Supports customizing various SVG icons to customize control appearance
  4. Compass control inherits from BaseControl, has all common properties and methods of base controls