UNPKG

qwc2

Version:
167 lines (166 loc) 8.75 kB
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); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Copyright 2025 Sourcepole AG * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ import React from 'react'; import { connect } from 'react-redux'; import axios from 'axios'; import PropTypes from 'prop-types'; import { v4 as uuidv4 } from 'uuid'; import { processStarted, processFinished } from '../../actions/processNotifications'; import ConfigUtils from '../../utils/ConfigUtils'; import LocaleUtils from '../../utils/LocaleUtils'; import FileSelector from '../widgets/FileSelector'; import Spinner from '../widgets/Spinner'; import { importGltf } from './utils/MiscUtils3D'; import './style/ImportObjects3D.css'; var ImportObjects3D = /*#__PURE__*/function (_React$Component) { function ImportObjects3D() { var _this; _classCallCheck(this, ImportObjects3D); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, ImportObjects3D, [].concat(args)); _defineProperty(_this, "state", { importing: false, selectedfile: null }); _defineProperty(_this, "importFile", function () { if (!_this.state.selectedfile) { return; } var file = _this.state.selectedfile; var taskid = uuidv4(); _this.setState({ importing: true }); _this.props.processStarted(taskid, LocaleUtils.tr("import3d.importing", file.name)); if (file.name.endsWith(".gltf") || file.name.endsWith(".glb")) { _this.importGltfFile(file, taskid); } else { _this.importTo3DTiles(file, taskid); } }); _defineProperty(_this, "importGltfFile", function (file, taskid) { var reader = new FileReader(); reader.onload = function (ev) { importGltf(ev.target.result, file.name, _this.props.sceneContext, { drawGroup: true, imported: true }, true); _this.setState({ selectedfile: null, importing: false }); _this.props.processFinished(taskid, true); }; reader.onerror = function () { _this.setState({ selectedfile: null, importing: false }); _this.props.processFinished(taskid, false); }; reader.readAsArrayBuffer(_this.state.selectedfile); }); _defineProperty(_this, "importTo3DTiles", function (file, taskid) { var _this$props$sceneCont; var sceneTarget = _this.props.sceneContext.scene.view.controls.target.clone(); sceneTarget.z = (_this$props$sceneCont = _this.props.sceneContext.getTerrainHeightFromMap([sceneTarget.x, sceneTarget.y])) !== null && _this$props$sceneCont !== void 0 ? _this$props$sceneCont : 0; var formData = new FormData(); var jsonBlob = new Blob([JSON.stringify({ inputs: [String(sceneTarget.x), String(sceneTarget.y), String(sceneTarget.z), _this.props.sceneContext.mapCrs] })], { type: 'application/json' }); formData.set('json', jsonBlob); formData.set('file', file); var headers = { "Content-Type": "multipart/form-data" }; var ogcProcessesUrl = ConfigUtils.getConfigProp("ogcProcessesUrl"); if (!ogcProcessesUrl) { _this.setState({ selectedfile: null, importing: false }); _this.props.processFinished(taskid, false, LocaleUtils.tr("import3d.noprocessesserver")); return; } axios.post(ogcProcessesUrl.replace(/\/$/, '') + '/modelimport/execution_multipart', formData, { headers: headers }).then(function (response) { var tilesetUrl = _this.props.importedTilesBaseUrl + response.data.result.value; _this.props.sceneContext.add3dTiles(tilesetUrl, taskid, { title: file.name }, true); _this.setState({ selectedfile: null, importing: false }); _this.props.processFinished(taskid, true); })["catch"](function (err) { _this.setState({ selectedfile: null, importing: false }); _this.props.processFinished(taskid, false); }); }); return _this; } _inherits(ImportObjects3D, _React$Component); return _createClass(ImportObjects3D, [{ key: "render", value: function render() { var _this2 = this; return /*#__PURE__*/React.createElement("div", { className: "importobjects3d-widget" }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(FileSelector, { accept: ".gltf,.glb,.ifc,.gml,.citygml,.cityjson,.gpkg", file: this.state.selectedfile, onFileSelected: function onFileSelected(file) { return _this2.setState({ selectedfile: file }); }, title: LocaleUtils.tr("layertree3d.supportedformats") })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", { className: "button", disabled: this.state.selectedfile === null || this.state.importing, onClick: this.importFile, type: "button" }, this.state.importing ? /*#__PURE__*/React.createElement(Spinner, null) : null, LocaleUtils.tr("layertree3d.import")))); } }]); }(React.Component); _defineProperty(ImportObjects3D, "propTypes", { importedTilesBaseUrl: PropTypes.string, processFinished: PropTypes.func, processStarted: PropTypes.func, sceneContext: PropTypes.object }); export default connect(function (state) { return {}; }, { processFinished: processFinished, processStarted: processStarted })(ImportObjects3D);