UNPKG

qwc2

Version:
183 lines (181 loc) 9.82 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 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 2020-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 { v4 as uuidv4 } from 'uuid'; import { LayerRole, addLayerFeatures, removeLayer, clearLayer } from '../actions/layers'; import { setSnappingConfig } from '../actions/map'; import { changeRedliningState, resetRedliningState } from '../actions/redlining'; import { setCurrentTask } from '../actions/task'; import TaskBar from '../components/TaskBar'; import LocaleUtils from '../utils/LocaleUtils'; import './style/Redlining.css'; import './style/ScratchDrawing.css'; /** * Task which which can be invoked by other tools to draw a geometry and pass it to a callback. * * Only useful for third-party code, i.e. over the JavaScript API. * * Invoke as `setCurrentTask("ScratchDrawing", null, null, {callback: <function(features, crs)>});` */ var ScratchDrawing = /*#__PURE__*/function (_React$Component) { function ScratchDrawing(props) { var _this; _classCallCheck(this, ScratchDrawing); _this = _callSuper(this, ScratchDrawing, [props]); _defineProperty(_this, "createDrawLayer", function (data) { var layerId = uuidv4(); var features = (data.initialFeatures || []).map(function (feature) { return _objectSpread(_objectSpread({}, feature), {}, { id: uuidv4(), shape: feature.geometry.type, styleName: 'default', styleOptions: _this.styleOptions(_this.drawingStyle(data.style)) }); }); var layer = { id: layerId, role: LayerRole.USERLAYER, type: 'vector' }; _this.props.addLayerFeatures(layer, features, true); return layerId; }); _defineProperty(_this, "drawingStyle", function (style) { return _objectSpread({ borderColor: [255, 0, 0, 1], size: 2, fillColor: [255, 255, 255, 0.5], text: "" }, style); }); _defineProperty(_this, "styleOptions", function (styleProps) { return { strokeColor: styleProps.borderColor, strokeWidth: 1 + 0.5 * styleProps.size, fillColor: styleProps.fillColor, circleRadius: 5 + styleProps.size, strokeDash: [], headmarker: styleProps.headmarker, tailmarker: styleProps.tailmarker }; }); _defineProperty(_this, "submitGeometry", function () { var _this$props$layers$fi; var features = ((_this$props$layers$fi = _this.props.layers.find(function (l) { return l.id === _this.props.redlining.layer; })) === null || _this$props$layers$fi === void 0 ? void 0 : _this$props$layers$fi.features) || []; _this.submitted = true; _this.props.task.data.callback(features, _this.props.projection); _this.props.setCurrentTask(null); }); _this.submitted = false; return _this; } _inherits(ScratchDrawing, _React$Component); return _createClass(ScratchDrawing, [{ key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { // Clear when task changes if (this.props.task.id !== "ScratchDrawing" && prevProps.task.id === "ScratchDrawing") { if (!this.submitted) { prevProps.task.data.callback(null, null); this.submitted = true; } this.props.removeLayer(prevProps.redlining.layer); this.props.resetRedliningState(); } // Setup redlining state if (this.props.task !== prevProps.task && this.props.task.id === "ScratchDrawing") { if (prevProps.task.id === "ScratchDrawing") { this.props.removeLayer(prevProps.redlining.layer); if (!this.submitted) { prevProps.task.data.callback(null, null); this.submitted = true; } } this.submitted = false; var data = this.props.task.data; var layerId = this.createDrawLayer(data); this.props.setSnappingConfig(data.snapping, data.snappingActive); this.props.changeRedliningState({ action: 'PickDraw', geomType: data.geomType, layer: layerId, layerTitle: null, drawMultiple: data.drawMultiple, style: this.drawingStyle(data.style) }); } } }, { key: "render", value: function render() { var _this$props$task$data, _this2 = this; return /*#__PURE__*/React.createElement(TaskBar, { task: "ScratchDrawing" }, /*#__PURE__*/React.createElement("div", { className: "scratch-drawing-taskbar-body", role: "body" }, /*#__PURE__*/React.createElement("span", null, (_this$props$task$data = this.props.task.data) === null || _this$props$task$data === void 0 ? void 0 : _this$props$task$data.message), /*#__PURE__*/React.createElement("button", { className: "button", onClick: function onClick() { return _this2.submitGeometry(); } }, LocaleUtils.tr("scratchdrawing.finish")))); } }]); }(React.Component); _defineProperty(ScratchDrawing, "propTypes", { addLayerFeatures: PropTypes.func, changeRedliningState: PropTypes.func, clearLayer: PropTypes.func, layers: PropTypes.array, projection: PropTypes.string, redlining: PropTypes.object, removeLayer: PropTypes.func, resetRedliningState: PropTypes.func, setCurrentTask: PropTypes.func, setSnappingConfig: PropTypes.func, task: PropTypes.object }); export default connect(function (state) { return { task: state.task, layers: state.layers.flat, redlining: state.redlining, projection: state.map.projection, theme: state.theme.current }; }, { changeRedliningState: changeRedliningState, addLayerFeatures: addLayerFeatures, clearLayer: clearLayer, removeLayer: removeLayer, resetRedliningState: resetRedliningState, setCurrentTask: setCurrentTask, setSnappingConfig: setSnappingConfig })(ScratchDrawing);