UNPKG

qwc2

Version:
730 lines (728 loc) 34.4 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 2017-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 { LayerRole, addLayer } from '../actions/layers'; import { setSnappingConfig } from '../actions/map'; import { changeRedliningState, resetRedliningState } from '../actions/redlining'; import Icon from '../components/Icon'; import TaskBar from '../components/TaskBar'; import ButtonBar from '../components/widgets/ButtonBar'; import ColorButton from '../components/widgets/ColorButton'; import ComboBox from '../components/widgets/ComboBox'; import MenuButton from '../components/widgets/MenuButton'; import NumberInput from '../components/widgets/NumberInput'; import VectorLayerPicker from '../components/widgets/VectorLayerPicker'; import ConfigUtils from '../utils/ConfigUtils'; import { END_MARKERS } from '../utils/FeatureStyles'; import LocaleUtils from '../utils/LocaleUtils'; import './style/Redlining.css'; /** * Allows drawing figures and text labels on the map. */ var Redlining = /*#__PURE__*/function (_React$Component) { function Redlining(props) { var _this; _classCallCheck(this, Redlining); _this = _callSuper(this, Redlining, [props]); _defineProperty(_this, "state", { selectText: false }); _defineProperty(_this, "onShow", function (mode, data) { var _data$geomType; _this.props.changeRedliningState(_objectSpread({ action: mode !== null && mode !== void 0 ? mode : 'Pick', geomType: (_data$geomType = data === null || data === void 0 ? void 0 : data.geomType) !== null && _data$geomType !== void 0 ? _data$geomType : null }, _this.redliningStateDefaults())); _this.props.setSnappingConfig(_this.props.snapping, _this.props.snappingActive); if (data && data.layerId) { var layer = _this.props.layers.find(function (l) { return l.id === data.layerId; }); if (layer) { _this.changeRedliningLayer(layer); } } }); _defineProperty(_this, "onHide", function () { _this.props.resetRedliningState(); }); _defineProperty(_this, "redliningStateDefaults", function () { return { style: _objectSpread(_objectSpread({}, _this.props.redlining.style), {}, { borderColor: _this.props.defaultBorderColor, fillColor: _this.props.defaultFillColor, textOutlineColor: _this.props.defaultTextOutlineColor, textFillColor: _this.props.defaultTextFillColor }), lenUnit: _this.props.defaultLengthUnit, areaUnit: _this.props.defaultAreaUnit }; }); _defineProperty(_this, "generateDashIcons", function () { _this.dashIcons = _this.props.predefinedDashPatterns.reduce(function (res, pattern) { var svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"16\"><line x1=\"0\" y1=\"8\" x2=\"32\" y2=\"8\" stroke=\"black\" stroke-width=\"2\" stroke-dasharray=\"".concat(pattern.join(" "), "\"></line></svg>"); res[pattern.join(":")] = "data:image/svg+xml;base64,".concat(btoa(svg)); return res; }, {}); }); _defineProperty(_this, "updateRedliningStyle", function (diff) { var newStyle = _objectSpread(_objectSpread({}, _this.props.redlining.style), diff); _this.props.changeRedliningState({ style: newStyle }); }); _defineProperty(_this, "renderBody", function () { var _this$props$layers$fi; var toolEnabled = function toolEnabled(tool) { return !_this.props.hiddenTools.includes(tool); }; var activeButton = _this.props.redlining.action === "Draw" ? _this.props.redlining.geomType : _this.props.redlining.action; var drawButtons = [{ key: "Point", tooltip: LocaleUtils.tr("redlining.point"), icon: "point", data: { action: "Draw", geomType: "Point", text: "" } }, { key: "LineString", tooltip: LocaleUtils.tr("redlining.line"), icon: "line", data: { action: "Draw", geomType: "LineString", text: "" } }, [{ key: "Polygon", tooltip: LocaleUtils.tr("redlining.polygon"), icon: "polygon", data: { action: "Draw", geomType: "Polygon", text: "" } }, toolEnabled("Circle") ? { key: "Circle", tooltip: LocaleUtils.tr("redlining.circle"), icon: "circle", data: { action: "Draw", geomType: "Circle", text: "" } } : null, toolEnabled("Ellipse") ? { key: "Ellipse", tooltip: LocaleUtils.tr("redlining.ellipse"), icon: "ellipse", data: { action: "Draw", geomType: "Ellipse", text: "" } } : null, toolEnabled("Square") ? { key: "Square", tooltip: LocaleUtils.tr("redlining.square"), icon: "box", data: { action: "Draw", geomType: "Square", text: "" } } : null, toolEnabled("Box") ? { key: "Box", tooltip: LocaleUtils.tr("redlining.rectangle"), icon: "rect", data: { action: "Draw", geomType: "Box", text: "" } } : null].filter(Boolean), { key: "Text", tooltip: LocaleUtils.tr("redlining.text"), icon: "text", data: { action: "Draw", geomType: "Text", text: "", measurements: false } }]; if (ConfigUtils.isMobile()) { drawButtons = [drawButtons.flat()]; } var activeFreeHand = _this.props.redlining.freehand ? "HandDrawing" : null; var freehandButtons = toolEnabled("HandWriting") ? [{ key: "HandDrawing", tooltip: LocaleUtils.tr("redlining.freehand"), icon: "freehand", data: { action: "Draw", geomType: _this.props.redlining.geomType, text: "", freehand: !_this.props.redlining.freehand }, disabled: _this.props.redlining.geomType !== "LineString" && _this.props.redlining.geomType !== "Polygon" }] : []; var editButtons = [{ key: "Pick", tooltip: LocaleUtils.tr("redlining.pick"), icon: "nodetool", data: { action: "Pick", geomType: null, text: "" } }, toolEnabled("Transform") ? { key: "Transform", tooltip: LocaleUtils.tr("redlining.transform"), icon: "transformtool", data: { action: "Transform", geomType: null, text: "" } } : null, toolEnabled("Clone") ? { key: "Clone", tooltip: LocaleUtils.tr("redlining.clone"), icon: "clone", data: { action: "Clone", geomType: null }, disabled: !_this.props.redlining.selectedFeature } : null, { key: "Delete", tooltip: LocaleUtils.tr("redlining.delete"), icon: "trash", data: { action: "Delete", geomType: null }, disabled: !_this.props.redlining.selectedFeature }].filter(Boolean); var extraButtons = toolEnabled("NumericInput") ? [{ key: "NumericInput", tooltip: LocaleUtils.tr("redlining.numericinput"), icon: "numericinput" }, { key: "FeatureAttributes", tooltip: LocaleUtils.tr("redlining.attributes"), icon: "list-alt" }] : []; for (var _i = 0, _Object$values = Object.values(_this.props.plugins || {}); _i < _Object$values.length; _i++) { var plugin = _Object$values[_i]; if (toolEnabled(plugin.cfg.key)) { editButtons.push(_objectSpread(_objectSpread({}, plugin.cfg), {}, { tooltip: plugin.cfg.tooltip ? LocaleUtils.tr(plugin.cfg.tooltip) : undefined })); } } var vectorLayers = _this.props.layers.filter(function (layer) { return layer.type === "vector" && layer.role === LayerRole.USERLAYER && !layer.readonly; }); // Ensure list always contains at least a "Redlining" layer if (vectorLayers.length === 0) { vectorLayers = [{ id: 'redlining', title: LocaleUtils.tr('redlining.layertitle') }].concat(_toConsumableArray(vectorLayers)); } var haveLayer = (((_this$props$layers$fi = _this.props.layers.find(function (l) { return l.id === _this.props.redlining.layer; })) === null || _this$props$layers$fi === void 0 || (_this$props$layers$fi = _this$props$layers$fi.features) === null || _this$props$layers$fi === void 0 ? void 0 : _this$props$layers$fi.length) || 0) > 0; var activePlugin = Object.values(_this.props.plugins || {}).find(function (plugin) { return plugin.cfg.key === _this.props.redlining.action; }); var controls = activePlugin ? /*#__PURE__*/React.createElement(activePlugin.controls, null) : _this.renderStandardControls(); return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", { className: "redlining-controlsbar" }, /*#__PURE__*/React.createElement("div", { className: "redlining-groupcontrol" }, /*#__PURE__*/React.createElement("div", null, LocaleUtils.tr("redlining.layer")), /*#__PURE__*/React.createElement(VectorLayerPicker, { addLayer: _this.props.addLayer, layers: vectorLayers, onChange: _this.changeRedliningLayer, value: _this.props.redlining.layer })), /*#__PURE__*/React.createElement("div", { className: "redlining-groupcontrol" }, /*#__PURE__*/React.createElement("div", null, LocaleUtils.tr("redlining.draw")), /*#__PURE__*/React.createElement("div", { className: "controlgroup" }, /*#__PURE__*/React.createElement(ButtonBar, { active: activeButton, buttons: drawButtons, onClick: function onClick(key, data) { return _this.actionChanged(data); } }), _this.props.redlining.action === "Draw" && (_this.props.redlining.geomType === "LineString" || _this.props.redlining.geomType === "Polygon") ? /*#__PURE__*/React.createElement(ButtonBar, { active: activeFreeHand, buttons: freehandButtons, onClick: function onClick(key, data) { return _this.actionChanged(data); } }) : null)), /*#__PURE__*/React.createElement("div", { className: "redlining-groupcontrol" }, /*#__PURE__*/React.createElement("div", null, LocaleUtils.tr("redlining.edit")), /*#__PURE__*/React.createElement(ButtonBar, { active: activeButton, buttons: editButtons, onClick: function onClick(key, data) { return _this.actionChanged(data); } })), /*#__PURE__*/React.createElement("div", { className: "redlining-groupcontrol" }, /*#__PURE__*/React.createElement("div", null, "\xA0"), /*#__PURE__*/React.createElement(ButtonBar, { active: _this.props.redlining.extraAction, buttons: extraButtons, onClick: function onClick(key) { return _this.props.changeRedliningState({ extraAction: key }); } })), toolEnabled("Export") ? /*#__PURE__*/React.createElement("div", { className: "redlining-groupcontrol" }, /*#__PURE__*/React.createElement("div", null, "\xA0"), /*#__PURE__*/React.createElement(MenuButton, { className: "redlining-export-menu", disabled: !haveLayer, menuIcon: "export", onActivate: _this["export"], tooltip: LocaleUtils.tr("redlining.export") }, /*#__PURE__*/React.createElement("div", { className: "redlining-export-menu-entry", key: "GeoJSON", value: "geojson" }, "GeoJSON"), /*#__PURE__*/React.createElement("div", { className: "redlining-export-menu-entry", key: "KML", value: "kml" }, "KML"))) : null), controls); }); _defineProperty(_this, "export", function (format) { _this.props.changeRedliningState({ action: 'Export', format: format }); }); _defineProperty(_this, "renderStandardControls", function () { var sizeLabel = LocaleUtils.tr("redlining.line"); var showDash = true; if (["Text", "Point"].includes(_this.props.redlining.geomType)) { sizeLabel = LocaleUtils.tr("redlining.size"); showDash = false; } var labelPlaceholder = LocaleUtils.tr("redlining.label"); if (_this.props.redlining.geomType === "Text") { labelPlaceholder = LocaleUtils.tr("redlining.text"); } if (_this.props.redlining.action !== 'Draw' && !_this.props.redlining.selectedFeature) { if (_this.props.redlining.action === 'Transform') { return /*#__PURE__*/React.createElement("div", { className: "redlining-message" }, LocaleUtils.tr("redlining.ctrlhint")); } else { return null; } } return /*#__PURE__*/React.createElement("div", { className: "redlining-controlsbar" }, /*#__PURE__*/React.createElement("div", { className: "redlining-control" }, /*#__PURE__*/React.createElement(Icon, { className: "redlining-control-icon", icon: "pen", size: "large" }), _this.props.redlining.geomType === 'Text' ? /*#__PURE__*/React.createElement(ColorButton, { color: _this.props.redlining.style.textOutlineColor, defaultColors: _this.props.predefinedBorderColors, onColorChanged: function onColorChanged(color) { return _this.updateRedliningStyle({ textOutlineColor: color }); } }) : /*#__PURE__*/React.createElement(ColorButton, { color: _this.props.redlining.style.borderColor, defaultColors: _this.props.predefinedBorderColors, onColorChanged: function onColorChanged(color) { return _this.updateRedliningStyle({ borderColor: color }); } })), _this.props.redlining.geomType === 'LineString' ? null : /*#__PURE__*/React.createElement("div", { className: "redlining-control" }, /*#__PURE__*/React.createElement(Icon, { className: "redlining-control-icon", icon: "fill", size: "large" }), _this.props.redlining.geomType === 'Text' ? /*#__PURE__*/React.createElement(ColorButton, { color: _this.props.redlining.style.textFillColor, defaultColors: _this.props.predefinedFillColors, onColorChanged: function onColorChanged(color) { return _this.updateRedliningStyle({ textFillColor: color }); } }) : /*#__PURE__*/React.createElement(ColorButton, { color: _this.props.redlining.style.fillColor, defaultColors: _this.props.predefinedFillColors, onColorChanged: function onColorChanged(color) { return _this.updateRedliningStyle({ fillColor: color }); } })), /*#__PURE__*/React.createElement("div", { className: "redlining-control" }, /*#__PURE__*/React.createElement("span", null, sizeLabel, ":\xA0"), /*#__PURE__*/React.createElement(NumberInput, { max: 99, min: 1, mobile: true, onChange: function onChange(nr) { return _this.updateRedliningStyle({ size: nr }); }, value: _this.props.redlining.style.size }), showDash ? /*#__PURE__*/React.createElement(ComboBox, { onChange: function onChange(value) { return _this.updateRedliningStyle({ strokeDash: value.split(":").filter(Boolean).map(Number) }); }, value: _this.props.redlining.style.strokeDash.join(":") }, _this.props.predefinedDashPatterns.map(function (pattern) { var value = pattern.join(":"); return /*#__PURE__*/React.createElement("div", { className: "redlining-dash-combo-entry", key: value, value: value }, /*#__PURE__*/React.createElement("img", { src: _this.dashIcons[value] })); })) : null), _this.props.redlining.geomType === 'LineString' ? /*#__PURE__*/React.createElement("div", { className: "redlining-control" }, /*#__PURE__*/React.createElement("span", null, LocaleUtils.tr("redlining.markers"), ":\xA0"), /*#__PURE__*/React.createElement("div", { className: "controlgroup" }, /*#__PURE__*/React.createElement(ComboBox, { className: "redlining-marker-combo", onChange: function onChange(value) { return _this.updateRedliningStyle({ headmarker: value }); }, value: _this.props.redlining.style.headmarker || "" }, /*#__PURE__*/React.createElement("div", { className: "redlining-marker-combo-entry", value: "" }), Object.entries(END_MARKERS).map(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], params = _ref2[1]; return /*#__PURE__*/React.createElement("div", { className: "redlining-marker-combo-entry", key: key, value: key }, /*#__PURE__*/React.createElement("img", { src: params.src, style: { transform: 'rotate(' + params.baserotation + 'deg)' } })); })), /*#__PURE__*/React.createElement(ComboBox, { className: "redlining-marker-combo", onChange: function onChange(value) { return _this.updateRedliningStyle({ tailmarker: value }); }, value: _this.props.redlining.style.tailmarker || "" }, /*#__PURE__*/React.createElement("div", { className: "redlining-marker-combo-entry", value: "" }), Object.entries(END_MARKERS).map(function (_ref3) { var _ref4 = _slicedToArray(_ref3, 2), key = _ref4[0], params = _ref4[1]; return /*#__PURE__*/React.createElement("div", { className: "redlining-marker-combo-entry", key: key, value: key }, /*#__PURE__*/React.createElement("img", { src: params.src, style: { transform: 'rotate(' + (180 + params.baserotation) + 'deg)' } })); })))) : null, /*#__PURE__*/React.createElement("div", { className: "redlining-control redlining-control-fill" }, /*#__PURE__*/React.createElement("div", { className: "controlgroup" }, _this.props.redlining.geomType !== 'Text' && _this.props.allowGeometryLabels ? /*#__PURE__*/React.createElement("button", { className: "button" + (_this.props.redlining.measurements ? " pressed" : ""), onClick: function onClick() { return _this.props.changeRedliningState({ measurements: !_this.props.redlining.measurements, style: _objectSpread(_objectSpread({}, _this.props.redlining.style), {}, { text: '' }) }); }, title: LocaleUtils.tr("redlining.measurements") }, /*#__PURE__*/React.createElement(Icon, { icon: "measure" })) : null, (_this.props.redlining.geomType === 'Text' || _this.props.allowGeometryLabels) && !_this.props.redlining.measurements ? /*#__PURE__*/React.createElement("input", { className: "controlgroup-fillitem", onChange: function onChange(ev) { return _this.updateRedliningStyle({ text: ev.target.value }); }, placeholder: labelPlaceholder, readOnly: _this.props.redlining.measurements, ref: function ref(el) { return _this.setLabelRef(el); }, type: "text", value: _this.props.redlining.style.text }) : null, _this.props.redlining.measurements && ['LineString', 'Circle'].includes(_this.props.redlining.geomType) ? /*#__PURE__*/React.createElement("select", { className: "controlgroup-fillitem", onChange: function onChange(ev) { return _this.props.changeRedliningState({ lenUnit: ev.target.value }); }, value: _this.props.redlining.lenUnit }, /*#__PURE__*/React.createElement("option", { value: "metric" }, LocaleUtils.tr("measureComponent.metric")), /*#__PURE__*/React.createElement("option", { value: "imperial" }, LocaleUtils.tr("measureComponent.imperial")), /*#__PURE__*/React.createElement("option", { value: "m" }, "m"), /*#__PURE__*/React.createElement("option", { value: "km" }, "km"), /*#__PURE__*/React.createElement("option", { value: "ft" }, "ft"), /*#__PURE__*/React.createElement("option", { value: "mi" }, "mi")) : null, _this.props.redlining.measurements && ['Polygon', 'Ellipse', 'Square', 'Box'].includes(_this.props.redlining.geomType) ? /*#__PURE__*/React.createElement("select", { className: "controlgroup-fillitem", onChange: function onChange(ev) { return _this.props.changeRedliningState({ areaUnit: ev.target.value }); }, value: _this.props.redlining.areaUnit }, /*#__PURE__*/React.createElement("option", { value: "metric" }, LocaleUtils.tr("measureComponent.metric")), /*#__PURE__*/React.createElement("option", { value: "imperial" }, LocaleUtils.tr("measureComponent.imperial")), /*#__PURE__*/React.createElement("option", { value: "sqm" }, "m\xB2"), /*#__PURE__*/React.createElement("option", { value: "ha" }, "ha"), /*#__PURE__*/React.createElement("option", { value: "sqkm" }, "km\xB2"), /*#__PURE__*/React.createElement("option", { value: "sqft" }, "ft\xB2"), /*#__PURE__*/React.createElement("option", { value: "acre" }, "acre"), /*#__PURE__*/React.createElement("option", { value: "sqmi" }, "mi\xB2")) : null))); }); _defineProperty(_this, "setLabelRef", function (el) { _this.labelInput = el; if (el && _this.state.selectText) { el.focus(); el.select(); _this.setState({ selectText: false }); } }); _defineProperty(_this, "actionChanged", function (data) { if (data.action === "Draw" && data.geomType === "Text") { data = _objectSpread(_objectSpread({}, data), {}, { style: { text: LocaleUtils.tr("redlining.text") } }); } else if (!_this.props.allowGeometryLabels) { data = _objectSpread(_objectSpread({}, data), {}, { style: { text: '' } }); } _this.props.changeRedliningState(data); }); _defineProperty(_this, "changeRedliningLayer", function (layer) { var action = ["Draw", "Pick", "Transform"].includes(_this.props.redlining.action) ? _this.props.redlining.action : "Pick"; _this.props.changeRedliningState({ layer: layer.id, layerTitle: layer.title, action: action }); }); _this.labelInput = null; _this.dashIcons = {}; return _this; } _inherits(Redlining, _React$Component); return _createClass(Redlining, [{ key: "componentDidMount", value: function componentDidMount() { this.componentDidUpdate({ redlining: {} }); } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { var _this2 = this; if (this.props.defaultBorderColor !== prevProps.defaultBorderColor || this.props.defaultFillColor !== prevProps.defaultFillColor || this.props.defaultLengthUnit !== prevProps.defaultLengthUnit || this.props.defaultAreaUnit !== prevProps.defaultAreaUnit || this.props.defaultTextFillColor !== prevProps.defaultTextFillColor || this.props.defaultTextOutlineColor !== prevProps.defaultTextOutlineColor) { this.props.changeRedliningState(this.redliningStateDefaults()); } if (prevProps.redlining.geomType !== this.props.redlining.geomType && this.props.redlining.geomType === 'Text' && !this.state.selectText) { this.setState({ selectText: true }); } if (!this.props.layers.find(function (layer) { return layer.id === _this2.props.redlining.layer; })) { var vectorLayers = this.props.layers.filter(function (layer) { return layer.type === "vector" && layer.role === LayerRole.USERLAYER && !layer.readonly; }); if (vectorLayers.length >= 1) { this.props.changeRedliningState({ layer: vectorLayers[0].id, layerTitle: vectorLayers[0].title }); } else if (this.props.redlining.layer !== 'redlining') { this.props.changeRedliningState({ layer: 'redlining', layerTitle: LocaleUtils.tr('redlining.layertitle') }); } } if (this.props.predefinedDashPatterns !== prevProps.predefinedDashPatterns) { this.generateDashIcons(); } } }, { key: "render", value: function render() { var _this3 = this; return /*#__PURE__*/React.createElement(TaskBar, { onHide: this.onHide, onShow: this.onShow, task: "Redlining" }, function () { return { body: _this3.renderBody() }; }); } }]); }(React.Component); _defineProperty(Redlining, "propTypes", { addLayer: PropTypes.func, /** Whether to allow labeling geometric figures. */ allowGeometryLabels: PropTypes.bool, changeRedliningState: PropTypes.func, /** Default area unit. Options: `metric`, `imperial`, `sqm`, `ha`, `sqkm`, `sqft`, `acre`, `sqmi` */ defaultAreaUnit: PropTypes.string, /** Default border color. In format `[r, g, b, a]`. */ defaultBorderColor: PropTypes.array, /** Default fill color. In format `[r, g, b, a]`. */ defaultFillColor: PropTypes.array, /** Default length unit. Options: `metric`, `imperial`, `m`, `km`, `ft`, `mi` */ defaultLengthUnit: PropTypes.string, /** Default text fill color. In format `[r, g, b, a]`. */ defaultTextFillColor: PropTypes.array, /** Default text outline color. In format `[r, g, b, a]`. */ defaultTextOutlineColor: PropTypes.array, /** Tools to hide. Available tools: `Circle`, `Ellipse`, `Square`, `Box`, `HandDrawing`, `Transform`, `NumericInput`, `Buffer`, `Export`. */ hiddenTools: PropTypes.array, layers: PropTypes.array, mapCrs: PropTypes.string, plugins: PropTypes.object, /** Predefined border colors. In format `[[r, g, b, a], ...]`. */ predefinedBorderColors: PropTypes.arrayOf(PropTypes.array), /** Predefined dash patterns. In format `[<dash-array>, ...]`, where a dash-array is list of alternating dash and gap widths, i.e. `[8 4]` for long dashes followed by shorter gaps. */ predefinedDashPatterns: PropTypes.arrayOf(PropTypes.array), /** Predefined fill colors. In format `[[r, g, b, a], ...]`. */ predefinedFillColors: PropTypes.arrayOf(PropTypes.array), redlining: PropTypes.object, resetRedliningState: PropTypes.func, setCurrentTask: PropTypes.func, setSnappingConfig: PropTypes.func, /** Whether snapping is available when editing. */ snapping: PropTypes.bool, /** Whether snapping is enabled by default when editing. * Either `false`, `edge`, `vertex` or `true` (i.e. both vertex and edge). */ snappingActive: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]) }); _defineProperty(Redlining, "defaultProps", { allowGeometryLabels: true, hiddenTools: [], snapping: true, snappingActive: true, plugins: [], defaultBorderColor: [255, 0, 0, 1], defaultFillColor: [255, 255, 255, 1], defaultTextFillColor: [0, 0, 0, 1], defaultTextOutlineColor: [255, 255, 255, 1], defaultAreaUnit: 'metric', defaultLengthUnit: 'metric', predefinedDashPatterns: [[], [8, 8], [1, 8], [8, 8, 1, 8]] }); export default (function (plugins) { return connect(function (state) { return { layers: state.layers.flat, redlining: state.redlining, mapCrs: state.map.projection, plugins: plugins }; }, { changeRedliningState: changeRedliningState, addLayer: addLayer, resetRedliningState: resetRedliningState, setSnappingConfig: setSnappingConfig })(Redlining); });