UNPKG

qwc2

Version:
742 lines (738 loc) 36.8 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 _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 _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 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 _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 _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 _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 _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 _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 { parseNumber } from '@norbulcz/num-parse'; import dateParser from 'any-date-parser'; import isEmpty from 'lodash.isempty'; import isEqual from 'lodash.isequal'; import PropTypes from 'prop-types'; import { v4 as uuidv4 } from 'uuid'; import { setEditContext, clearEditContext } from '../actions/editing'; import { addLayerFeatures, removeLayer, changeLayerProperty } from '../actions/layers'; import { setSnappingConfig } from '../actions/map'; import { setCurrentTask, setCurrentTaskBlocked } from '../actions/task'; import AttributeForm from '../components/AttributeForm'; import Icon from '../components/Icon'; import PickFeature from '../components/PickFeature'; import SideBar from '../components/SideBar'; import ButtonBar from '../components/widgets/ButtonBar'; import ConfigUtils from '../utils/ConfigUtils'; import EditingInterface from '../utils/EditingInterface'; import { getFeatureTemplate } from '../utils/EditingUtils'; import LayerUtils from '../utils/LayerUtils'; import LocaleUtils from '../utils/LocaleUtils'; import MapUtils from '../utils/MapUtils'; import './style/Editing.css'; /** * Allows editing geometries and attributes of datasets. * * The attribute form is generated from the QGIS attribute form configuration. * * This plugin queries the dataset via the editing service specified by * `editServiceUrl` in `config.json` (by default the `qwc-data-service`). */ var Editing = /*#__PURE__*/function (_React$Component) { function Editing() { var _this; _classCallCheck(this, Editing); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, Editing, [].concat(args)); _defineProperty(_this, "state", { selectedLayer: null, selectedLayerVisibility: null, pickedFeatures: null, busy: false, minimized: false, drawPick: false, pendingClone: null }); _defineProperty(_this, "onShow", function () { if (_this.props.taskData) { _this.changeSelectedLayer(_this.props.taskData.layer, _this.props.taskData.feature); } else { _this.changeSelectedLayer(_this.state.selectedLayer); } _this.props.setSnappingConfig(_this.props.snapping, _this.props.snappingActive); }); _defineProperty(_this, "onHide", function () { _this.props.clearEditContext('Editing'); _this.setLayerVisibility(_this.state.selectedLayer, _this.state.selectedLayerVisibility); _this.setState({ minimized: false, drawPick: false }); }); _defineProperty(_this, "renderCloneAttributeDialog", function () { var quickButtons = [{ key: 'All', label: LocaleUtils.tr("editing.clone_all") }, { key: 'None', label: LocaleUtils.tr("editing.clone_none") }, { key: 'Visible', label: LocaleUtils.tr("editing.clone_visible") }]; var actionButtons = [{ key: 'Copy', label: LocaleUtils.tr("editing.clone_copy"), icon: "ok", extraClasses: "button-accept" }, { key: 'DontCopy', label: LocaleUtils.tr("editing.clone_dontcopy"), icon: "remove", extraClasses: "button-reject" }]; return /*#__PURE__*/React.createElement("div", { className: "editing-body" }, /*#__PURE__*/React.createElement("div", { className: "editing-clone-dialog" }, /*#__PURE__*/React.createElement("div", { className: "editing-clone-header" }, LocaleUtils.tr("editing.clone_select_attrs")), /*#__PURE__*/React.createElement(ButtonBar, { buttons: quickButtons, onClick: _this.onCloneAttrQuickSelect }), /*#__PURE__*/React.createElement("table", { className: "editing-clone-table" }, /*#__PURE__*/React.createElement("tbody", null, _this.state.pendingClone.matchingAttributes.map(function (attr) { return /*#__PURE__*/React.createElement("tr", { key: attr.fieldId }, /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("label", { className: "editing-clone-attribute", key: attr.fieldId }, /*#__PURE__*/React.createElement("input", { checked: _this.state.pendingClone.selectedAttributes.includes(attr.fieldId), onChange: function onChange() { return _this.toggleAttribute(attr.fieldId); }, type: "checkbox" }), /*#__PURE__*/React.createElement("span", { className: "editing-clone-attribute-name" }, attr.fieldName, !attr.visible ? /*#__PURE__*/React.createElement("i", null, " " + LocaleUtils.tr("editing.clone_hidden")) : "", attr.autoCalculated ? /*#__PURE__*/React.createElement("i", null, " " + LocaleUtils.tr("editing.clone_defaulted")) : ""))), /*#__PURE__*/React.createElement("td", { title: attr.value }, attr.value)); }))), /*#__PURE__*/React.createElement(ButtonBar, { buttons: actionButtons, onClick: _this.onCloneAction }))); }); _defineProperty(_this, "renderBody", function () { var _this$props$editConte, _editConfig$permissio; // Show clone attribute selection dialog if pending if (_this.state.pendingClone) { return _this.renderCloneAttributeDialog(); } if (!_this.props.theme || isEmpty(_this.props.editConfigs)) { return /*#__PURE__*/React.createElement("div", { role: "body", style: { padding: "1em" } }, LocaleUtils.tr("editing.noeditablelayers")); } var editConfig = (_this$props$editConte = _this.props.editContext) === null || _this$props$editConte === void 0 ? void 0 : _this$props$editConte.editConfig; var editPermissions = (_editConfig$permissio = editConfig === null || editConfig === void 0 ? void 0 : editConfig.permissions) !== null && _editConfig$permissio !== void 0 ? _editConfig$permissio : {}; var actionButtons = []; actionButtons.push({ key: 'Pick', icon: 'pick', label: LocaleUtils.tr("editing.pick"), data: { action: 'Pick', feature: null } }); if (editPermissions.creatable !== false && !_this.props.editContext.geomReadOnly) { actionButtons.push({ key: 'Draw', icon: 'editdraw', label: LocaleUtils.tr("editing.draw"), data: { action: 'Draw' } }); } if (ConfigUtils.havePlugin("AttributeTable") && _this.props.showAttributeTableButton) { actionButtons.push({ key: 'AttribTable', icon: 'editing', label: LocaleUtils.tr("editing.attrtable"), data: { action: 'AttrTable' } }); } var featureSelection = null; if (editConfig && _this.state.pickedFeatures && _this.state.pickedFeatures.length > 1) { var featureText = LocaleUtils.tr("editing.feature"); featureSelection = /*#__PURE__*/React.createElement("div", { className: "editing-feature-selection" }, /*#__PURE__*/React.createElement("select", { className: "combo editing-feature-select", disabled: _this.props.editContext.changed === true || _this.props.editContext.id !== _this.props.currentEditContext, onChange: function onChange(ev) { return _this.setEditFeature(ev.target.value); }, value: (_this.props.editContext.feature || {}).id || "" }, _this.state.pickedFeatures.map(function (feature) { return /*#__PURE__*/React.createElement("option", { key: feature.id, value: feature.id }, editConfig.displayField ? feature.properties[editConfig.displayField] : featureText + " " + feature.id); }))); } var pickBar = null; if (_this.props.allowCloneGeometry && (_this.props.editContext.action === "Draw" || _this.state.drawPick) && !(_this.props.editContext.feature || {}).geometry) { var pickButtons = [{ key: 'DrawPick', icon: 'pick', label: LocaleUtils.tr("editing.pickdrawfeature") }]; pickBar = /*#__PURE__*/React.createElement(ButtonBar, { active: _this.state.drawPick ? "DrawPick" : null, buttons: pickButtons, onClick: _this.toggleDrawPick }); } var attributeForm = null; if (editConfig && _this.props.editContext.feature && (_this.props.editContext.action === "Pick" || _this.props.editContext.feature.geometry)) { var _this$props$layers$fi; var translations = (_this$props$layers$fi = _this.props.layers.find(function (layer) { return layer.wms_name === _this.props.editContext.mapPrefix; })) === null || _this$props$layers$fi === void 0 ? void 0 : _this$props$layers$fi.translations; attributeForm = /*#__PURE__*/React.createElement(AttributeForm, { editContext: _this.props.editContext, iface: _this.props.iface, onCommit: _this.updatePickedFeatures, translations: translations }); } return /*#__PURE__*/React.createElement("div", { className: "editing-body" }, /*#__PURE__*/React.createElement("div", { className: "editing-layer-selection" }, /*#__PURE__*/React.createElement("select", { className: "combo editing-layer-select", disabled: _this.props.editContext.changed === true || _this.props.editContext.id !== _this.props.currentEditContext, onChange: function onChange(ev) { return _this.changeSelectedLayer(ev.target.value); }, value: _this.state.selectedLayer || "" }, /*#__PURE__*/React.createElement("option", { disabled: true, value: "" }, LocaleUtils.tr("editing.selectlayer")), Object.entries(_this.props.editConfigs).map(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), mapName = _ref2[0], serviceConfigs = _ref2[1]; return Object.entries(serviceConfigs).map(function (_ref3) { var _ref5, _ref6, _match$layer$translat, _match$layer$translat2, _match$sublayer; var _ref4 = _slicedToArray(_ref3, 2), layerName = _ref4[0], edConfig = _ref4[1]; var match = LayerUtils.searchLayer(_this.props.layers, 'wms_name', mapName, 'name', layerName); if (!match) { return null; } var layerTitle = (_ref5 = (_ref6 = (_match$layer$translat = (_match$layer$translat2 = match.layer.translations) === null || _match$layer$translat2 === void 0 || (_match$layer$translat2 = _match$layer$translat2.layertree) === null || _match$layer$translat2 === void 0 ? void 0 : _match$layer$translat2[layerName]) !== null && _match$layer$translat !== void 0 ? _match$layer$translat : edConfig.layerTitle) !== null && _ref6 !== void 0 ? _ref6 : match === null || match === void 0 || (_match$sublayer = match.sublayer) === null || _match$sublayer === void 0 ? void 0 : _match$sublayer.title) !== null && _ref5 !== void 0 ? _ref5 : layerName; var value = mapName + "#" + layerName; return /*#__PURE__*/React.createElement("option", { key: value, value: value }, layerTitle); }); }))), /*#__PURE__*/React.createElement(ButtonBar, { active: _this.state.drawPick ? "Draw" : _this.props.editContext.action, buttons: actionButtons, disabled: !editConfig || _this.props.editContext.changed || _this.props.editContext.id !== _this.props.currentEditContext, onClick: _this.actionClicked }), featureSelection, pickBar, attributeForm); }); _defineProperty(_this, "actionClicked", function (action, data) { _this.setState({ drawPick: false, pickedFeatures: null }); if (action === "AttribTable") { _this.props.setCurrentTask("AttributeTable", null, null, { layer: _this.state.selectedLayer }); } else if (action === "Draw") { var featureSkel = { type: "Feature", properties: {} }; getFeatureTemplate(_this.props.editContext.editConfig, featureSkel, _this.props.iface, _this.props.editContext.mapPrefix, _this.props.map.projection, function (feature) { _this.props.setEditContext('Editing', _objectSpread(_objectSpread({}, data), {}, { feature: feature })); }); } else { _this.props.setEditContext('Editing', _objectSpread({}, data)); } }); _defineProperty(_this, "pickFilter", function (feature) { var geomType = _this.props.editContext.geomType; return feature.geometry && (feature.geometry.type === geomType || "Multi" + feature.geometry.type === geomType || feature.geometry.type.replace(/^Multi/, "") === geomType && feature.geometry.coordinates.length === 1); }); _defineProperty(_this, "geomPicked", function (layer, feature, mapName) { var _this$props$editConte2; var geomType = _this.props.editContext.geomType; var geometry = feature.geometry; if (geometry.type !== geomType) { if ("Multi" + feature.geometry.type === geomType) { // Convert picked geometry to multi-type geometry = { type: "Multi" + geometry.type, coordinates: [geometry.coordinates] }; } else if (geometry.type.replace(/^Multi/, "") === geomType && geometry.coordinates.length === 1) { // Convert picked geometry to single type geometry = { type: geometry.type.replace(/^Multi/, ""), coordinates: geometry.coordinates[0] }; } else { // Should not happen, mismatching geometries should already have been filtered from the list of choices return; } } var editFeature = { type: "Feature", geometry: geometry, id: uuidv4() }; var targetFields = (_this$props$editConte2 = _this.props.editContext.editConfig) === null || _this$props$editConte2 === void 0 ? void 0 : _this$props$editConte2.fields; var matchingAttributes = []; if (!isEmpty(targetFields)) { var _this$props$editConfi; var sourceProperties = feature.properties || {}; // Get source layer's field configuration and build name-to-id mapping var sourceFields = (_this$props$editConfi = _this.props.editConfigs[mapName]) === null || _this$props$editConfi === void 0 || (_this$props$editConfi = _this$props$editConfi[layer]) === null || _this$props$editConfi === void 0 ? void 0 : _this$props$editConfi.fields; var sourceNameToIdMap = (sourceFields || []).reduce(function (res, field) { return _objectSpread(_objectSpread({}, res), {}, _defineProperty(_defineProperty({}, field.name, field.id), field.id, field.id)); }, {}); var sourcePropertiesById = Object.entries(sourceProperties).reduce(function (res, _ref7) { var _ref8 = _slicedToArray(_ref7, 2), key = _ref8[0], value = _ref8[1]; return _objectSpread(_objectSpread({}, res), {}, _defineProperty({}, sourceNameToIdMap[key] || key, value)); }, {}); // Build list of matching attributes with metadata targetFields.forEach(function (field) { if (!field.expression) { var value = sourcePropertiesById[field.id]; if (value !== null && value !== undefined && value !== '') { var _field$constraints; // Parse number values if (field.type === 'number') { if (typeof value === 'string') { var numValue = parseNumber(value.replace(',', '.')); if (!isNaN(numValue)) { value = numValue; } } } else if (field.type === 'boolean') { value = !['0', 'false'].includes(String(value).toLowerCase()); } else if (field.type === 'date') { if (typeof value === 'string') { value = dateParser.fromString(value).toISOString(); } } else if (field.type === 'list') { // Not supported return; } matchingAttributes.push({ fieldId: field.id, fieldName: field.name, value: value, visible: ((_field$constraints = field.constraints) === null || _field$constraints === void 0 ? void 0 : _field$constraints.hidden) !== true, autoCalculated: !!field.defaultValue }); } } }); } if (matchingAttributes.length > 0) { // Default selection: only visible, non-auto-calculated fields var defaultSelection = matchingAttributes.filter(function (attr) { return attr.visible && !attr.autoCalculated; }).map(function (attr) { return attr.fieldId; }); _this.setState({ drawPick: false, pendingClone: { editFeature: editFeature, matchingAttributes: matchingAttributes, selectedAttributes: defaultSelection } }); } else { _this.props.setEditContext('Editing', { action: "Draw", feature: editFeature, changed: true }); _this.setState({ drawPick: false }); } }); _defineProperty(_this, "confirmCopyAttributes", function () { var _this$state$pendingCl = _this.state.pendingClone, editFeature = _this$state$pendingCl.editFeature, matchingAttributes = _this$state$pendingCl.matchingAttributes, selectedAttributes = _this$state$pendingCl.selectedAttributes; var copiedProperties = {}; matchingAttributes.forEach(function (attr) { if (selectedAttributes.includes(attr.fieldId)) { copiedProperties[attr.fieldId] = attr.value; } }); editFeature.properties = copiedProperties; _this.props.setEditContext('Editing', { action: "Draw", feature: editFeature, changed: true }); _this.setState({ pendingClone: null }); }); _defineProperty(_this, "cancelCopyAttributes", function () { var editFeature = _this.state.pendingClone.editFeature; _this.props.setEditContext('Editing', { action: "Draw", feature: editFeature, changed: true }); _this.setState({ pendingClone: null }); }); _defineProperty(_this, "toggleAttribute", function (fieldId) { _this.setState(function (state) { var selectedAttributes = state.pendingClone.selectedAttributes.includes(fieldId) ? state.pendingClone.selectedAttributes.filter(function (id) { return id !== fieldId; }) : [].concat(_toConsumableArray(state.pendingClone.selectedAttributes), [fieldId]); return { pendingClone: _objectSpread(_objectSpread({}, state.pendingClone), {}, { selectedAttributes: selectedAttributes }) }; }); }); _defineProperty(_this, "onCloneAttrQuickSelect", function (action) { if (action === 'All') { var allFieldIds = _this.state.pendingClone.matchingAttributes.map(function (attr) { return attr.fieldId; }); _this.setState(function (state) { return { pendingClone: _objectSpread(_objectSpread({}, state.pendingClone), {}, { selectedAttributes: allFieldIds }) }; }); } else if (action === 'None') { _this.setState(function (state) { return { pendingClone: _objectSpread(_objectSpread({}, state.pendingClone), {}, { selectedAttributes: [] }) }; }); } else if (action === 'Visible') { var visibleFieldIds = _this.state.pendingClone.matchingAttributes.filter(function (attr) { return attr.visible && !attr.autoCalculated; }).map(function (attr) { return attr.fieldId; }); _this.setState(function (state) { return { pendingClone: _objectSpread(_objectSpread({}, state.pendingClone), {}, { selectedAttributes: visibleFieldIds }) }; }); } }); _defineProperty(_this, "onCloneAction", function (action) { if (action === 'Copy') { _this.confirmCopyAttributes(); } else if (action === 'DontCopy') { _this.cancelCopyAttributes(); } }); _defineProperty(_this, "setLayerVisibility", function (selectedLayer, visibility) { if (selectedLayer !== null) { var _selectedLayer$split = selectedLayer.split("#"), _selectedLayer$split2 = _slicedToArray(_selectedLayer$split, 2), wmsName = _selectedLayer$split2[0], layerName = _selectedLayer$split2[1]; var match = LayerUtils.searchLayer(_this.props.layers, 'wms_name', wmsName, 'name', layerName); if (match) { var oldvisibility = match.sublayer.visibility; if (oldvisibility !== visibility && visibility !== null) { var recurseDirection = !oldvisibility ? "both" : "children"; _this.props.changeLayerProperty(match.layer.id, "visibility", visibility, match.path, recurseDirection); } return oldvisibility; } } return null; }); _defineProperty(_this, "changeSelectedLayer", function (selectedLayer) { var feature = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var _split = (selectedLayer !== null && selectedLayer !== void 0 ? selectedLayer : '#').split("#"), _split2 = _slicedToArray(_split, 2), mapName = _split2[0], layerName = _split2[1]; var editConfig = selectedLayer ? _this.props.editConfigs[mapName][layerName] : null; _this.props.setEditContext('Editing', { action: "Pick", feature: feature, changed: false, mapPrefix: mapName, editConfig: editConfig }); var prevLayerVisibility = null; if (_this.state.selectedLayer !== null) { _this.setLayerVisibility(_this.state.selectedLayer, _this.state.selectedLayerVisibility); prevLayerVisibility = _this.setLayerVisibility(selectedLayer, true); } _this.setState({ selectedLayer: selectedLayer, selectedLayerVisibility: prevLayerVisibility, drawPick: false }); }); _defineProperty(_this, "setEditFeature", function (featureId) { var feature = _this.state.pickedFeatures.find(function (f) { return f.id.toString() === featureId; }); _this.props.setEditContext('Editing', { feature: feature, changed: false }); }); _defineProperty(_this, "toggleDrawPick", function () { _this.setState(function (state) { var pickActive = !state.drawPick; _this.props.setEditContext('Editing', { action: pickActive ? null : "Draw" }); return { drawPick: pickActive }; }); }); _defineProperty(_this, "updatePickedFeatures", function (newfeature) { if (_this.state.pickedFeatures) { _this.setState(function (state) { return { pickedFeatures: state.pickedFeatures.map(function (feature) { return feature.id === newfeature.id ? newfeature : feature; }) }; }); } }); return _this; } _inherits(Editing, _React$Component); return _createClass(Editing, [{ key: "componentDidUpdate", value: function componentDidUpdate(prevProps, prevState) { var _this2 = this; // Clear selected layer on layers change if (this.props.layers !== prevProps.layers && this.state.selectedLayer) { var _this$state$selectedL = this.state.selectedLayer.split("#"), _this$state$selectedL2 = _slicedToArray(_this$state$selectedL, 2), wmsName = _this$state$selectedL2[0], layerName = _this$state$selectedL2[1]; if (!LayerUtils.searchLayer(this.props.layers, 'wms_name', wmsName, 'name', layerName)) { this.setState({ selectedLayer: null }); } } // If click point changed and in pick mode with a selected layer, trigger a pick var isCurrentContext = this.props.editContext.id === this.props.currentEditContext; if (this.props.enabled && isCurrentContext && this.props.editContext.action === 'Pick' && this.state.selectedLayer && !this.props.editContext.changed) { var newPoint = this.props.map.click || {}; var oldPoint = prevProps.map.click || {}; if (newPoint.coordinate && !isEqual(newPoint.coordinate, oldPoint.coordinate)) { var _this$props$filter$fi; var scale = Math.round(MapUtils.computeForZoom(this.props.map.scales, this.props.map.zoom)); var _this$state$selectedL3 = this.state.selectedLayer.split("#"), _this$state$selectedL4 = _slicedToArray(_this$state$selectedL3, 2), _wmsName = _this$state$selectedL4[0], _layerName = _this$state$selectedL4[1]; var editConfig = this.props.editConfigs[_wmsName][_layerName]; this.props.iface.getFeature(editConfig, newPoint.coordinate, this.props.map.projection, scale, 96, function (featureCollection) { var features = featureCollection ? featureCollection.features : null; _this2.setState({ pickedFeatures: features }); var feature = features ? features[0] : null; _this2.props.setEditContext('Editing', { feature: feature, changed: false }); }, (_this$props$filter$fi = this.props.filter.filterParams) === null || _this$props$filter$fi === void 0 ? void 0 : _this$props$filter$fi[this.state.selectedLayer], this.props.filter.filterGeom); } } if (prevProps.editContext.changed !== this.props.editContext.changed) { this.props.setCurrentTaskBlocked(this.props.editContext.changed === true, LocaleUtils.tr("editing.unsavedchanged")); } if (!this.props.editContext.feature && prevState.pickedFeatures) { this.setState({ pickedFeatures: null }); } } }, { key: "render", value: function render() { var _this3 = this; var minMaxTooltip = this.state.minimized ? LocaleUtils.tr("editing.maximize") : LocaleUtils.tr("editing.minimize"); var extraTitlebarContent = /*#__PURE__*/React.createElement(Icon, { className: "editing-minimize-maximize", icon: this.state.minimized ? 'chevron-down' : 'chevron-up', onClick: function onClick() { return _this3.setState(function (state) { return { minimized: !state.minimized }; }); }, title: minMaxTooltip }); var attribFormVisible = !!(this.props.editContext.feature && (this.props.editContext.action === "Pick" || this.props.editContext.feature.geometry)); return [/*#__PURE__*/React.createElement(SideBar, { extraTitlebarContent: extraTitlebarContent, heightResizeable: !this.state.minimized && attribFormVisible, icon: "editing", id: "Editing", key: "EditingSidebar", onHide: this.onHide, onShow: this.onShow, side: this.props.side, title: LocaleUtils.tr("appmenu.items.Editing"), width: this.props.width }, function () { return { body: _this3.state.minimized ? null : _this3.renderBody() }; }), this.state.drawPick ? /*#__PURE__*/React.createElement(PickFeature, { featureFilter: this.pickFilter, featurePicked: this.geomPicked, key: "FeaturePicker" }) : null]; } }]); }(React.Component); _defineProperty(Editing, "propTypes", { addLayerFeatures: PropTypes.func, /** Whether to enable the "Clone existing geometry" functionality. */ allowCloneGeometry: PropTypes.bool, changeLayerProperty: PropTypes.func, clearEditContext: PropTypes.func, currentEditContext: PropTypes.string, editConfigs: PropTypes.object, editContext: PropTypes.object, enabled: PropTypes.bool, filter: PropTypes.object, iface: PropTypes.object, layers: PropTypes.array, map: PropTypes.object, removeLayer: PropTypes.func, setCurrentTask: PropTypes.func, setCurrentTaskBlocked: PropTypes.func, setEditContext: PropTypes.func, setSnappingConfig: PropTypes.func, /** Whether to show a button to open the AttributeTable (if the plugin is available). */ showAttributeTableButton: PropTypes.bool, /** The side of the application on which to display the sidebar. */ side: PropTypes.string, /** 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]), taskData: PropTypes.object, theme: PropTypes.object, /** The default width of the editing sidebar, as a CSS width string. */ width: PropTypes.string }); _defineProperty(Editing, "defaultProps", { width: "30em", side: 'right', snapping: true, snappingActive: true, allowCloneGeometry: true, showAttributeTableButton: true }); export default (function () { var iface = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : EditingInterface; return connect(function (state) { return { enabled: state.task.id === 'Editing', theme: state.theme.current, layers: state.layers.flat, filter: state.layers.filter, editConfigs: state.layers.editConfigs, map: state.map, iface: iface, editContext: state.editing.contexts.Editing || {}, currentEditContext: state.editing.currentContext, taskData: state.task.id === "Editing" ? state.task.data : null }; }, { addLayerFeatures: addLayerFeatures, removeLayer: removeLayer, clearEditContext: clearEditContext, setEditContext: setEditContext, setSnappingConfig: setSnappingConfig, setCurrentTask: setCurrentTask, setCurrentTaskBlocked: setCurrentTaskBlocked, changeLayerProperty: changeLayerProperty })(Editing); });