qwc2
Version:
QGIS Web Client
78 lines (77 loc) • 5.57 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 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 _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 { SET_EDIT_CONTEXT, CLEAR_EDIT_CONTEXT } from '../actions/editing';
var defaultState = {
contexts: {},
currentContext: null
};
var _nonZeroZCoordinate = function nonZeroZCoordinate(coordinates) {
return coordinates.find(function (entry) {
return Array.isArray(entry[0]) ? _nonZeroZCoordinate(entry) : entry.length >= 3 && entry[2] !== 0;
});
};
var checkNonZeroZ = function checkNonZeroZ(oldState, newState, fallback) {
var _oldState$feature;
// Only recompute if feature id in state changes
if (!newState.feature) {
return false;
} else if (newState.feature.id !== (oldState === null || oldState === void 0 || (_oldState$feature = oldState.feature) === null || _oldState$feature === void 0 ? void 0 : _oldState$feature.id)) {
var _newState$feature$geo;
return _nonZeroZCoordinate([((_newState$feature$geo = newState.feature.geometry) === null || _newState$feature$geo === void 0 ? void 0 : _newState$feature$geo.coordinates) || []]) !== undefined;
}
return (oldState === null || oldState === void 0 ? void 0 : oldState.geomNonZeroZ) || false;
};
var checkGeomReadOnly = function checkGeomReadOnly(editConfig) {
var _editConfig$geomType, _editConfig$permissio;
var simpleGeomType = ((_editConfig$geomType = editConfig === null || editConfig === void 0 ? void 0 : editConfig.geomType) !== null && _editConfig$geomType !== void 0 ? _editConfig$geomType : "").replace(/^Multi/, '').replace(/Z$/, '');
return (editConfig === null || editConfig === void 0 ? void 0 : editConfig.geomType) && !['Point', 'LineString', 'Polygon'].includes(simpleGeomType) || (editConfig === null || editConfig === void 0 || (_editConfig$permissio = editConfig.permissions) === null || _editConfig$permissio === void 0 ? void 0 : _editConfig$permissio.updatable) === false;
};
export default function editing() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
var action = arguments.length > 1 ? arguments[1] : undefined;
switch (action.type) {
case SET_EDIT_CONTEXT:
{
var _action$editConfig, _state$contexts$actio, _editConfig$permissio2;
var editConfig = (_action$editConfig = action.editConfig) !== null && _action$editConfig !== void 0 ? _action$editConfig : (_state$contexts$actio = state.contexts[action.contextId]) === null || _state$contexts$actio === void 0 ? void 0 : _state$contexts$actio.editConfig;
return {
contexts: _objectSpread(_objectSpread({}, state.contexts), {}, _defineProperty({}, action.contextId, _objectSpread(_objectSpread(_objectSpread({
action: null,
feature: null,
changed: false,
mapPrefix: null,
editConfig: null
}, state.contexts[action.contextId]), action.editContext), {}, {
geomNonZeroZ: checkNonZeroZ(state.contexts[action.contextId], action.editContext),
geomReadOnly: checkGeomReadOnly(editConfig),
id: action.contextId,
geomType: editConfig === null || editConfig === void 0 ? void 0 : editConfig.geomType,
permissions: (_editConfig$permissio2 = editConfig === null || editConfig === void 0 ? void 0 : editConfig.permissions) !== null && _editConfig$permissio2 !== void 0 ? _editConfig$permissio2 : {}
}))),
currentContext: action.contextId
};
}
case CLEAR_EDIT_CONTEXT:
{
var newState = {
contexts: _objectSpread({}, state.contexts),
currentContext: state.currentContext === action.contextId ? action.newActiveContextId : state.currentContext
};
delete newState.contexts[action.contextId];
return newState;
}
default:
return state;
}
}