qwc2
Version:
QGIS Web Client
206 lines (205 loc) • 11.7 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 _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 _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
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 _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 isEmpty from 'lodash.isempty';
import ol from 'openlayers';
import PropTypes from 'prop-types';
import { changeRedliningPickState } from '../../actions/redliningPick';
import FeatureStyles from "../../utils/FeatureStyles";
var RedliningPickSupport = /*#__PURE__*/function (_React$Component) {
function RedliningPickSupport(props) {
var _this;
_classCallCheck(this, RedliningPickSupport);
_this = _callSuper(this, RedliningPickSupport, [props]);
_defineProperty(_this, "addPickInteraction", function (layerId) {
_this.reset(layerId);
var redliningLayer = _this.searchRedliningLayer(layerId);
if (!redliningLayer) {
return;
}
var selectInteraction = new ol.interaction.Select({
layers: [redliningLayer],
toggleCondition: function toggleCondition() {
return true;
}
});
selectInteraction.on('select', function (evt) {
var selectedFeatures = _this.props.redliningPick.selectedFeatures.slice(0);
// Add newly selected features
var _iterator = _createForOfIteratorHelper(evt.selected || []),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var feature = _step.value;
// Skip text features for now
if (feature.shape === "Text") {
continue;
}
selectedFeatures.push(feature.getId());
_this.selectFeature(feature);
}
// Deselect currently selected features
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
var _iterator2 = _createForOfIteratorHelper(evt.deselected || []),
_step2;
try {
var _loop = function _loop() {
var feature = _step2.value;
selectedFeatures = selectedFeatures.filter(function (id) {
return id !== feature.getId();
});
_this.deselectFeature(feature);
};
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
_loop();
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
_this.props.changeRedliningPickState({
selectedFeatures: selectedFeatures
});
}, _this);
_this.props.map.addInteraction(selectInteraction);
_this.interactions = [selectInteraction];
});
_defineProperty(_this, "reset", function (layerId) {
while (_this.interactions.length > 0) {
_this.props.map.removeInteraction(_this.interactions.shift());
}
_this.deselectAllFeatures(layerId);
_this.props.changeRedliningPickState({
selectedFeatures: []
});
});
_defineProperty(_this, "selectFeature", function (feature) {
var style = feature.getStyle();
if (Array.isArray(style)) {
style = [].concat(_toConsumableArray(style), [_this.selectedStyle]);
} else {
style = [style, _this.selectedStyle];
}
feature.setStyle(style);
});
_defineProperty(_this, "deselectFeature", function (feature) {
var style = feature.getStyle();
if (Array.isArray(style)) {
style = feature.getStyle().filter(function (entry) {
return entry !== _this.selectedStyle;
});
feature.setStyle(style.length > 1 ? style : style[0]);
}
});
_defineProperty(_this, "deselectAllFeatures", function (layerId) {
var redliningLayer = _this.searchRedliningLayer(layerId);
if (redliningLayer) {
var _iterator3 = _createForOfIteratorHelper(_this.props.redliningPick.selectedFeatures || []),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var id = _step3.value;
var feature = redliningLayer.getSource().getFeatureById(id);
if (feature) {
_this.deselectFeature(feature);
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
}
});
_defineProperty(_this, "searchRedliningLayer", function (layerId) {
var redliningLayer = null;
_this.props.map.getLayers().forEach(function (olLayer) {
if (olLayer.get('id') === layerId) {
redliningLayer = olLayer;
}
});
return redliningLayer;
});
_this.interactions = [];
_this.selectedFeatures = [];
var geometryFunction = function geometryFunction(feature) {
if (feature.getGeometry().getType() === "Point") {
return new ol.geom.MultiPoint([feature.getGeometry().getCoordinates()]);
} else if (feature.getGeometry().getType() === "LineString") {
return new ol.geom.MultiPoint(feature.getGeometry().getCoordinates());
}
return new ol.geom.MultiPoint(feature.getGeometry().getCoordinates()[0]);
};
_this.selectedStyle = FeatureStyles.interactionVertex({
geometryFunction: geometryFunction
});
return _this;
}
_inherits(RedliningPickSupport, _React$Component);
return _createClass(RedliningPickSupport, [{
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (this.props.redliningPick === prevProps.redliningPick) {
// pass
} else if (!this.props.redliningPick.active && prevProps.redliningPick.active) {
this.reset(this.props.redliningPick.layer);
} else if (this.props.redliningPick.active && !prevProps.redliningPick.active) {
this.addPickInteraction(this.props.redliningPick.layer);
} else if (this.props.redliningPick.active === prevProps.redliningPick.active && isEmpty(this.props.redliningPick.selectedFeatures) && !isEmpty(prevProps.redliningPick.selectedFeatures)) {
// Re-initialize
this.reset(prevProps.redliningPick.layer);
this.addPickInteraction(this.props.redliningPick.layer);
}
}
}, {
key: "render",
value: function render() {
return null;
}
}]);
}(React.Component);
_defineProperty(RedliningPickSupport, "propTypes", {
changeRedliningPickState: PropTypes.func,
changeState: PropTypes.func,
map: PropTypes.object,
redliningPick: PropTypes.object
});
export default connect(function (state) {
return {
redliningPick: state.redliningPick
};
}, {
changeRedliningPickState: changeRedliningPickState
})(RedliningPickSupport);