utils/plotting/index.js

/*
 * 态势标绘主类
 * @Author: jianlei wang
 * @Date: 2024-02-19 14:26:22
 * @Last Modified by: jianlei wang
 * @Last Modified time: 2024-05-24 15:55:06
 */
import { Cesium } from '../../../namespace'
import { resetGlobeHandler } from '../Handler'

import CreatePoint from './create/CreatePoint'
import CreateBillboard from './create/CreateBillboard'
import CreatePolyline from './create/CreatePolyline'
import CreateCurve from './create/CreateCurve'
import CreateFreeLine from './create/CreateFreeLine'
import { removeEntity } from '../layers/Entity'
import CreatePolygon from './create/CreatePolygon'
import CreateFreePolygon from './create/CreateFreePolygon'
import CreateRegularPolygon from './create/CreateRegularPolygon'
import CreateBow from './create/CreateBow'
import CreateElliptic from './create/CreateElliptic'
import CreateSector from './create/CreateSector'
import CreateCircle from './create/CreateCircle'
import CreateRectangle from './create/CreateRectangle'
import CreateRoundRectangle from './create/CreateRoundRectangle'
import CreateAssemble from './create/CreateAssemble'
import CreateLineArrow from './create/CreateLineArrow'
import CreateRightAngleArrow from './create/CreateRightAngleArrow'
import CreateStraightArrow from './create/CreateStraight'
import CreateAttackArrow from './create/CreateAttackArrow'
import CreateSwallowtailArrow from './create/CreateSwallowtailArrow'
import CreatePincerArrow from './create/CreatePincerArrow'
import CreateFlag from './create/CreateFlag'
import CreateFormation from './create/CreateFormation'
import CreateLabel from './create/CreateLabel'

/**
 * 态势标绘主类
 * @class
 */
class MilitaryPlotting {
  /**
   * 构造函数
   * @param {Object} viewer - 地图场景对象
   */
  constructor(viewer) {
    this._viewer = viewer
    this._results = this._viewer.entities.add(new Cesium.Entity())
  }

  /**
   * 标绘结果对象集,Entity类对象,参考Cesium,主要借助Parent管理
   * @readonly
   * @type {Entity}
   */
  get results() {
    return this._results
  }

  /**
   * 绘制点
   * @param {PlotPoint} options - 绘制点参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawPoint(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreatePoint(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制广告版
   * @param {PlotBillboard} options - 绘制广告版参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawBillboard(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateBillboard(this._viewer, handler, this._results, options, callback)
  }
  /**
   * 绘制折线
   * @param {PlotPolyline} options - 绘制折线参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawPolyline(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreatePolyline(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制圆滑曲线
   * @param {PlotPolyline} options - 绘制曲线参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawCurve(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateCurve(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制自由线
   * @param {PlotPolyline} options - 绘制自由线参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawFreeLine(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateFreeLine(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制多边形
   * @param {PlotPolygon} options - 绘制多边形参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawPolygon(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreatePolygon(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制自由多边形
   * @param {PlotPolygon} options - 绘制自由多边形参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawFreePolygon(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateFreePolygon(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制正多边形
   * @param {PlotPolygon} options - 绘制正多边形参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawRegularPolygon(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateRegularPolygon(
      this._viewer,
      handler,
      this._results,
      options,
      callback
    )
  }

  /**
   * 绘制弓形
   * @param {PlotPolyline} options - 绘制弓形参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawBow(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateBow(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制椭圆
   * @param {PlotColor} options - 绘制椭圆参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawElliptic(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateElliptic(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制扇形
   * @param {PlotPolygon} options - 绘制扇形参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawSector(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateSector(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制圆
   * @param {PlotColor} options - 绘制圆参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawCircle(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateCircle(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制矩形
   * @param {PlotColor} options - 绘制矩形参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawRectangle(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateRectangle(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制圆角矩形
   * @param {PlotPolygon} options - 绘制圆角矩形参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawRoundRectangle(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateRoundRectangle(
      this._viewer,
      handler,
      this._results,
      options,
      callback
    )
  }

  /**
   * 绘制集结地
   * @param {PlotPolygon} options - 绘制集结地参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawAssemble(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateAssemble(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制简单箭头-包括直线和曲线
   * @param {PlotPolyline} options - 绘制简单箭头参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawLineArrow(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateLineArrow(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制直角箭头
   * @param {PlotPolygon} options - 绘制直角箭头参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawRightAngleArrow(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateRightAngleArrow(
      this._viewer,
      handler,
      this._results,
      options,
      callback
    )
  }

  /**
   * 绘制直线箭头
   * @param {PlotPolygon} options - 绘制直线箭头参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawStraightArrow(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateStraightArrow(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制攻击箭头
   * @param {PlotPolygon} options - 绘制攻击箭头参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawAttackArrow(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateAttackArrow(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制燕尾箭头
   * @param {PlotArrow} options - 绘制燕尾箭头参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawSwallowtailArrow(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateSwallowtailArrow(
      this._viewer,
      handler,
      this._results,
      options,
      callback
    )
  }

  /**
   * 绘制钳击箭头
   * @param {PlotPolygon} options - 绘制钳击箭头参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawPincerArrow(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreatePincerArrow(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制旗标
   * @param {PlotFlag} options - 绘制旗标参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawFlag(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateFlag(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制阵型
   * @param {PlotFormation} options - 绘制阵型参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawFormation(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateFormation(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 绘制文本
   * @param {PlotLabel} options - 绘制文本参数,不传参为{}
   * @param {entityCallback} callback 回调函数,Entity对象,参照Cesium
   */
  DrawLabel(options, callback) {
    let handler = resetGlobeHandler(this._viewer)
    CreateLabel(this._viewer, handler, this._results, options, callback)
  }

  /**
   * 清除所有标绘对象
   */
  removeAll() {
    removeEntity(this._viewer, this._results)
    this._results = this._viewer.entities.add(new Cesium.Entity())
  }
  /**
   * 移除指定id的标绘对象
   * @param {string} id 待移除对象id
   * @returns {Entity} 移除后的Entity父元素
   */
  removeById(id) {
    const index = this._results._children.findIndex((ele) => ele.id === id)
    if (index < 0) return
    this._viewer.entities.removeById(id)
    this._results._children.splice(index, 1)
    return this._results
  }

  /**
   * 移除指定标绘对象
   * @param {Entity} item 待移除对象
   * @returns {Entity} 移除后的Entity父元素
   */
  remove(item) {
    const id = item.id
    return this.removeById(id)
  }
}
export default MilitaryPlotting