UNPKG

@vtx/cs-map

Version:

React components for Vortex

122 lines (120 loc) 6.44 kB
"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["default"] = void 0; var _react = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _useProps2 = _interopRequireDefault(require("../use-props")); var _cesium = require("cesium"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } var InundateAnalysis = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) { var _useProps = (0, _useProps2["default"])(), map = _useProps.map; var data = props.data, setProgress = props.setProgress; var polygonRef = (0, _react.useRef)(); var playRef = (0, _react.useRef)({}); var layerRef = (0, _react.useRef)(); (0, _react.useImperativeHandle)(ref, function () { return { removePolygon: removePolygon, addPolygon: addPolygon, onFinish: onFinish, onReset: onReset, onProgress: onProgress, polygonRef: polygonRef, playRef: playRef, layerRef: layerRef }; }); (0, _react.useEffect)(function () { layerRef.current = new _cesium.CustomDataSource('measureLayer'); layerRef.current.unclickable = true; layerRef.current.cancelBubble = true; layerRef.current.layerControl = false; map.dataSources.add(layerRef.current); return function () { map.dataSources.remove(layerRef.current); }; }, []); var removePolygon = function removePolygon() { if (polygonRef.current) { layerRef.current.entities.remove(polygonRef.current); polygonRef.current = null; } }; var addPolygon = function addPolygon(_ref) { var min = _ref.min, max = _ref.max, speed = _ref.speed, color = _ref.color; removePolygon(); var _p = data.map(function (v) { return [].concat(_toConsumableArray(v), [10]); }); var total = max - min; playRef.current = { color: color || "rgba(0,191,255,0.5)", // 水面颜色 targetHeight: max, // 目标高度 currentHeight: min, // 当前高度 speed: speed, // 速度 progress: 0, // 进度 play: true }; polygonRef.current = layerRef.current.entities.add({ polygon: { hierarchy: _cesium.Cartesian3.fromDegreesArrayHeights(_p.flat(Infinity)), extrudedHeight: new _cesium.CallbackProperty(function () { var _currentHeight = playRef.current.currentHeight; if (playRef.current.play) { _currentHeight += speed / 60; var _progress = _currentHeight / total * 100; if (_currentHeight > playRef.current.targetHeight) { _currentHeight = 0; _progress = 0; } playRef.current.currentHeight = _currentHeight; setProgress === null || setProgress === void 0 || setProgress(_progress); } return _currentHeight; }, false), perPositionHeight: true, closeTop: false, material: new _cesium.Color.fromCssColorString(playRef.current.color) } }); }; var onFinish = function onFinish(values) { addPolygon(values); }; var onReset = function onReset() { removePolygon(); }; var onProgress = function onProgress(_progress) { playRef.current.progress = _progress; playRef.current.currentHeight = _progress / 100 * playRef.current.targetHeight; }; return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null); }); InundateAnalysis.propTypes = { data: _propTypes["default"].array, perspective: _propTypes["default"].string, model: _propTypes["default"].object }; var _default = exports["default"] = InundateAnalysis; //# sourceMappingURL=index.js.map