qwc2
Version:
QGIS Web Client
213 lines (211 loc) • 11.4 kB
JavaScript
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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 } from 'react-redux';
import classNames from 'classnames';
import isEmpty from 'lodash.isempty';
import PropTypes from 'prop-types';
import { toggleFullscreen, View3DMode } from '../../actions/display';
import { openExternalUrl, setTopbarHeight } from '../../actions/windows';
import AppMenu from '../../components/AppMenu';
import FullscreenSwitcher from '../../components/FullscreenSwitcher';
import { Swipeable } from '../../components/Swipeable';
import Toolbar from '../../components/Toolbar';
import SearchField3D from '../../components/map3d/SearchField3D';
import ConfigUtils from '../../utils/ConfigUtils';
import LocaleUtils from '../../utils/LocaleUtils';
import ThemeUtils from '../../utils/ThemeUtils';
/**
* Bottom bar of the 3D map, including the search bar, tool bar and menu.
*/
var TopBar3D = /*#__PURE__*/function (_React$Component) {
function TopBar3D() {
var _this;
_classCallCheck(this, TopBar3D);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, TopBar3D, [].concat(args));
_defineProperty(_this, "state", {
allowedMenuItems: [],
allowedToolbarItems: []
});
_defineProperty(_this, "filter2DItems", function (item) {
var pluginConf = ConfigUtils.getPluginConfig(item.key);
return isEmpty(pluginConf) || _this.props.view3dMode === View3DMode.FULLSCREEN && pluginConf.availableIn3D;
});
_defineProperty(_this, "storeHeight", function (el) {
if (el) {
_this.props.setTopbarHeight(el.clientHeight);
}
});
_defineProperty(_this, "openUrl", function (url, target, title, icon) {
if (target === "iframe") {
target = ":iframedialog:externallinkiframe";
}
_this.props.openExternalUrl(url, target, {
title: title,
icon: icon
});
});
_defineProperty(_this, "addGenericMenuItems", function (menuItems, inputConfig) {
inputConfig.forEach(function (entry) {
if (entry.subitems) {
var group = [];
_this.addGenericMenuItems(group, entry.subitems);
if (group.length > 0) {
menuItems.push(_objectSpread(_objectSpread({}, entry), {}, {
subitems: group
}));
}
} else {
var pluginConfig = ConfigUtils.getPluginConfig(entry.key);
if (entry.url || pluginConfig.availableIn3D) {
menuItems.push(entry);
}
}
});
});
return _this;
}
_inherits(TopBar3D, _React$Component);
return _createClass(TopBar3D, [{
key: "componentDidMount",
value: function componentDidMount() {
this.componentDidUpdate({});
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (this.props.currentTheme !== prevProps.currentTheme || this.props.view3dMode !== prevProps.view3dMode) {
this.setState({
allowedToolbarItems: ThemeUtils.allowedItems(this.props.toolbarItems, this.props.currentTheme, this.filter2DItems),
allowedMenuItems: ThemeUtils.allowedItems(this.props.menuItems, this.props.currentTheme, this.filter2DItems)
});
}
}
}, {
key: "render",
value: function render() {
var _ConfigUtils$getPlugi,
_this2 = this;
var config = ((_ConfigUtils$getPlugi = ConfigUtils.getPluginConfig("TopBar")) === null || _ConfigUtils$getPlugi === void 0 ? void 0 : _ConfigUtils$getPlugi.cfg) || {};
var logo;
var assetsPath = ConfigUtils.getAssetsPath();
var isMobile = ConfigUtils.isMobile();
if (isMobile) {
logo = assetsPath + "/img/logo-mobile." + (config.logoFormat || "svg");
} else {
logo = assetsPath + "/img/logo." + (config.logoFormat || "svg");
}
var logoEl = /*#__PURE__*/React.createElement("img", {
className: "topbar-logo",
src: config.logoSrc || logo
});
if (config.logoUrl) {
logoEl = /*#__PURE__*/React.createElement("a", {
href: config.logoUrl,
rel: "noreferrer",
target: "_blank"
}, logoEl);
}
var menuCompact = !isMobile ? config.appMenuCompact : false;
var classes = classNames({
TopBar: true,
mobile: isMobile,
fullscreen: this.props.fullscreen
});
return /*#__PURE__*/React.createElement(Swipeable, {
onSwipedDown: function onSwipedDown() {
return _this2.props.toggleFullscreen(false);
},
onSwipedUp: function onSwipedUp() {
return _this2.props.toggleFullscreen(true);
}
}, /*#__PURE__*/React.createElement("div", {
className: classes,
ref: this.storeHeight
}, logoEl, /*#__PURE__*/React.createElement("div", {
className: "topbar-center-span"
}, /*#__PURE__*/React.createElement("div", {
className: "topbar-search-container"
}, /*#__PURE__*/React.createElement(SearchField3D, {
sceneContext: this.props.sceneContext,
searchOptions: this.props.searchOptions
})), /*#__PURE__*/React.createElement(Toolbar, {
openExternalUrl: this.openUrl,
toolbarItems: this.state.allowedToolbarItems
})), /*#__PURE__*/React.createElement(AppMenu, {
appMenuClearsTask: config.appMenuClearsTask,
appMenuShortcut: config.appMenuShortcut,
buttonLabel: LocaleUtils.tr("appmenu.menulabel"),
keepMenuOpen: menuCompact,
menuCompact: menuCompact,
menuItems: this.state.allowedMenuItems,
openExternalUrl: this.openUrl,
showFilterField: config.appMenuFilterField
}), this.props.view3dMode === View3DMode.FULLSCREEN ? /*#__PURE__*/React.createElement(FullscreenSwitcher, null) : null));
}
}]);
}(React.Component);
_defineProperty(TopBar3D, "propTypes", {
currentTheme: PropTypes.object,
fullscreen: PropTypes.bool,
/** The menu items, in the same format as the 2D `TopBar` menu items.
* You can include entries for the View3D plugins.
* You can also include entries for 2D plugins which are compatible with the 3D view (i.e. `ThemeSwitcher`, `Share`, etc.),
* these will be displayed only in fullsceen 3D mode. */
menuItems: PropTypes.array,
openExternalUrl: PropTypes.func,
sceneContext: PropTypes.object,
/** Options passed down to the search component. */
searchOptions: PropTypes.shape({
/** Minimum scale denominator when zooming to search result. */
minScaleDenom: PropTypes.number
}),
setTopbarHeight: PropTypes.func,
toggleFullscreen: PropTypes.func,
/** The toolbar, in the same format as the 2D `TopBar` toolbar items.
* You can include entries for the View3D plugins.
* You can also include entries for 2D plugins which are compatible with the 3D view (i.e. `ThemeSwitcher`, `Share`, etc.),
* these will be displayed only in fullsceen 3D mode. */
toolbarItems: PropTypes.array,
view3dMode: PropTypes.number
});
_defineProperty(TopBar3D, "defaultProps", {
searchOptions: {
minScaleDenom: 1000
}
});
export default connect(function (state) {
return {
currentTheme: state.theme.current,
fullscreen: state.display.fullscreen,
view3dMode: state.display.view3dMode
};
}, {
setTopbarHeight: setTopbarHeight,
toggleFullscreen: toggleFullscreen,
openExternalUrl: openExternalUrl
})(TopBar3D);