import createTooltip from "./tooltip.js";
import {
  CesiumToSuperMap
} from "./tools.js";
export default {
  queryUrl: 'https://yeepms.yeec.com.cn/iserver/services/map-sxgk/rest/maps/hnyy_geoquery',
  dataService: 'https://yeepms.yeec.com.cn/iserver/services/data-sxgk/rest/data',
  g_tooltips: createTooltip(document.body),
  g_drawEntityCollection: new Cesium.CustomDataSource("drawPolygon"),
  concatFields: function () {
    let pointFileds = this.g_pointFields;
    let fields = [];
    for (let field in pointFileds) {
      fields.push(field);
    }
    let lineFields = this.g_lineFields;
    for (let field2 in lineFields) {
      if (fields.indexOf(field2) == -1)
        fields.push(field2);
    }
    return fields;
  },

  //  清除查询绘制图形
  clearDrawGraphics: function (viewer) {
    let g_handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
    if (this.g_drawEntityCollection) {
      this.g_drawEntityCollection.entities.removeAll();
      viewer.dataSources.remove(this.g_drawEntityCollection, true);
    }
    if (Cesium.defined(g_handler)) {
      g_handler.destroy();
      g_handler = null;
    }
    this.g_tooltips.setVisible(false);
  },

  /**
   * 该方法用于将cesium三维面缓冲区转换为iserver查询需使用的面图形
   * @param ellipseBuffer 缓冲区
   */
  converCesiumToSuperMapEllipse: function (ellipseBuffer) {
    if (!Cesium.defined(ellipseBuffer)) {
      throw undefined;
    }
    const ellipse = ellipseBuffer.ellipse;
    const time = Cesium.JulianDate.now();
    const positions = Cesium.EllipseGeometryLibrary.computeEllipsePositions({
      center: ellipseBuffer.position.getValue(time),
      semiMajorAxis: ellipse.semiMajorAxis.getValue(time),
      semiMinorAxis: ellipse.semiMinorAxis.getValue(time),
      rotation: 0.0,
      granularity: 0.005
    }, false, true);
    const positionFlat = positions.outerPositions;
    const length = positions.outerPositions.length / 3;
    const posArray = [];
    for (let i = 0; i < length; i++) {
      posArray[i] = Cesium.Cartesian3.fromArray(positionFlat, i * 3);
    }
    return {
      positions: posArray
    };
  },

  // 笛卡尔坐标转换为投影坐标系
  conver84ToSupermap: function (obj = {
    positions: Cesium.Cartesian3
  }) {
    return CesiumToSuperMap.convertPolygon(Cesium, SuperMap, obj);
  },

  //  清除查询绘制图形
  destroy: function (viewer) {
    let g_handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);

    this.destroyLocation(viewer);
    if (Cesium.defined(g_handler)) {
      g_handler.destroy();
      g_handler = null;
    }
    this.clearDrawGraphics(viewer);
    this.g_tooltips.setVisible(false);
  },

  //  清除定位标识
  destroyLocation: function (viewer) {
    let locationEntities = Cesium.Entity;
    let locatFeatures = [{
      layer: Cesium.S3MTilesLayer,
      ids: []
    }];
    if (locationEntities.length > 0) {
      locationEntities.forEach(item => {
        viewer.entities.remove(item);
      });
      locationEntities = [];
    }
    if (locatFeatures.length > 0) {
      locatFeatures.forEach(item => {
        item.layer && item.layer.removeObjsColor(item.ids);
      })
      locatFeatures = [];
    }
  },

  /**
   * 画线
   * @param viewer 
   * @param callback 
   */
  drawPolyline: function (viewer = Cesium.Viewer, callback = Function) {
    let g_handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
    const tooltips = createTooltip(document.body);

    let isDrawing = false;
    let positions = [];
    let polyline = null;
    g_handler.setInputAction(e => {
      const position = viewer.scene.pickPosition(e.position);
      if (!isDrawing) {
        positions.push(position);
        isDrawing = true;
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    g_handler.setInputAction(e => {
      if (isDrawing) {
        const position = viewer.scene.pickPosition(e.endPosition);
        if (positions.length === 1) {
          positions.push(position);
          polyline = viewer.entities.add({
            polyline: {
              positions: new Cesium.CallbackProperty(() => {
                return positions;
              }, false),
              width: 2.0,
              material: Cesium.Color.DODGERBLUE
            }
          });
        } else {
          if (Cesium.defined(polyline)) {
            positions.pop();
            positions.push(position);
          }
        }
      }
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
    g_handler.setInputAction(e => {
      tooltips.setVisible(false);
      if (!isDrawing) return;
      if (positions.length === 2) {
        const position = viewer.scene.pickPosition(e.position);
        if (Cesium.defined(polyline)) {
          positions.pop();
          positions.push(position);
        }
        isDrawing = false;
        g_handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
        g_handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
        g_handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
        g_handler.destroy();
        g_handler = null;
        callback(polyline);
      }
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  },

  /**
   * 画圆
   * @param callback 回调函数
   */
  drawCircle: function (viewer = Cesium.Viewer, callback) {
    let isDrawing = false;
    let center = null;
    let otherpoint = null;
    let circle = null;
    let line = null;
    let g_handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);

    g_handler.setInputAction(e => {
      if (!isDrawing) {
        const position = viewer.scene.pickPosition(e.position);
        center = position;
        isDrawing = true;
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    g_handler.setInputAction(e => {
      this.g_tooltips.showAt(e.endPosition, "<p>左键单击绘制，右键单击结束绘制</p>");
      if (isDrawing) {
        let evposition = viewer.scene.pickPosition(e.endPosition);
        const cartegra = Cesium.Cartographic.fromCartesian(evposition);
        const position = Cesium.Cartesian3.fromRadians(cartegra.longitude, cartegra.latitude,
          Cesium.Cartographic.fromCartesian(center).height);
        if (Cesium.defined(center)) {
          if (Cesium.defined(circle)) {
            otherpoint = position;
          } else {
            otherpoint = position;
            circle = this.g_drawEntityCollection.entities.add({
              position: center,
              ellipse: {
                semiMajorAxis: new Cesium.CallbackProperty(() => {
                  return Cesium.Cartesian3.distance(center, otherpoint);
                }, false),
                semiMinorAxis: new Cesium.CallbackProperty(() => {
                  return Cesium.Cartesian3.distance(center, otherpoint);
                }, false),
                granularity: Cesium.Math.RADIANS_PER_DEGREE / 10,
                height: Cesium.Cartographic.fromCartesian(center).height,
                fill: true,
                material: Cesium.Color.DEEPSKYBLUE.withAlpha(0.1),
                outline: true,
                outlineColor: Cesium.Color.DODGERBLUE,
                outlineWidth: 1.0
              }
            })
            line = this.g_drawEntityCollection.entities.add({
              position: new Cesium.CallbackProperty(() => {
                return Cesium.Cartesian3.lerp(center, otherpoint, 0.5, new Cesium
                  .Cartesian3());
              }, false),
              orientation: new Cesium.CallbackProperty(() => {
                const heading = this.getHeading(center, otherpoint);
                const hpr = new Cesium.HeadingPitchRoll(heading, 0, 0);
                return Cesium.Quaternion.fromHeadingPitchRoll(hpr);
              }, false),
              polyline: {
                positions: new Cesium.CallbackProperty(() => {
                  return [center, otherpoint];
                }, false),
                width: 2,
                material: Cesium.Color.DODGERBLUE
              },
              label: {
                text: new Cesium.CallbackProperty(() => {
                  return Cesium.Cartesian3.distance(center, otherpoint).toFixed(1) +
                    "m";
                }, false),
                style: Cesium.LabelStyle.FILL,
                font: "20px sans-serif",
                pixelOffset: new Cesium.Cartesian2(0, -20),
                fillColor: Cesium.Color.WHITE,
                outlineColor: Cesium.Color.WHITE,
                outlineWidth: 1.0
              }
            })
            viewer.dataSources.add(this.g_drawEntityCollection);
          }
        }
      }
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
    g_handler.setInputAction(e => {
      this.g_tooltips.setVisible(false);
      if (!isDrawing) return;
      if (Cesium.defined(center)) {
        let evposition = viewer.scene.pickPosition(e.position);
        const cartegra = Cesium.Cartographic.fromCartesian(evposition);
        const position = Cesium.Cartesian3.fromRadians(cartegra.longitude, cartegra.latitude,
          Cesium.Cartographic.fromCartesian(center).height);
        //const radius=Cesium.Cartesian3.distance(center,otherpoint);
        if (Cesium.defined(circle)) {
          otherpoint = position;
        }
        callback(circle);
        isDrawing = false;
        g_handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
        g_handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
        g_handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
        g_handler.destroy();
        g_handler = null;
      }
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  },

  /**
   * 画面
   * @param callback 回调函数
   */
  drawPolygon: function (viewer = Cesium.Viewer, callback) {
    this.g_handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
        this.g_tooltips = createTooltip(document.querySelector(AppX.appConfig.mainContainer));
        //this.g_drawHandler = handler;
        let isDrawing = false;
        let positions = [];
        let realPositions = [];
        let polygon = undefined;
        //客户要求贴地
        polygon = new Cesium.Entity({
            name: "HelperPolygon",
            polyline: {
                positions: new Cesium.CallbackProperty(function (time, result) {
                    if (realPositions.length <3) {
                        return realPositions;
                    } else {
                        const line = realPositions.map(item =>{return item;});
                        line.push(line[0]);
                        return line;
                    }
                }, false),
                material: Cesium.Color.DODGERBLUE,
                followSurface: false,
                clampToGround: true,
                width: 2.0,
                show: new Cesium.CallbackProperty(function (time, result) {
                    return realPositions.length >= 2;
                }, false)
            },
            polygon: {
                hierarchy: new Cesium.CallbackProperty(function (time, result) {
                    return new Cesium.PolygonHierarchy(realPositions);
                }, false),
                material: Cesium.Color.DEEPSKYBLUE.withAlpha(0.1),
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                perPositionHeight: false,
                outline: false,
                outlineColor: Cesium.Color.ORANGERED
            }
        })
        this.g_drawEntityCollection.entities.add(polygon);
        viewer.dataSources.add(this.g_drawEntityCollection);
        this.g_handler.setInputAction(e => {
            const position = viewer.scene.pickPosition(e.position);
            positions.push(position);
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
        this.g_handler.setInputAction(e => {
            this.g_tooltips.showAt(e.endPosition, "<p>左键单击绘制，右键单击结束绘制</p>");
            const position = viewer.scene.pickPosition(e.endPosition);
            realPositions=positions.concat([position]);
        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
        this.g_handler.setInputAction(e => {
            this.g_tooltips.remove();
            const position = viewer.scene.pickPosition(e.position);
            
            positions.push(position);
            if(positions.length>=3){
                callback(polygon);
            }else{
                this.clearDrawGraphics(viewer);
            }
            this.g_handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
            this.g_handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
            this.g_handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
            this.g_handler.destroy();
            this.g_handler = null;
        }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  },
  /**
   * 画矩形
   * @param callback 回调函数
   */
  drawRect: function (container,viewer = Cesium.Viewer, callback) {
    const scene = viewer.scene;
    const tooltip = createTooltip(container);
    const _selectedObjs=null;
    function DrawRectHandler(dom) {
        let startPoint,
            self = this,
            isShiftAndLeftDown = false,
            handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas),
            removalFunctions = [],
            rect = new Rect(dom);
        this.isDestroyed = false;
        this.activeEvt = new Cesium.Event();
        this.cancelEvt = new Cesium.Event();
        this.movingEvt = new Cesium.Event();
        this.drawEvt = new Cesium.Event();

        // div框
        function Rect(parentDom) {
            this.rect = document.createElement('div');
            this.rect.style.visibility = 'hidden';
            parentDom.appendChild(this.rect);
            this.leftTopPoint = new Cesium.Cartesian2();
            this.rightBottomPoint = new Cesium.Cartesian2();
            this.leftBottomPoint=new Cesium.Cartesian2();
            this.rightTopPoint=new Cesium.Cartesian2();
            Rect.prototype.setPosition = function (startPoint, endPosition) {
                let w = endPosition.x - startPoint.x;
                let h = endPosition.y - startPoint.y;
                let left, top, width, height;
                if (w < 0) {
                    left = endPosition.x;
                    width = -w;
                } else {
                    left = startPoint.x;
                    width = w;
                }
                if (h < 0) {
                    top = endPosition.y;
                    height = -h;
                } else {
                    top = startPoint.y;
                    height = h;
                }
                this.leftTopPoint = new Cesium.Cartesian2(left, top);
                this.rightBottomPoint = new Cesium.Cartesian2(left + width, top + height);
                this.leftBottomPoint=new Cesium.Cartesian2(left,top + height);
                this.rightTopPoint=new Cesium.Cartesian2(left+width,top);
                this.rect.style = `position:absolute;top:${top}px;left:${left}px;width:${width}px;height:${height}px;border:2px dashed #333;`;
                this.setVisible(true);
            }
            Rect.prototype.setVisible = function (isVisible) {
                this.rect.style.visibility = isVisible ? 'visible' : 'hidden';
            }
            Rect.prototype.getRectPoint = function () {
                return {
                    leftTopPoint: this.leftTopPoint,
                    rightBottomPoint: this.rightBottomPoint,
                    leftBottomPoint:this.leftBottomPoint,
                    rightTopPoint:this.rightTopPoint
                }
            }
            Rect.prototype.destroy = function () {
                dom.removeChild(rect);
                this.rect = null;
            }
        }
        // 开关相机控制
        function setCameraCtrl(isActive) {
            let cameraCtrl = scene.screenSpaceCameraController;
            cameraCtrl.enableInputs =isActive;
        }
        // 鼠标cursor控制
        function toggleCursorStyle(isActive) {
            if (isActive) {
                viewer.enableCursorStyle = false;
                viewer._element.style.cursor = '';
                dom.style.cursor = 'default';
            } else {
                viewer.enableCursorStyle = true;
            }
        }
        // 初始化事件处理
        function initEvent() {
            handler.setInputAction(function (e) {
                isShiftAndLeftDown = true;
                startPoint = new Cesium.Cartesian2(e.position.x, e.position.y);
            }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
            handler.setInputAction(function (e) {
                
                let endPosition = e.endPosition;
                self.activeEvt.raiseEvent(endPosition);
                if (!isShiftAndLeftDown) return;
                rect.setPosition(startPoint, endPosition);
                rect.setVisible(true);
                self.movingEvt.raiseEvent(rect.getRectPoint());
            }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
            handler.setInputAction(function (e) {
                isShiftAndLeftDown = false;
                rect.setVisible(false);
                self.drawEvt.raiseEvent(rect.getRectPoint());
            }, Cesium.ScreenSpaceEventType.LEFT_UP);
            handler.setInputAction(function (e) {
                rect.setVisible(false);
                self.deactivate();
            }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
        }

        // 移除事件监听
        function removeEvent() {
            handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOWN);
            handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
            handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_UP);
        }

        DrawRectHandler.prototype.destroy = function () {
            if (this.isDestroyed) return;
            setCameraCtrl(true);
            removeEvent();
            for (let i = 0, j = removalFunctions.length; i < j; i++) {
                removalFunctions[i]();
            }
            handler.destroy();
            rect.destroy();
            rect = null;
            this.isDestroyed = true;
        }
        DrawRectHandler.prototype.activate = function () {
            if (this.isDestroyed) return;
            setCameraCtrl(false);
            toggleCursorStyle(true);
            initEvent();
        }
        DrawRectHandler.prototype.deactivate = function () {
            if (this.isDestroyed) return;
            tooltip.setVisible(false);
            setCameraCtrl(true);
            toggleCursorStyle(false);
            removeEvent();
        }
    }
    let drawRect = new DrawRectHandler(container);
    // res为框的左上点与右下点的相对于给定dom节点的坐标
    drawRect.drawEvt.addEventListener(function (res) {
        tooltip.setVisible(false);
        drawRect.deactivate();
        callback(res);
    });
    drawRect.movingEvt.addEventListener(function (res) {
        tooltip.showAt(res.rightBottomPoint,
            '<p>松开鼠标左键以结束选择区域,鼠标右键取消操作</p>'
        );
    });
    drawRect.activeEvt.addEventListener(function (position) {
        tooltip.showAt(position,
            '<p>点击鼠标左键以开始选择区域,鼠标右键取消操作</p>'
        );
    });
    drawRect.cancelEvt.addEventListener(function () {
        tooltip.setVisible(false);
    })
    return drawRect;
  },

  /**
   * 该方法用于获取两点连线的方位角
   * @param pointA 起点A
   * @param pointB 终点B
   * @returns 弧度值
   */
  getHeading: function (pointA, pointB) {
    const transform = Cesium.Transforms.eastNorthUpToFixedFrame(pointA);
    const positionvector = Cesium.Cartesian3.subtract(pointB, pointA, new Cesium.Cartesian3());
    const vector = Cesium.Matrix4.multiplyByPointAsVector(Cesium.Matrix4.inverse(transform,
      new Cesium.Matrix4()), positionvector, new Cesium.Cartesian3());
    const direction = Cesium.Cartesian3.normalize(vector, new Cesium.Cartesian3());
    const heading = Math.atan2(direction.y, direction.x) - Cesium.Math.PI_OVER_TWO;
    return Cesium.Math.TWO_PI - Cesium.Math.zeroToTwoPi(heading);
  },

  /**
   * 属性查询（查询地图服务）
   * @param options 
   */
  queryMapByAttribute: function (options) {
    let filterParams = [];
    filterParams = options.datasetNames.map(item => {
      return new SuperMap.REST.FilterParameter({
        name: item,
        attributeFilter: options.whereclause,
        groupBy: options.groupBy,
        orderBy: options.orderBy,
        fields: options.fields
      });
    });
    const sqlParams = new SuperMap.REST.QueryBySQLParameters({
      queryParams: filterParams,
      queryOption: !options.queryOption ? SuperMap.REST.QueryOption.ATTRIBUTEANDGEOMETRY : options.queryOption
    });
    const sqlService = new SuperMap.REST.QueryBySQLService(options.url, {
      eventListeners: {
        processCompleted: options.completed,
        processFailed: options.failed
      }
    });
    sqlService.processAsync(sqlParams);
  },

  /**
   * 空间查询（查询地图服务）
   * @param options 
   */
  queryMapByGeometry: function (options) {
    let filterParams = [];
    filterParams = options.datasetNames.map(item => {
      return new SuperMap.REST.FilterParameter({
        name: item,
        attributeFilter: options.whereclause,
        groupBy: options.groupBy,
        orderBy: options.orderBy,
        fields: options.fields
      });
    });
    const geoParams = new SuperMap.REST.QueryByGeometryParameters({
      geometry: options.geometry,
      queryParams: filterParams,
      returnContent: true,
      spatialQueryMode: !options.spatialMode ? SuperMap.REST.SpatialQueryMode.INTERSECT : options.spatialMode,
      queryOption: !options.queryOption ? SuperMap.REST.QueryOption.ATTRIBUTEANDGEOMETRY : options.queryOption
    });
    const queryService = new SuperMap.REST.QueryByGeometryService(options.url, {
      eventListeners: {
        processCompleted: options.completed,
        processFailed: options.failed
      }
    });
    queryService.processAsync(geoParams);
  },

  /**
   * 该方法用于属性查询(查询数据服务)
   * @param options 
   */
  queryByAttribute: function (options = {
    url: '',
    datasetNames: [],
    whereclause: '',
    fields: [],
    completed: Function,
    failed: Function
  }) {
    const filterparams = new SuperMap.REST.FilterParameter({
      attributeFilter: options.whereclause,
      fields: options.fields
    });
    const sqlParams = new SuperMap.REST.GetFeaturesBySQLParameters({
      queryParameter: filterparams,
      datasetNames: options.datasetNames,
      toIndex: -1
    });
    const queryservice = new SuperMap.REST.GetFeaturesBySQLService(options.url, {
      eventListeners: {
        processCompleted: options.completed,
        processFailed: options.failed
      }
    });
    queryservice.processAsync(sqlParams);
  },

  g_pointFields: {
    "SMID": {
      alianame: "SmID",
      visible: false
    },
    "PIPE_ID": {
      alianame: "部件标识码",
      visible: true
    },
    "ROAD_NAME": {
      alianame: "道路名称",
      visible: true
    },
    "CODE": {
      alianame: "编码",
      visible: false
    },
    "PIPE_CATEGORY": {
      alianame: "类别",
      visible: true
    },
    "TYPE": {
      alianame: "类型",
      visible: true
    },
    "DESIGN_DEPTH": {
      alianame: "埋深",
      visible: true
    }
  },
  g_lineFields: {
    "SMID": {
      alianame: "SmID",
      visible: false
    },
    "PIPE_ID": {
      alianame: "部件标识码",
      visible: true
    },
    "ROAD_NAME": {
      alianame: "道路名称",
      visible: true
    },
    "CODE": {
      alianame: "编码",
      visible: false
    },
    "PIPE_CATEGORY": {
      alianame: "类别",
      visible: true
    },
    "TYPE": {
      alianame: "类型",
      visible: true
    },
    "DESIGN_IN_DEEP": {
      alianame: "起点埋深",
      visible: true
    },
    "DESIGN_OUT_DEEP": {
      alianame: "终点埋深",
      visible: true
    },
    "SHAPE_DATA1": {
      alianame: "管径",
      visible: true
    },
  },
  pipe: [
    {
        //名称
        "title": "设计-污水管线",
        //三维场景名称
        "name": "NETWORK_SJ_PSWS@sxgk#1",
        //二维地图服务
        "mapname": "TF_SJ_PSWS_PIPE_B@sxgk",
        //数据服务数据源名称
        "datasource": "sxgk",
        //数据服务数据集名称
        "dataset": "NETWORK_SJ_PSWS",
        //数据类型
        "geometryType": "line",
        //管线类型
        "pipeType": "SJ",
        //线段颜色
        //"lineColor": [76, 57, 38],
        "lineColor": [255, 54, 54],
        //
        "origindataset": "TF_SJ_PSWS_PIPE_B",
        "threeDDateset": "TF_SJ_PSWS_PIPE_B_3D"
    },
    {
        "title": "设计-污水管点",
        "name": "NETWORK_SJ_PSWS_Node@sxgk#1",
        "mapname": "TF_SJ_PSWS_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_SJ_PSWS_NODE_B_3D",
        "tubewelldataset": "TF_SJ_PSWS_JG_B_3D",
        "geometryType": "point",
        "pipeType": "SJ",
        "origindataset": "TF_SJ_PSWS_NODE_B",
        "threeDDateset": "TF_SJ_PSWS_NODE_B_3D",
        "ADJUNCT": [
            // "NETWORK_JSJS_Node@sxgk#2",//阀门
            // "NETWORK_JSJS_Node@sxgk#3",//水表
            // "NETWORK_JSJS_Node@sxgk#4"//消防栓
        ],
        "WELL": [
            "TF_SJ_PSWS_JG_B_3D@sxgk#1",
            "TF_SJ_PSWS_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "设计-雨水管线",
        "name": "NETWORK_SJ_PSYS@sxgk#1",
        "mapname": "TF_SJ_PSYS_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_SJ_PSYS",
        "geometryType": "line",
        "pipeType": "SJ",
        "lineColor": [0, 255, 255],
        "origindataset": "TF_SJ_PSYS_PIPE_B",
        "threeDDateset": "TF_SJ_PSYS_PIPE_B_3D"
    },
    {
        "title": "设计-雨水管点",
        "name": "NETWORK_SJ_PSYS_Node@sxgk#1",
        "mapname": "TF_SJ_PSYS_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_SJ_PSYS_NODE_B_3D",
        "tubewelldataset": "TF_SJ_PSYS_JG_B_3D",
        "geometryType": "point",
        "pipeType": "SJ",
        "origindataset": "TF_SJ_PSYS_NODE_B",
        "threeDDateset": "TF_SJ_PSYS_NODE_B_3D",
        "ADJUNCT": [],
        "WELL": [
            "TF_SJ_PSYS_JG_B_3D@sxgk#1",
            "TF_SJ_PSYS_JG_B_3D@sxgk#2"
        ]
    }, {
        "title": "设计-雨污合流管线",
        "name": "NETWORK_SJ_PSHS@sxgk#1",
        "mapname": "TF_SJ_PSHS_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_SJ_PSHS",
        "geometryType": "line",
        "pipeType": "SJ",
        "lineColor": [76, 57, 38],
        "origindataset": "TF_SJ_PSHS_PIPE_B",
        "threeDDateset": "TF_SJ_PSHS_PIPE_B_3D"
    },
    {
        "title": "设计-雨污合流管点",
        "name": "NETWORK_SJ_PSHS_Node@sxgk#1",
        "mapname": "TF_SJ_PSHS_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_SJ_PSHS_NODE_B_3D",
        "tubewelldataset": "TF_SJ_PSHS_JG_B_3D",
        "geometryType": "point",
        "pipeType": "SJ",
        "origindataset": "TF_SJ_PSHS_NODE_B",
        "threeDDateset": "TF_SJ_PSHS_NODE_B_3D",
        "ADJUNCT": [],
        "WELL": [
            "TF_SJ_PSHS_JG_B_3D@sxgk#1",
            "TF_SJ_PSHS_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-输水管线",
        "name": "NETWORK_PC_JSSS@sxgk#1",
        "mapname": "TF_PC_JSSS_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_JSSS",
        "geometryType": "line",
        "pipeType": "PC",
        "lineColor": [0, 255, 255],
        "origindataset": "TF_PC_JSSS_PIPE_B",
        "threeDDateset": "TF_PC_JSSS_PIPE_B_3D"
    },
    {
        "title": "存量-输水管点",
        "name": "TF_PC_JSSS_JG_B_3D@sxgk#1",
        "mapname": "TF_PC_JSSS_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_JSSS_NODE_B_3D",
        "tubewelldataset": "TF_PC_JSSS_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_JSSS_NODE_B",
        "threeDDateset": "TF_PC_JSSS_NODE_B_3D",
        "ADJUNCT": [
        ],
        "WELL": [
            "TF_PC_JSSS_JG_B_3D@sxgk#1",
            "TF_PC_JSSS_JG_B_3D@sxgk#2"
        ]
    },
    {
        //名称
        "title": "存量-污水管线",
        //三维场景名称
        "name": "NETWORK_PC_PSWS@sxgk#1",
        //二维地图服务
        "mapname": "TF_PC_PSWS_PIPE_B@sxgk",
        //数据服务数据源名称
        "datasource": "sxgk",
        //数据服务数据集名称
        "dataset": "NETWORK_PC_PSWS",
        //数据类型
        "geometryType": "line",
        //管线类型
        "pipeType": "PC",
        //线段颜色
        //"lineColor": [76, 57, 38],
        "lineColor": [255, 54, 54],
        //
        "origindataset": "TF_PC_PSWS_PIPE_B",
        "threeDDateset": "TF_PC_PSWS_PIPE_B_3D"
    },
    {
        "title": "存量-污水管点",
        "name": "NETWORK_PC_PSWS_Node@sxgk#1",
        "mapname": "TF_PC_PSWS_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_PSWS_NODE_B_3D",
        "tubewelldataset": "TF_PC_PSWS_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_PSWS_NODE_B",
        "threeDDateset": "TF_PC_PSWS_NODE_B_3D",
        "ADJUNCT": [
        ],
        "WELL": [
            "TF_PC_PSWS_JG_B_3D@sxgk#1",
            "TF_PC_PSWS_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-雨水管线",
        "name": "NETWORK_PC_PSYS@sxgk#1",
        "mapname": "TF_PC_PSYS_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_PSYS",
        "geometryType": "line",
        "pipeType": "PC",
        "lineColor": [0, 255, 255],
        "origindataset": "TF_PC_PSYS_PIPE_B",
        "threeDDateset": "TF_PC_PSYS_PIPE_B_3D"
    },
    {
        "title": "存量-雨水管点",
        "name": "NETWORK_PC_PSYS_Node@sxgk#1",
        "mapname": "TF_PC_PSYS_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_PSYS_NODE_B_3D",
        "tubewelldataset": "TF_PC_PSYS_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_PSYS_NODE_B",
        "threeDDateset": "TF_PC_PSYS_NODE_B_3D",
        "ADJUNCT": [],
        "WELL": [
            "TF_PC_PSYS_JG_B_3D@sxgk#1",
            "TF_PC_PSYS_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-雨污合流管线",
        "name": "NETWORK_PC_PSHS@sxgk#1",
        "mapname": "TF_PC_PSHS_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_PSHS",
        "geometryType": "line",
        "pipeType": "PC",
        "lineColor": [76, 57, 38],
        "origindataset": "TF_PC_PSHS_PIPE_B",
        "threeDDateset": "TF_PC_PSHS_PIPE_B_3D"
    },
    {
        "title": "存量-雨污合流管点",
        "name": "NETWORK_PC_PSHS_Node@sxgk#1",
        "mapname": "TF_PC_PSHS_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_PSHS_NODE_B_3D",
        "tubewelldataset": "TF_PC_PSHS_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_PSHS_NODE_B",
        "threeDDateset": "TF_PC_PSHS_NODE_B_3D",
        "ADJUNCT": [

        ],
        "WELL": [
            "TF_PC_PSHS_JG_B_3D@sxgk#1",
            "TF_PC_PSHS_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-供电管线",
        "name": "NETWORK_PC_DLGD@sxgk#1",
        "mapname": "TF_PC_DLGD_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_DLGD",
        "geometryType": "line",
        "pipeType": "PC",
        "lineColor": [255, 0, 0],
        "origindataset": "TF_PC_DLGD_PIPE_B",
        "threeDDateset": "TF_PC_DLGD_PIPE_B_3D"
    },
    {
        "title": "存量-供电管点",
        "name": "NETWORK_PC_DLGD_Node@sxgk#1",
        "mapname": "TF_PC_DLGD_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_DLGD_NODE_B_3D",
        "tubewelldataset": "TF_PC_DLGD_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_DLGD_NODE_B",
        "threeDDateset": "TF_PC_DLGD_NODE_B_3D",
        "ADJUNCT": [

        ],
        "WELL": [
            "TF_PC_DLGD_JG_B_3D@sxgk#1",
            "TF_PC_DLGD_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-燃气管线",
        "name": "NETWORK_PC_RQTQ@sxgk#1",
        "mapname": "TF_PC_RQTQ_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_RQTQ",
        "geometryType": "line",
        "pipeType": "PC",
        "lineColor": [255, 0, 255],
        "origindataset": "TF_PC_RQTQ_PIPE_B",
        "threeDDateset": "TF_PC_RQTQ_PIPE_B_3D"
    },
    {
        "title": "存量-燃气管点",
        "name": "NETWORK_PC_RQTQ_Node@sxgk#1",
        "mapname": "TF_PC_RQTQ_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_RQTQ_NODE_B_3D",
        "tubewelldataset": "TF_PC_RQTQ_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_RQTQ_NODE_B",
        "threeDDateset": "TF_PC_RQTQ_NODE_B_3D",
        "ADJUNCT": [
            "NETWORK_PC_RQTQ_Node@sxgk#2",
            "NETWORK_PC_RQTQ_Node@sxgk#3",
            "NETWORK_PC_RQTQ_Node@sxgk#4"
        ],
        "WELL": [
            "TF_PC_RQTQ_JG_B_3D@sxgk#1",
            "TF_PC_RQTQ_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-路灯管线",
        "name": "NETWORK_PC_DLLD@sxgk#1",
        "mapname": "TF_PC_DLLD_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_DLLD",
        "geometryType": "line",
        "pipeType": "PC",
        "lineColor": [255, 0, 0],
        "origindataset": "TF_PC_DLLD_PIPE_B",
        "threeDDateset": "TF_PC_DLLD_PIPE_B_3D"
    },
    {
        "title": "存量-路灯管点",
        "name": "NETWORK_PC_DLLD_Node@sxgk#1",
        "mapname": "TF_PC_DLLD_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_DLLD_NODE_B_3D",
        "tubewelldataset": "TF_PC_DLLD_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_DLLD_NODE_B",
        "threeDDateset": "TF_PC_DLLD_NODE_B_3D",
        "ADJUNCT": [

        ],
        "WELL": [
            "TF_PC_DLLD_JG_B_3D@sxgk#1",
            "TF_PC_DLLD_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-电视管线",
        "name": "NETWORK_PC_TXDS@sxgk#1",
        "mapname": "TF_PC_TXDS_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_TXDS",
        "geometryType": "line",
        "pipeType": "PC",
        "lineColor": [0, 255, 0],
        "origindataset": "TF_PC_TXDS_PIPE_B",
        "threeDDateset": "TF_PC_TXDS_PIPE_B_3D"
    },
    {
        "title": "存量-电视管点",
        "name": "NETWORK_PC_TXDS_Node@sxgk#1",
        "mapname": "TF_PC_TXDS_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_TXDS_NODE_B_3D",
        "tubewelldataset": "TF_PC_TXDS_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_TXDS_NODE_B",
        "threeDDateset": "TF_PC_TXDS_NODE_B_3D",
        "ADJUNCT": [
        ],
        "WELL": [
            "TF_PC_TXDS_JG_B_3D@sxgk#1",
            "TF_PC_TXDS_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-电信管线",
        "name": "NETWORK_PC_TXDX@sxgk#1",
        "mapname": "TF_PC_TXDX_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_TXDX",
        "geometryType": "line",
        "pipeType": "PC",
        "lineColor": [0, 255, 0],
        "origindataset": "TF_PC_TXDX_PIPE_B",
        "threeDDateset": "TF_PC_TXDX_PIPE_B_3D"
    },
    {
        "title": "存量-电信管点",
        "name": "NETWORK_PC_TXDX_Node@sxgk#1",
        "mapname": "TF_PC_TXDX_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_TXDX_NODE_B_3D",
        "tubewelldataset": "TF_PC_TXDX_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_TXDX_NODE_B",
        "threeDDateset": "TF_PC_TXDX_NODE_B_3D",
        "ADJUNCT": [
            "NETWORK_PC_TXDX_Node@sxgk#2"//接线箱
        ],
        "WELL": [
            "TF_PC_TXDX_JG_B_3D@sxgk#1",
            "TF_PC_TXDX_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-监控管线",
        "name": "NETWORK_PC_TXJK@sxgk#1",
        "mapname": "TF_PC_TXJK_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_TXJK",
        "geometryType": "line",
        "hasTube": true,//是否有套管,
        "tubeName": "NETWORK_PC_TXJK@sxgk#2",//套管图层名
        "pipeType": "PC",
        "lineColor": [0, 255, 0],
        "origindataset": "TF_PC_TXJK_PIPE_B",
        "threeDDateset": "TF_PC_TXJK_PIPE_B_3D"
    },
    {
        "title": "存量-监控管点",
        "name": "NETWORK_PC_TXJK_Node@sxgk#1",
        "mapname": "TF_PC_TXJK_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_TXJK_NODE_B_3D",
        "tubewelldataset": "TF_PC_TXJK_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_TXJK_NODE_B",
        "threeDDateset": "TF_PC_TXJK_NODE_B_3D",
        "ADJUNCT": [
        ],
        "WELL": [
            "TF_PC_TXJK_JG_B_3D@sxgk#1",
            "TF_PC_TXJK_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-电话管线",
        "name": "NETWORK_PC_TXDH@sxgk#1",
        "mapname": "TF_PC_TXDH_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_TXDH",
        "geometryType": "line",
        "hasTube": true,//是否有套管,
        "tubeName": "NETWORK_PC_TXDH@sxgk#2",//套管图层名
        "pipeType": "PC",
        "lineColor": [0, 255, 0],
        "origindataset": "TF_PC_TXDH_PIPE_B",
        "threeDDateset": "TF_PC_TXDH_PIPE_B_3D"
    },
    {
        "title": "存量-电话管点",
        "name": "NETWORK_PC_TXDH_Node@sxgk#1",
        "mapname": "TF_PC_TXDH_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_TXDH_NODE_B_3D",
        "tubewelldataset": "TF_PC_TXDH_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_TXDH_NODE_B",
        "threeDDateset": "TF_PC_TXDH_NODE_B_3D",
        "ADJUNCT": [
        ],
        "WELL": [
            "TF_PC_TXDH_JG_B_3D@sxgk#1",
            "TF_PC_TXDH_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-信息网络管线",
        "name": "NETWORK_PC_TXXX@sxgk#1",
        "mapname": "TF_PC_TXXX_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_TXXX",
        "geometryType": "line",
        "hasTube": true,//是否有套管,
        "tubeName": "NETWORK_PC_TXXX@sxgk#2",//套管图层名
        "pipeType": "PC",
        "lineColor": [0, 255, 0],
        "origindataset": "TF_PC_TXXX_PIPE_B",
        "threeDDateset": "TF_PC_TXXX_PIPE_B_3D"
    },
    {
        "title": "存量-信息网络管点",
        "name": "NETWORK_PC_TXXX_Node@sxgk#1",
        "mapname": "TF_PC_TXXX_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_TXXX_NODE_B_3D",
        "tubewelldataset": "TF_PC_TXXX_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_TXXX_NODE_B",
        "threeDDateset": "TF_PC_TXXX_NODE_B_3D",
        "ADJUNCT": [
        ],
        "WELL": [
            "TF_PC_TXXX_JG_B_3D@sxgk#1",
            "TF_PC_TXXX_JG_B_3D@sxgk#2"
        ]
    },
    {
        "title": "存量-综合管线",
        "name": "NETWORK_PC_ZH@sxgk#1",
        "mapname": "TF_PC_ZH_PIPE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "NETWORK_PC_ZH",
        "geometryType": "line",
        "hasTube": true,//是否有套管,
        "tubeName": "NETWORK_PC_ZH@sxgk#2",//套管图层名
        "pipeType": "PC",
        "lineColor": [0, 0, 0],
        "origindataset": "TF_PC_ZH_PIPE_B",
        "threeDDateset": "TF_PC_ZH_PIPE_B_3D"
    },
    {
        "title": "存量-综合管点",
        "name": "NETWORK_PC_ZH_Node@sxgk#1",
        "mapname": "TF_PC_ZH_NODE_B@sxgk",
        "datasource": "sxgk",
        "dataset": "TF_PC_ZH_NODE_B_3D",
        "tubewelldataset": "TF_PC_ZH_JG_B_3D",
        "geometryType": "point",
        "pipeType": "PC",
        "origindataset": "TF_PC_ZH_NODE_B",
        "threeDDateset": "TF_PC_ZH_NODE_B_3D",
        "ADJUNCT": [
        ],
        "WELL": [
            "TF_PC_ZH_JG_B_3D@sxgk#1",
            "TF_PC_ZH_JG_B_3D@sxgk#2"
        ]
    }
  ],

  /**
   * 该方法用于管线定位
   * @param viewer 场景视图
   * @param feature 管线数据
   * @param geometry 管线类型  point,line
   */
  location(viewer, feature, geometry, layername) {
      const flyField = layername.pipeType === "SJ" ? "CODE" : "PIPE_ID";
      const attributes = feature.attributes;
      //const geo = feature.geometry;
      let locationEntities = [];
      let locatFeatures = [{
        layer: Cesium.S3MTilesLayer,
        ids: []
      }];
      if (locationEntities.length > 0) {
          locationEntities.forEach(item => {
              viewer.entities.remove(item);
          })
          locationEntities = [];
          if (locatFeatures.length > 0) {
              locatFeatures.forEach(item => {
                  item.layer && item.layer.removeObjsColor(item.ids);

              })
              locatFeatures = [];
          }
      }
      const gl = this;
      if (geometry === "line") {
          const layer = viewer.scene.layers.find(layername.name);
          const queryComplete = (result => {
              if (result.originResult.features.length === 0) return;
              const fid = result.originResult.features[0].ID;
              //layer.setSelection(fid);
              layer.setObjsColor([fid], Cesium.Color.DARKRED);
              locatFeatures.push({ layer: layer, ids: [fid] });
              //layer.refresh();
              const geofeature = result.originResult.features[0].geometry;
              const data = result.result.features[0].data;
              const s_lon = parseFloat(geofeature.points[0].x);
              const s_lat = parseFloat(geofeature.points[0].y);
              const s_height = parseFloat(geofeature.points[0].z - 0);//this.AppX.appConfig.downDepth
              const e_lon = parseFloat(geofeature.points[1].x);
              const e_lat = parseFloat(geofeature.points[1].y);
              const e_height = parseFloat(geofeature.points[1].z - 0);//this.AppX.appConfig.downDepth
              let startPoint = Cesium.Cartographic.fromDegrees(s_lon, s_lat, s_height);
              let endPoint = Cesium.Cartographic.fromDegrees(e_lon, e_lat, e_height);
              const s_p = Cesium.Cartographic.toCartesian(startPoint);
              const e_p = Cesium.Cartographic.toCartesian(endPoint);
              // const start_board = viewer.entities.add(gl.addPointSIDBillboard(data["IN_JUNEID"], s_p));
              // const end_board = viewer.entities.add(gl.addPointSIDBillboard(data["OUT_JUNEID"], e_p));
              // this.locationEntities.push(start_board);
              // this.locationEntities.push(end_board);
              // viewer.flyTo([start_board, end_board]);

              let addEntity = function (entity) {
                  let entites = viewer.entities.add(entity);
                  locationEntities.push(entites);
                  if (locationEntities.length > 1) {
                      viewer.flyTo([locationEntities[0], locationEntities[1]]);
                  }
              };
              gl.addUnitBillboard(data["IN_JUNEID"], s_p, addEntity.bind(gl));
              gl.addUnitBillboard(data["OUT_JUNEID"], e_p, addEntity.bind(gl));
          })
          const queryFial = (error) => { console.error(error); }
          this.queryByAttribute({
              url: this.dataService,
              datasetNames: [layername.datasource + ":" + layername.threeDDateset],
              whereclause: flyField + "='" + attributes[flyField] + "'",
              fields: ["SMID", "IN_JUNEID", "OUT_JUNEID", flyField],
              completed: queryComplete.bind(this),
              failed: queryFial.bind(this)
          })
      } else if (geometry === "point") {
          const isWell = attributes["TYPE"].indexOf("井") !== -1;
          const layers = viewer.scene.layers.layerQueue.filter(item => {
              if (isWell) {//如果是附属物井
                  return layername["WELL"].indexOf(item.name) !== -1;
              } else {
                  return layername["ADJUNCT"].indexOf(item.name) !== -1;
              }
          });
          const queryComplete = (result => {
              if (result.originResult.features.length === 0) return;
              const fid = result.originResult.features[0].ID;
              const geo = result.originResult.features[0].geometry;
              const data = result.result.features[0].data;
              layers.forEach(item => {
                  //item.setSelection(fid);
                  item.setObjsColor([fid], Cesium.Color.DARKRED);
                  locatFeatures.push({ layer: item, ids: [fid] });
              })
              const x = parseFloat(geo.x);
              const y = parseFloat(geo.y);
              const height = parseFloat(geo.z - 0);//this.AppX.appConfig.downDepth
              const bottomPosition = Cesium.Cartographic.fromDegrees(x, y, height);
              const position = Cesium.Cartographic.toCartesian(bottomPosition)
              // const point = viewer.entities.add(this.addPointSIDBillboard(data["PIPE_ID"], position));
              // this.locationEntities.push(point);
              let addEntity = function (entity) {
                  // this.locationEntities.push(entity);
                  let entites = viewer.entities.add(entity);
                  locationEntities.push(entites);
                  viewer.flyTo(entity);
              };
              gl.addUnitBillboard(data["PIPE_ID"], position, addEntity.bind(gl));
          })
          const queryFial = (error) => { console.error(error); }
          const queryDataset = layername.threeDDateset
          this.queryByAttribute({
              url: this.dataService,
              datasetNames: [layername.datasource + ":" + queryDataset],
              whereclause: flyField + "='" + attributes[flyField] + "'",
              fields: ["SMID", "PIPE_ID", flyField],
              completed: queryComplete.bind(this),
              failed: queryFial.bind(this)
          })
      }
  },
  /**
   * 该方法用于生成部件定位指示牌
   * @param text 站点信息
   * @param position 位置
   * @param 生成站点后的回调
   */
  addUnitBillboard(text, position, callback) {
      const that = this;
      const bottomPosition = Cesium.Cartographic.fromCartesian(position);
      const topPosition = Cesium.Cartographic.fromRadians(bottomPosition.longitude, bottomPosition.latitude, bottomPosition.height + 10);
      const bPosition = Cesium.Cartographic.toCartesian(bottomPosition);
      const tPosition = Cesium.Cartographic.toCartesian(topPosition);
      const color = "rgb(56, 136, 205)";
      const colorWithAlpha = "rgba(56, 136, 205, 0.9)";
      const canvas = document.createElement('canvas');
      canvas.width = 100;
      canvas.height = 60;
      const ctx = canvas.getContext('2d');
      const img = new Image();
      img.src = require("@/assets/label.png");
      img.onload = function () {
          ctx.lineWidth = 10;
          ctx.strokeStyle = color;
          ctx.font = "30px Arial";
          const width = ctx.measureText(text).width + 20;
          canvas.width = width;
          ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
          ctx.font = "30px Arial";
          ctx.fillStyle = "rgb(255,255,255)";
          ctx.textBaseline = "middle";
          ctx.fillText(text, 10, 30);
          const entity = new Cesium.Entity({
              // id: options.id,
              // name: options.name,
              show: true,
              position: Cesium.Cartographic.toCartesian(topPosition),
              polyline: {
                  positions: [bPosition, tPosition],
                  material: Cesium.Color.fromBytes(56, 136, 205, 255),
                  width: 3
              },
              billboard: {
                  sizeInMeters: false,
                  image: canvas,
                  height: 60,
                  verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                  horizontalOrigin: Cesium.HorizontalOrigin.CENTER
              }
          })
          callback(entity)
      }
  },
};
