UNPKG

qwc2

Version:
304 lines (302 loc) 17.6 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 _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; } 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 2016-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 ol from 'openlayers'; import PropTypes from 'prop-types'; import { changeZoomLevel, setDisplayCrs } from '../actions/map'; import { openExternalUrl, setBottombarHeight } from '../actions/windows'; import CoordinateDisplayer from '../components/CoordinateDisplayer'; import InputContainer from '../components/widgets/InputContainer'; import NumberInput from '../components/widgets/NumberInput'; import CoordinatesUtils from '../utils/CoordinatesUtils'; import LocaleUtils from '../utils/LocaleUtils'; import MapUtils from '../utils/MapUtils'; import './style/BottomBar.css'; /** * Bottom bar, displaying mouse coordinate, scale, etc. */ var BottomBar = /*#__PURE__*/function (_React$Component) { function BottomBar() { var _this; _classCallCheck(this, BottomBar); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, BottomBar, [].concat(args)); _defineProperty(_this, "state", { scale: 0 }); _defineProperty(_this, "renderLink", function (entry) { var _entry$labelMsgId; return /*#__PURE__*/React.createElement("a", { href: entry.url, key: (_entry$labelMsgId = entry.labelMsgId) !== null && _entry$labelMsgId !== void 0 ? _entry$labelMsgId : entry.label, onClick: function onClick(ev) { return _this.openUrl(ev, entry.url, entry.urlTarget, entry.labelMsgId ? LocaleUtils.tr(entry.labelMsgId) : entry.label, entry.icon); } }, /*#__PURE__*/React.createElement("span", { className: "extra_label" }, entry.labelMsgId ? LocaleUtils.tr(entry.labelMsgId) : entry.label)); }); _defineProperty(_this, "initScaleBar", function (el) { _this.scalebar = new ol.control.ScaleLine(_objectSpread({ className: 'bottombar-scalebar', target: el, minWidth: 64, units: 'metric' }, _this.props.scalebarOptions)); MapUtils.getHook(MapUtils.GET_MAP).addControl(_this.scalebar); }); _defineProperty(_this, "openUrl", function (ev, url, target, title, icon) { if (target === "iframe") { target = ":iframedialog:externallinkiframe"; } _this.props.openExternalUrl(url, target, { title: title, icon: icon }); ev.preventDefault(); }); _defineProperty(_this, "setScale", function (value) { var scale = parseInt(value, 10); if (!isNaN(scale)) { var zoom = MapUtils.computeZoom(_this.props.map.scales, scale); _this.props.changeZoomLevel(zoom); } else { _this.props.changeZoomLevel(_this.props.map.zoom); } }); _defineProperty(_this, "storeHeight", function (el) { if (el) { _this.props.setBottombarHeight(el.clientHeight); } }); return _this; } _inherits(BottomBar, _React$Component); return _createClass(BottomBar, [{ key: "componentWillUnmount", value: function componentWillUnmount() { if (this.scalebar) { var _MapUtils$getHook, _MapUtils$getHook$rem; (_MapUtils$getHook = MapUtils.getHook(MapUtils.GET_MAP)) === null || _MapUtils$getHook === void 0 || (_MapUtils$getHook$rem = _MapUtils$getHook.removeControl) === null || _MapUtils$getHook$rem === void 0 || _MapUtils$getHook$rem.call(_MapUtils$getHook, this.scalebar); } } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { if (this.props.map !== prevProps.map) { this.setState({ scale: Math.round(MapUtils.computeForZoom(this.props.map.scales, this.props.map.zoom)) }); } } }, { key: "render", value: function render() { var _this2 = this; if (this.props.fullscreen) { return null; } var leftBottomLinks = (this.props.additionalBottomBarLinks || []).filter(function (entry) { return entry.side === "left"; }).map(this.renderLink); var rightBottomLinks = (this.props.additionalBottomBarLinks || []).filter(function (entry) { return entry.side !== "left"; }).map(this.renderLink); if (this.props.viewertitleUrl) { var entry = { url: this.props.viewertitleUrl, urlTarget: this.props.viewertitleUrlTarget, label: LocaleUtils.tr("bottombar.viewertitle_label"), icon: this.props.viewertitleUrlIcon }; rightBottomLinks.push(this.renderLink(entry)); } if (this.props.termsUrl) { var _entry = { url: this.props.termsUrl, urlTarget: this.props.termsUrlTarget, label: LocaleUtils.tr("bottombar.terms_label"), icon: this.props.termsUrlIcon }; rightBottomLinks.push(this.renderLink(_entry)); } var enabledMouseCrs = [].concat(_toConsumableArray(this.props.additionalMouseCrs || []), [this.props.map.projection, "EPSG:4326"]); // eslint-disable-next-line no-unused-vars var availableCRS = Object.fromEntries(Object.entries(CoordinatesUtils.getAvailableCRS()).filter(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1]; return enabledMouseCrs.includes(key); })); var scalebar = null; if (this.props.displayScalebar) { scalebar = /*#__PURE__*/React.createElement("div", { className: "bottombar-scalebar-container", ref: this.initScaleBar }); } var coordinates = null; if (this.props.displayCoordinates) { coordinates = /*#__PURE__*/React.createElement("div", { className: "controlgroup" }, /*#__PURE__*/React.createElement("span", { className: "bottombar-mousepos-label" }, LocaleUtils.tr("bottombar.mousepos_label"), ":\xA0"), /*#__PURE__*/React.createElement(CoordinateDisplayer, { className: "bottombar-mousepos", coordinateFormatter: this.props.coordinateFormatter, displayCrs: this.props.map.displayCrs, mapCrs: this.props.map.projection }), /*#__PURE__*/React.createElement("select", { onChange: function onChange(ev) { return _this2.props.setDisplayCrs(ev.target.value); }, value: this.props.map.displayCrs }, Object.keys(availableCRS).map(function (crs) { return /*#__PURE__*/React.createElement("option", { key: crs, value: crs }, availableCRS[crs].label); }))); } var scales = null; if (this.props.displayScales) { scales = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", { className: "bottombar-scales-label" }, LocaleUtils.tr("bottombar.scale_label"), ":\xA0"), /*#__PURE__*/React.createElement(InputContainer, { className: "bottombar-scale-combo" }, /*#__PURE__*/React.createElement("span", { className: "bottombar-scale-combo-prefix", role: "prefix" }, " 1 : "), /*#__PURE__*/React.createElement("select", { onChange: function onChange(ev) { return _this2.props.changeZoomLevel(parseInt(ev.target.value, 10)); }, role: "input", value: Math.round(this.props.map.zoom) }, this.props.map.scales.map(function (item, index) { return /*#__PURE__*/React.createElement("option", { key: index, value: index }, LocaleUtils.toLocaleFixed(item, 0)); })), /*#__PURE__*/React.createElement(NumberInput, { decimals: 0, hideArrows: true, onChange: this.setScale, role: "input", value: this.state.scale }))); } var style = { marginLeft: this.props.mapMargins.outerLeft + 'px', marginRight: this.props.mapMargins.outerRight + 'px' }; return /*#__PURE__*/React.createElement("div", { id: "BottomBar", ref: this.storeHeight, style: style }, scalebar, /*#__PURE__*/React.createElement("span", { className: "bottombar-links" }, leftBottomLinks), /*#__PURE__*/React.createElement("span", { className: "bottombar-spacer" }), coordinates, scales, /*#__PURE__*/React.createElement("span", { className: "bottombar-spacer" }), /*#__PURE__*/React.createElement("span", { className: "bottombar-links" }, rightBottomLinks)); } }]); }(React.Component); _defineProperty(BottomBar, "propTypes", { /** Additional bottombar links.`side` can be `left` or `right` (default). */ additionalBottomBarLinks: PropTypes.arrayOf(PropTypes.shape({ label: PropTypes.string, labelMsgId: PropTypes.string, side: PropTypes.string, url: PropTypes.string, urlTarget: PropTypes.string, icon: PropTypes.string })), additionalMouseCrs: PropTypes.array, changeZoomLevel: PropTypes.func, /** Custom coordinate formatter, as `(coordinate, crs) => string`. */ coordinateFormatter: PropTypes.func, /** Whether to display the coordinates in the bottom bar. */ displayCoordinates: PropTypes.bool, /** Whether to display the scalebar in the bottom bar. */ displayScalebar: PropTypes.bool, /** Whether to display the scale in the bottom bar. */ displayScales: PropTypes.bool, fullscreen: PropTypes.bool, map: PropTypes.object, mapMargins: PropTypes.object, openExternalUrl: PropTypes.func, /** See [OpenLayers API doc](https://openlayers.org/en/latest/apidoc/module-ol_control_ScaleLine-ScaleLine.html) */ scalebarOptions: PropTypes.object, setBottombarHeight: PropTypes.func, setDisplayCrs: PropTypes.func, /** The URL of the terms label anchor. */ termsUrl: PropTypes.string, /** Icon of the terms inline window. Relevant only when `termsUrlTarget` is `iframe`. */ termsUrlIcon: PropTypes.string, /** The target where to open the terms URL. If `iframe`, it will be displayed in an inline window, otherwise in a new tab. You can also use the `:iframedialog:<dialogname>:<options>` syntax to set up the inline window. */ termsUrlTarget: PropTypes.string, /** The URL of the viewer title label anchor. */ viewertitleUrl: PropTypes.string, /** Icon of the viewer title inline window. Relevant only when `viewertitleUrl` is `iframe`. */ viewertitleUrlIcon: PropTypes.string, /** The target where to open the viewer title URL. If `iframe`, it will be displayed in an inline window, otherwise in a new tab. You can also use the `:iframedialog:<dialogname>:<options>` syntax to set up the inline window. */ viewertitleUrlTarget: PropTypes.string }); _defineProperty(BottomBar, "defaultProps", { displayCoordinates: true, displayScalebar: true, displayScales: true }); export default connect(function (state) { var _state$display, _state$theme$current$, _state$theme$current; return { map: state.map, fullscreen: (_state$display = state.display) === null || _state$display === void 0 ? void 0 : _state$display.fullscreen, mapMargins: state.windows.mapMargins, additionalMouseCrs: (_state$theme$current$ = (_state$theme$current = state.theme.current) === null || _state$theme$current === void 0 ? void 0 : _state$theme$current.additionalMouseCrs) !== null && _state$theme$current$ !== void 0 ? _state$theme$current$ : [] }; }, { changeZoomLevel: changeZoomLevel, openExternalUrl: openExternalUrl, setBottombarHeight: setBottombarHeight, setDisplayCrs: setDisplayCrs })(BottomBar);