"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.handelGeometry = exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _cesium = require("cesium");
var _icons = require("@ant-design/icons");
var _antd = require("antd");
var _InfoTool = _interopRequireDefault(require("./InfoTool"));
var _classnames = _interopRequireDefault(require("classnames"));
var _turf = require("@turf/turf");
var _Marker = _interopRequireDefault(require("../marker/Marker"));
var _Polygon = _interopRequireDefault(require("../polygon/Polygon"));
var _Polyline = _interopRequireDefault(require("../polyline/Polyline"));
var _layerControl = require("../tools/layer-control");
var _createFeatureCollection = require("../feature-layer/createFeatureCollection");
var _popup = _interopRequireDefault(require("../popup"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (c = i[4] || 3, u = i[5] === e ? i[3] : i[5], i[4] = 3, i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var ClusterTitle = function ClusterTitle(props) {
  var layer = props.layer;
  var name = layer.name;
  var imgUrl = (0, _layerControl.getImgUrl)(layer);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])('cs-map-popup-cluster-title')
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: imgUrl,
    alt: "",
    className: (0, _classnames["default"])('cs-map-popup-cluster-title-img')
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])('cs-map-popup-cluster-title-text')
  }, name));
};

// 根据图片地址获取图片高度
var getImageHeightBySrc = function getImageHeightBySrc(src) {
  return new Promise(function (resolve) {
    // js从base64数据中获取宽高
    var image = new Image();
    image.src = src;
    image.onload = function () {
      resolve(image.height);
    };
  });
};
ClusterTitle.propTypes = {
  layer: _propTypes["default"].object
};
var Cluster = function Cluster(props) {
  var layer = props.layer,
    features = props.features,
    onFeatureClick = props.onFeatureClick,
    onFitView = props.onFitView;
  var labelField = layer.labelField;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])('cs-map-popup-cluster')
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])('cs-map-popup-cluster-header')
  }, "\u5171 ", features.length, " \u4E2A\u70B9\u4F4D", /*#__PURE__*/_react["default"].createElement("a", {
    onClick: onFitView
  }, "\u7F29\u653E\u81F3")), /*#__PURE__*/_react["default"].createElement(_antd.Table, {
    pagination: false,
    size: "small",
    dataSource: features,
    scroll: {
      y: 120
    },
    columns: [{
      title: '名称',
      dataIndex: '名称',
      width: 60,
      render: function render(text, record) {
        return /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            return onFeatureClick(record);
          }
        }, record.values_[labelField]);
      }
    }, {
      title: '操作',
      dataIndex: '操作',
      width: 30,
      render: function render(text, record) {
        return /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            return onFeatureClick(record);
          }
        }, "\u5B9A\u4F4D");
      }
    }]
  }));
};
Cluster.propTypes = {
  layer: _propTypes["default"].object,
  features: _propTypes["default"].array,
  onFeatureClick: _propTypes["default"].func,
  onFitView: _propTypes["default"].func
};
var handelGeometry = exports.handelGeometry = function handelGeometry(entity) {
  var _entity$data, _coordinates, _midpoint;
  var geometry = entity === null || entity === void 0 || (_entity$data = entity.data) === null || _entity$data === void 0 ? void 0 : _entity$data.geometry;
  var type = geometry === null || geometry === void 0 ? void 0 : geometry.type;
  var coordinates = geometry === null || geometry === void 0 ? void 0 : geometry.coordinates;
  var midpoint = entity === null || entity === void 0 ? void 0 : entity.data; // 默认点
  var position = null;
  var offset = {
    x: 0,
    y: 20
  };
  if (['MultiLineString', 'LineString'].includes(type) && (_coordinates = coordinates) !== null && _coordinates !== void 0 && _coordinates.length) {
    if (coordinates.length >= 3) {
      var features = (0, _turf.featureCollection)(coordinates.map(function (lngLatArr) {
        return (0, _turf.point)(lngLatArr);
      }));
      var center = (0, _turf.center)(features);
      var line = (0, _turf.lineString)(coordinates);
      midpoint = (0, _turf.nearestPointOnLine)(line, center, {
        units: 'miles'
      });
    } else if (coordinates.length > 1) {
      midpoint = _turf.midpoint.apply(void 0, _toConsumableArray(coordinates.map(function (lngLatArr) {
        return (0, _turf.point)(lngLatArr);
      })));
    } else {
      var lngLatArr = coordinates[0];
      midpoint = (0, _turf.midpoint)((0, _turf.point)(lngLatArr[0]), (0, _turf.point)(lngLatArr[1]));
    }
  } else if (['Polygon', 'MultiPolygon'].includes(type)) {
    var _coordinates2;
    // 兼容polygon首尾坐标不一致情况
    coordinates = (_coordinates2 = coordinates) === null || _coordinates2 === void 0 ? void 0 : _coordinates2.map(function (item) {
      if (item[0][0] !== item[item.length - 1][0] || item[0][1] !== item[item.length - 1][1]) {
        return [].concat(_toConsumableArray(item), [item[0]]);
      }
      return item;
    });
    // 面
    // 注意：polygon首尾坐标要一致
    var polygon = (0, _turf.polygon)(coordinates);
    midpoint = (0, _turf.centerOfMass)(polygon);
  } else if (['Point'].includes(type)) {
    offset = {
      x: 5,
      y: 20
    };
  }
  if ((_midpoint = midpoint) !== null && _midpoint !== void 0 && (_midpoint = _midpoint.geometry) !== null && _midpoint !== void 0 && _midpoint.coordinates) {
    position = _cesium.Cartesian3.fromDegrees.apply(_cesium.Cartesian3, _toConsumableArray(midpoint.geometry.coordinates));
  }
  return {
    position: position,
    geometryType: type,
    _offset: offset
  };
};
var MapPopup = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var map = props.map;
  var _useState = (0, _react.useState)(null),
    _useState2 = _slicedToArray(_useState, 2),
    content = _useState2[0],
    setContent = _useState2[1];
  var _useState3 = (0, _react.useState)(null),
    _useState4 = _slicedToArray(_useState3, 2),
    title = _useState4[0],
    setTitle = _useState4[1];
  var popupRef = (0, _react.useRef)();
  var featureRef = (0, _react.useRef)();
  var infoToolRef = (0, _react.useRef)(new _InfoTool["default"]({
    map: map
  }));
  var viewRef = (0, _react.useRef)();
  var highlightLayerRef = (0, _react.useRef)();
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      showTemplate: _showTemplate,
      hideTemplate: hideTemplate
    };
  });
  var _showTemplate = /*#__PURE__*/function () {
    var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(feature, highlightLayer, options) {
      var _feature$_position, _feature$data, _highlightLayer2;
      var _popupRef$current, _layer2$_options, _layer2$cluster, points, features, _layer2, Template, layer, properties, position, offset, height, _feature$_billboard$s, _feature$_billboard, src, _height, _feature$_billboard$s2, _feature$_polygon, coordinates, _handelGeometry, _position, _offset, _feature$_polyline, _coordinates3, _handelGeometry2, _position2, _offset2, _midpoint$geometry, geometry, _geometry$coordinates, point1, point2, midpoint, _handelGeometry3, _position3, _offset3, _popupRef$current2, template, labelField, currentCameraHeight, viewThreshold, viewHeight, _feature$data2;
      return _regenerator().w(function (_context) {
        while (1) switch (_context.n) {
          case 0:
            setContent(null);
            if (feature) {
              _context.n = 1;
              break;
            }
            hideTemplate();
            return _context.a(2);
          case 1:
            if (!(feature && feature.length >= 2)) {
              _context.n = 2;
              break;
            }
            points = [];
            features = feature.map(function (f) {
              var properties = map.getProperties(f);
              points.push((0, _turf.point)(f.geometry));
              return {
                feature: f,
                geometryInfo: (properties === null || properties === void 0 ? void 0 : properties.geometryInfo) || {
                  type: 'point',
                  lngLats: f.geometry.join(','),
                  coordType: 'wgs84'
                },
                values_: properties,
                properties: properties
              };
            });
            _layer2 = map.getLayerByFeature(feature[0]);
            infoToolRef.current.add({
              position: map._clickObject.position,
              content: '',
              element: (_popupRef$current = popupRef.current) === null || _popupRef$current === void 0 ? void 0 : _popupRef$current.wrapDom,
              inputFeature: feature,
              type: '',
              offset: {
                x: 0,
                y: 20
              }
            });
            setTitle(/*#__PURE__*/_react["default"].createElement(ClusterTitle, {
              layer: _layer2
            }));

            // 判断是否有自定义聚合列表模版
            Template = (_layer2 === null || _layer2 === void 0 || (_layer2$_options = _layer2._options) === null || _layer2$_options === void 0 || (_layer2$_options = _layer2$_options.cluster) === null || _layer2$_options === void 0 ? void 0 : _layer2$_options.template) || (_layer2 === null || _layer2 === void 0 || (_layer2$cluster = _layer2.cluster) === null || _layer2$cluster === void 0 ? void 0 : _layer2$cluster.template) || Cluster;
            setContent(/*#__PURE__*/_react["default"].createElement(Template, {
              layer: _layer2,
              features: features,
              onFitView: function onFitView() {
                map.fitView({
                  data: features
                });
                hideTemplate(null, map.autoView);
              },
              onFeatureClick: function onFeatureClick(f) {
                _showTemplate(f.feature, highlightLayer);
              }
            }));
            return _context.a(2);
          case 2:
            layer = map.getLayerByFeature(feature);
            if (!(layer !== null && layer !== void 0 && layer.cancelPopup || feature !== null && feature !== void 0 && feature.cancelPopup)) {
              _context.n = 3;
              break;
            }
            return _context.a(2);
          case 3:
            map.layers.highlightFeature = feature;
            properties = map.getProperties(feature);
            feature.values_ = properties;
            featureRef.current = feature;
            position = feature === null || feature === void 0 || (_feature$_position = feature._position) === null || _feature$_position === void 0 ? void 0 : _feature$_position._value; // 偏移量
            offset = {
              x: 5,
              y: 76
            };
            height = map.fitViewHeight || 5000;
            if (!(feature instanceof _Marker["default"] || feature !== null && feature !== void 0 && feature._billboard)) {
              _context.n = 6;
              break;
            }
            if ((_feature$_billboard$s = feature._billboard.scale) !== null && _feature$_billboard$s !== void 0 && _feature$_billboard$s._value) {
              offset.y = offset.y * feature._billboard.scale._value;
            }
            src = ((_feature$_billboard = feature._billboard) === null || _feature$_billboard === void 0 || (_feature$_billboard = _feature$_billboard._image) === null || _feature$_billboard === void 0 ? void 0 : _feature$_billboard._value) || '';
            if (!src) {
              _context.n = 5;
              break;
            }
            _context.n = 4;
            return getImageHeightBySrc(src);
          case 4:
            _height = _context.v;
            if (_height && typeof _height === 'number') {
              if ((_feature$_billboard$s2 = feature._billboard.scale) !== null && _feature$_billboard$s2 !== void 0 && _feature$_billboard$s2._value) {
                _height = _height * feature._billboard.scale._value;
              }
              offset.y = _height + 10;
            }
          case 5:
            _context.n = 7;
            break;
          case 6:
            if (feature instanceof _Polygon["default"] || feature !== null && feature !== void 0 && feature._polygon) {
              coordinates = [((feature === null || feature === void 0 || (_feature$_polygon = feature._polygon) === null || _feature$_polygon === void 0 || (_feature$_polygon = _feature$_polygon._hierarchy) === null || _feature$_polygon === void 0 || (_feature$_polygon = _feature$_polygon._value) === null || _feature$_polygon === void 0 ? void 0 : _feature$_polygon.positions) || []).map(function (v) {
                var cartographic = _cesium.Cartographic.fromCartesian(v); // 经纬高对象
                var lng = _cesium.Math.toDegrees(cartographic.longitude);
                var lat = _cesium.Math.toDegrees(cartographic.latitude);
                return [lng, lat];
              })];
              _handelGeometry = handelGeometry({
                data: {
                  geometry: {
                    type: 'Polygon',
                    coordinates: coordinates
                  }
                }
              }), _position = _handelGeometry.position, _offset = _handelGeometry._offset;
              position = _position;
              offset = _offset;
              height = null;
            } else if (feature instanceof _Polyline["default"] || feature !== null && feature !== void 0 && feature._polyline) {
              _coordinates3 = ((feature === null || feature === void 0 || (_feature$_polyline = feature._polyline) === null || _feature$_polyline === void 0 || (_feature$_polyline = _feature$_polyline._positions) === null || _feature$_polyline === void 0 ? void 0 : _feature$_polyline._value) || []).map(function (v) {
                var cartographic = _cesium.Cartographic.fromCartesian(v); // 经纬高对象
                var lng = _cesium.Math.toDegrees(cartographic.longitude);
                var lat = _cesium.Math.toDegrees(cartographic.latitude);
                return [lng, lat];
              });
              _handelGeometry2 = handelGeometry({
                data: {
                  geometry: {
                    type: 'LineString',
                    coordinates: _coordinates3
                  }
                }
              }), _position2 = _handelGeometry2.position, _offset2 = _handelGeometry2._offset;
              position = _position2;
              offset = _offset2;
              height = null;
            }
          case 7:
            if (feature instanceof _cesium.Cesium3DTileFeature) {
              offset = {
                x: 0,
                y: 20
              };
              position = map._clickObject.position;
              // position = Cartesian3.fromDegrees();
            } else if (feature.primitive) {
              if (properties.geometryInfo) {
                offset = {
                  x: 0,
                  y: 20
                };
                geometry = (0, _createFeatureCollection.transformGeometry)(properties.geometryInfo);
                _geometry$coordinates = _slicedToArray(geometry.coordinates[0], 2), point1 = _geometry$coordinates[0], point2 = _geometry$coordinates[1];
                midpoint = (0, _turf.midpoint)(point1, point2);
                if (midpoint !== null && midpoint !== void 0 && (_midpoint$geometry = midpoint.geometry) !== null && _midpoint$geometry !== void 0 && _midpoint$geometry.coordinates) {
                  position = _cesium.Cartesian3.fromDegrees.apply(_cesium.Cartesian3, _toConsumableArray(midpoint.geometry.coordinates));
                }
              } else {
                offset = {
                  x: 0,
                  y: 20
                };
                position = map._clickObject.position;
              }
            }

            // 影像图层的数据
            if (feature instanceof _cesium.ImageryLayerFeatureInfo || feature !== null && feature !== void 0 && (_feature$data = feature.data) !== null && _feature$data !== void 0 && (_feature$data = _feature$data.geometry) !== null && _feature$data !== void 0 && _feature$data.coordinates) {
              _handelGeometry3 = handelGeometry(feature), _position3 = _handelGeometry3.position, _offset3 = _handelGeometry3._offset;
              position = _position3;
              offset = _offset3;
            }
            if (layer !== null && layer !== void 0 && layer.template) {
              template = layer.template;
              labelField = layer.labelField;
              setTitle(labelField && properties[labelField]);
              setContent(feature && template(feature));
              infoToolRef.current.add({
                position: position,
                content: '',
                element: (_popupRef$current2 = popupRef.current) === null || _popupRef$current2 === void 0 ? void 0 : _popupRef$current2.wrapDom,
                inputFeature: feature,
                type: '',
                offset: offset
              });
              map.popupRef = feature;
            }
            currentCameraHeight = map.camera.positionCartographic.height;
            viewThreshold = currentCameraHeight < height;
            viewHeight = viewThreshold ? currentCameraHeight : height;
            if (!viewRef.current && map.autoView) {
              getView();
            }
            if (viewThreshold) {
              viewRef.current = null;
            }
            highlightLayer = highlightLayer || map.highlightLayer;
            highlightLayerRef.current = highlightLayer;
            highlightLayer.addHighlightFeature(feature);
            if ((_highlightLayer2 = highlightLayer) !== null && _highlightLayer2 !== void 0 && _highlightLayer2.layer && map.autoView) {
              // 影像图层的数据
              if (feature instanceof _cesium.ImageryLayerFeatureInfo && map.viewMode === '2D' && (feature === null || feature === void 0 || (_feature$data2 = feature.data) === null || _feature$data2 === void 0 || (_feature$data2 = _feature$data2.geometry) === null || _feature$data2 === void 0 ? void 0 : _feature$data2.type) !== 'Point') {
                map.fitView({
                  geoJson: {
                    features: [feature.data]
                  }
                });
              } else {
                map.fitView({
                  entity: highlightLayer.layer,
                  height: viewHeight
                });
              }
            }
          case 8:
            return _context.a(2);
        }
      }, _callee);
    }));
    return function showTemplate(_x, _x2, _x3) {
      return _ref.apply(this, arguments);
    };
  }();
  var hideTemplate = function hideTemplate(_layer) {
    if (_layer) {
      var layer = typeof _layer === 'string' ? map.getLayerByKey(_layer) : _layer;
      if (layer && layer.key && map.popupRef) {
        var _highlightLayer = map.getLayerByFeature(map.popupRef);
        if (_highlightLayer.key === layer.key) {
          onClose();
        }
      }
    } else {
      onClose();
    }
  };

  // 判断点位异常-点位异常展示红色
  function judgeAbnormal() {
    var _ref2 = map.getProperties(featureRef.current) || {},
      status = _ref2.status;
    return status && [1, 2, 4].includes(status);
  }

  // 关闭气泡
  var onClose = function onClose() {
    var _infoToolRef$current, _highlightLayerRef$cu, _highlightLayerRef$cu2;
    map.onCloseTemplateBefore && map.onCloseTemplateBefore(featureRef.current);
    map.popupRef = null;
    featureRef.current = null;
    infoToolRef === null || infoToolRef === void 0 || (_infoToolRef$current = infoToolRef.current) === null || _infoToolRef$current === void 0 || _infoToolRef$current.remove();
    map.layers.highlightFeature = null;
    if (map.entities.getById('highlight-1')) {
      map.entities.remove(map.entities.getById('highlight-1'));
    }

    // 清除高亮
    (_highlightLayerRef$cu = highlightLayerRef.current) === null || _highlightLayerRef$cu === void 0 || (_highlightLayerRef$cu2 = _highlightLayerRef$cu.clearHighlight) === null || _highlightLayerRef$cu2 === void 0 || _highlightLayerRef$cu2.call(_highlightLayerRef$cu);
    // highlightLayerRef.current.clearFeatures();

    // map.fitView();

    if (map.autoView && map.closePopupAutoView) {
      setView();
    }
    setContent(null);
  };
  var getView = function getView() {
    //获取当前视角的 pitch
    var pitch = map.camera.pitch;

    //获取当前视角的 heading
    var heading = map.camera.heading;

    //获取当前视角的 position（位置）
    var position = map.camera.position;
    viewRef.current = {
      x: position.x,
      y: position.y,
      z: position.z,
      pitch: pitch,
      heading: heading,
      viewMode: map.viewMode
    };
  };
  var setView = function setView() {
    if (viewRef.current && viewRef.current.viewMode === map.viewMode) {
      map.camera.flyTo({
        //定位到范围中心点
        destination: {
          x: viewRef.current.x,
          y: viewRef.current.y,
          z: viewRef.current.z
        },
        orientation: {
          heading: viewRef.current.heading,
          //左右方向
          pitch: viewRef.current.pitch,
          //上下方向
          roll: 0.0
        },
        duration: 2
      });
      viewRef.current = null;
    }
  };
  var theme = judgeAbnormal() ? 'red' : '';
  return /*#__PURE__*/_react["default"].createElement(_popup["default"], {
    ref: popupRef,
    title: title,
    onClose: onClose,
    theme: theme
  }, content);
});
MapPopup.propTypes = {
  map: _propTypes["default"].object,
  feature: _propTypes["default"].object,
  layer: _propTypes["default"].object,
  highlightLayer: _propTypes["default"].object,
  onClose: _propTypes["default"].func
};
var _default = exports["default"] = MapPopup;
//# sourceMappingURL=Popup.js.map
