qwc2-lts
Version:
QGIS Web Client
268 lines (266 loc) • 15.5 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 _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 _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 PropTypes from 'prop-types';
import { changeZoomLevel, setBottombarHeight, setDisplayCrs } from '../actions/map';
import { openExternalUrl } from '../actions/windows';
import CoordinateDisplayer from '../components/CoordinateDisplayer';
import InputContainer from '../components/widgets/InputContainer';
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, "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: "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 bottomLinks = (this.props.additionalBottomBarLinks || []).map(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 _this2.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));
});
if (this.props.viewertitleUrl) {
bottomLinks.push(/*#__PURE__*/React.createElement("a", {
href: this.props.viewertitleUrl,
key: "viewertitle",
onClick: function onClick(ev) {
return _this2.openUrl(ev, _this2.props.viewertitleUrl, _this2.props.viewertitleUrlTarget, LocaleUtils.tr("bottombar.viewertitle_label"), _this2.props.viewertitleUrlIcon);
}
}, /*#__PURE__*/React.createElement("span", {
className: "viewertitle_label"
}, LocaleUtils.tr("bottombar.viewertitle_label"))));
}
if (this.props.termsUrl) {
bottomLinks.push(/*#__PURE__*/React.createElement("a", {
href: this.props.termsUrl,
key: "terms",
onClick: function onClick(ev) {
return _this2.openUrl(ev, _this2.props.termsUrl, _this2.props.termsUrlTarget, LocaleUtils.tr("bottombar.terms_label"), _this2.props.termsUrlIcon);
}
}, /*#__PURE__*/React.createElement("span", {
className: "terms_label"
}, LocaleUtils.tr("bottombar.terms_label"))));
}
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 coordinates = null;
if (this.props.displayCoordinates) {
coordinates = /*#__PURE__*/React.createElement("div", {
className: "controlgroup"
}, /*#__PURE__*/React.createElement("span", null, LocaleUtils.tr("bottombar.mousepos_label"), ":\xA0"), /*#__PURE__*/React.createElement(CoordinateDisplayer, {
className: "bottombar-mousepos",
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", null, 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("input", {
onBlur: function onBlur(ev) {
return _this2.setScale(ev.target.value);
},
onChange: function onChange(ev) {
return _this2.setState({
scale: ev.target.value
});
},
onKeyUp: function onKeyUp(ev) {
if (ev.key === 'Enter') _this2.setScale(ev.target.value);
},
role: "input",
type: "text",
value: this.state.scale
})));
}
var style = this.props.mapMargins.splitTopAndBottomBar ? {
marginLeft: this.props.mapMargins.left + 'px',
marginRight: this.props.mapMargins.right + 'px'
} : {};
return /*#__PURE__*/React.createElement("div", {
id: "BottomBar",
ref: this.storeHeight,
style: style
}, /*#__PURE__*/React.createElement("span", {
className: "bottombar-spacer"
}), coordinates, scales, /*#__PURE__*/React.createElement("span", {
className: "bottombar-spacer"
}), /*#__PURE__*/React.createElement("span", {
className: "bottombar-links"
}, bottomLinks));
}
}]);
}(React.Component);
_defineProperty(BottomBar, "propTypes", {
/** Additional bottombar links */
additionalBottomBarLinks: PropTypes.arrayOf(PropTypes.shape({
label: PropTypes.string,
labelMsgId: PropTypes.string,
url: PropTypes.string,
urlTarget: PropTypes.string,
icon: PropTypes.string
})),
additionalMouseCrs: PropTypes.array,
changeZoomLevel: PropTypes.func,
/** Whether to display the coordinates in the bottom bar. */
displayCoordinates: 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,
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,
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);