UNPKG

qwc2-lts

Version:
190 lines (188 loc) 8.58 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 2024 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, Provider } from 'react-redux'; import PropTypes from 'prop-types'; import { createSelector } from 'reselect'; import { setCurrentTask } from '../actions/task'; import ResizeableWindow from '../components/ResizeableWindow'; import ReducerIndex from '../reducers/index'; import map3dReducer from '../reducers/map3d'; import searchProvidersSelector from '../selectors/searchproviders'; import { createStore } from '../stores/StandardStore'; import LocaleUtils from '../utils/LocaleUtils'; /** * Displays a 3D map view. */ var View3D = /*#__PURE__*/function (_React$Component) { function View3D(props) { var _this; _classCallCheck(this, View3D); _this = _callSuper(this, View3D, [props]); _defineProperty(_this, "state", { enabled: false, componentLoaded: false }); _defineProperty(_this, "onClose", function () { _this.setState({ enabled: false }); }); _defineProperty(_this, "setRef", function (ref) { _this.map3dComponentRef = ref; }); _defineProperty(_this, "setViewToExtent", function () { if (_this.map3dComponentRef) { _this.map3dComponentRef.setViewToExtent(_this.props.mapBBox.bounds, _this.props.mapBBox.rotation); } }); _defineProperty(_this, "redrawScene", function (ev) { if (_this.map3dComponentRef) { _this.map3dComponentRef.redrawScene(ev); } }); _this.map3dComponent = null; _this.map3dComponentRef = null; // Subset of 2d reducers var _ReducerIndex$reducer = ReducerIndex.reducers, task = _ReducerIndex$reducer.task, windows = _ReducerIndex$reducer.windows; _this.store = createStore({ task: task, windows: windows, map: map3dReducer }); return _this; } _inherits(View3D, _React$Component); return _createClass(View3D, [{ key: "componentDidUpdate", value: function componentDidUpdate(prevProps, prevState) { var _this2 = this; if (this.props.enabled && !prevProps.enabled) { this.setState({ enabled: true }); this.props.setCurrentTask(null); import('../components/map3d/Map3D').then(function (component) { _this2.map3dComponent = component["default"]; _this2.map3dComponentRef = null; _this2.setState({ componentLoaded: true }); }); } else if (!this.state.enabled && prevState.enabled) { this.map3dComponent = null; this.map3dComponentRef = null; this.setState({ componentLoaded: false }); } } }, { key: "render", value: function render() { if (!this.state.enabled) { return null; } var extraControls = [{ icon: "sync", callback: this.setViewToExtent, title: LocaleUtils.tr("map3d.syncview") }]; var Map3D = this.map3dComponent; return /*#__PURE__*/React.createElement(ResizeableWindow, { extraControls: extraControls, icon: "map3d", initialHeight: this.props.geometry.initialHeight, initialWidth: this.props.geometry.initialWidth, initialX: this.props.geometry.initialX, initialY: this.props.geometry.initialY, initiallyDocked: this.props.geometry.initiallyDocked, onClose: this.onClose, onExternalWindowResized: this.redrawScene, splitScreenWhenDocked: true, splitTopAndBottomBar: true, title: LocaleUtils.tr("map3d.title") }, this.state.componentLoaded ? /*#__PURE__*/React.createElement(Provider, { role: "body", store: this.store }, /*#__PURE__*/React.createElement(Map3D, { innerRef: this.setRef, layers: this.props.layers, mapBBox: this.props.mapBBox, options: this.props.options, projection: this.props.projection, searchProviders: this.props.searchProviders, theme: this.props.theme })) : null); } }]); }(React.Component); _defineProperty(View3D, "propTypes", { enabled: PropTypes.bool, /** Default window geometry. */ geometry: PropTypes.shape({ initialWidth: PropTypes.number, initialHeight: PropTypes.number, initialX: PropTypes.number, initialY: PropTypes.number, initiallyDocked: PropTypes.bool }), layers: PropTypes.array, mapBBox: PropTypes.object, /** Various configuration options */ options: PropTypes.shape({ /** Minimum scale denominator when zooming to search result. */ searchMinScaleDenom: PropTypes.number }), projection: PropTypes.string, searchProviders: PropTypes.object, setCurrentTask: PropTypes.func, theme: PropTypes.object }); _defineProperty(View3D, "defaultProps", { geometry: { initialWidth: 600, initialHeight: 800, initialX: 0, initialY: 0, initiallyDocked: true }, options: { searchMinScaleDenom: 1000 } }); export default connect(createSelector([function (state) { return state; }, searchProvidersSelector], function (state, searchProviders) { return { enabled: state.task.id === 'View3D', mapBBox: state.map.bbox, projection: state.map.projection, layers: state.layers.flat, theme: state.theme.current, searchProviders: searchProviders }; }), { setCurrentTask: setCurrentTask })(View3D);