UNPKG

qwc2

Version:
18 lines 22.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 _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 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 isEmpty from"lodash.isempty";import PropTypes from"prop-types";import{LayerRole,addLayerFeatures,addMarker,removeMarker,removeLayer}from"../actions/layers";import{setCurrentTask}from"../actions/task";import IdentifyViewer from"../components/IdentifyViewer";import MapSelection from"../components/MapSelection";import ResizeableWindow from"../components/ResizeableWindow";import TaskBar from"../components/TaskBar";import NumberInput from"../components/widgets/NumberInput";import ConfigUtils from"../utils/ConfigUtils";import CoordinatesUtils from"../utils/CoordinatesUtils";import IdentifyUtils from"../utils/IdentifyUtils";import LocaleUtils from"../utils/LocaleUtils";import MeasureUtils from"../utils/MeasureUtils";import VectorLayerUtils from"../utils/VectorLayerUtils";import"./style/Identify.css";/** * Displays queried feature attributes. * * Uses WMS GetFeatureInfo to query features and displays the result in * table, as a HTML fragment or as plain text based on the supported GetFeatureInfo * format. * * Extendable in combination with the `qwc-feature-info-service`, which provides support * for customized queries and templates for the result presentation. */var Identify=/*#__PURE__*/function(_React$Component){function Identify(){var _this;_classCallCheck(this,Identify);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,Identify,[].concat(args));_defineProperty(_this,"state",{mode:"Point",identifyResults:null,pendingRequests:0,radius:0,radiusUnits:_this.props.initialRadiusUnits,exitTaskOnResultsClose:null,filterGeom:null,filterGeomModifiers:{}});_defineProperty(_this,"identifyPoint",function(clickPoint){if(clickPoint){_this.setState(function(state){// Remove any search selection layer to avoid confusion _this.props.removeLayer("searchselection");var pendingRequests=0;var identifyResults=_this.props.click.modifiers.ctrl!==true?{}:state.identifyResults;var queryableLayers=[];queryableLayers=IdentifyUtils.getQueryLayers(_this.props.layers,_this.props.map);queryableLayers.forEach(function(l){var request=IdentifyUtils.buildRequest(l,l.queryLayers.join(","),clickPoint,_this.props.map,_this.props.params);++pendingRequests;IdentifyUtils.sendRequest(request,function(response){_this.setState(function(state2){return{pendingRequests:state2.pendingRequests-1}});if(response){_this.parseResult(response,l,request.params.info_format,clickPoint)}})});if(!isEmpty(_this.props.click.features)){_this.props.click.features.forEach(function(feature){var layer=_this.props.layers.find(function(l){return l.id===feature.layerId});if((layer===null||layer===void 0?void 0:layer.role)===LayerRole.USERLAYER){var _layer$features$find,_layer$features,_layer$features$find2,_layer$projection;var queryFeature=_objectSpread({},(_layer$features$find=(_layer$features=layer.features)===null||_layer$features===void 0||(_layer$features$find2=_layer$features.find)===null||_layer$features$find2===void 0?void 0:_layer$features$find2.call(_layer$features,function(f){return f.id===feature.id}))!==null&&_layer$features$find!==void 0?_layer$features$find:feature);if(!(queryFeature!==null&&queryFeature!==void 0&&queryFeature.properties)){return}if(!identifyResults[layer.name]){identifyResults[layer.name]=[]}queryFeature.crs=(_layer$projection=layer.projection)!==null&&_layer$projection!==void 0?_layer$projection:_this.props.map.projection;queryFeature.displayname=queryFeature.properties.name||queryFeature.properties.Name||queryFeature.properties.NAME||queryFeature.properties.label||queryFeature.properties.id||queryFeature.id;queryFeature.layertitle=layer.title||layer.name||layer.id;queryFeature.properties=Object.entries(queryFeature.properties).reduce(function(res,_ref){var _ref2=_slicedToArray(_ref,2),key=_ref2[0],val=_ref2[1];return _objectSpread(_objectSpread({},res),{},_defineProperty({},key,_typeof(val)==="object"?JSON.stringify(val):val))},{});identifyResults[layer.name].push(queryFeature)}})}_this.props.addMarker("identify",clickPoint,"",_this.props.map.projection);return{identifyResults:identifyResults,pendingRequests:pendingRequests}})}});_defineProperty(_this,"queryPoint",function(prevProps){if(_this.props.click.button!==0||_this.props.click===prevProps.click||(_this.props.click.features||[]).find(function(feature){return feature.id==="startupposmarker"})){return null}var searchMarker=(_this.props.click.features||[]).find(function(feature){return feature.id==="searchmarker"});if(searchMarker&&searchMarker.geometry.type==="Point"){return searchMarker.geometry.coordinates}return _this.props.click.coordinate});_defineProperty(_this,"identifyRegion",function(){var queryableLayers=IdentifyUtils.getQueryLayers(_this.props.layers,_this.props.map);var poly=_this.state.filterGeom.coordinates[0];if(poly.length<3||isEmpty(queryableLayers)){return}var identifyResults=_this.state.filterGeomModifiers.ctrl!==true?{}:_this.state.identifyResults;var center=[0,0];poly.forEach(function(point){center[0]+=point[0];center[1]+=point[1]});center[0]/=poly.length;center[1]/=poly.length;var filter=VectorLayerUtils.geoJSONGeomToWkt(_this.state.filterGeom);var pendingRequests=0;var params=_objectSpread({},_this.props.params);if(_this.props.params.region_feature_count){params.feature_count=_this.props.params.region_feature_count;delete params.region_feature_count}queryableLayers.forEach(function(layer){var request=IdentifyUtils.buildFilterRequest(layer,layer.queryLayers.join(","),filter,_this.props.map,params);++pendingRequests;IdentifyUtils.sendRequest(request,function(response){_this.setState(function(state){return{pendingRequests:state.pendingRequests-1}});if(response){_this.parseResult(response,layer,request.params.info_format,center)}});_this.setState({identifyResults:identifyResults,pendingRequests:pendingRequests})})});_defineProperty(_this,"identifyRadius",function(){var clickPoint=_this.state.filterGeom.center;var queryableLayers=IdentifyUtils.getQueryLayers(_this.props.layers,_this.props.map);if(isEmpty(queryableLayers)){return}var identifyResults=_this.state.filterGeomModifiers.ctrl!==true?{}:_this.state.identifyResults;var filter=VectorLayerUtils.geoJSONGeomToWkt(_this.state.filterGeom);var pendingRequests=0;var params=_objectSpread({},_this.props.params);if(_this.props.params.radius_feature_count){params.feature_count=_this.props.params.radius_feature_count;delete params.radius_feature_count}queryableLayers.forEach(function(layer){var request=IdentifyUtils.buildFilterRequest(layer,layer.queryLayers.join(","),filter,_this.props.map,params);++pendingRequests;IdentifyUtils.sendRequest(request,function(response){_this.setState(function(state){return{pendingRequests:state.pendingRequests-1}});if(response){_this.parseResult(response,layer,request.params.info_format,clickPoint)}});_this.setState({identifyResults:identifyResults,pendingRequests:pendingRequests})});_this.props.addMarker("identify",clickPoint,"",_this.props.map.projection)});_defineProperty(_this,"changeBufferUnit",function(ev){_this.setState({radiusUnits:ev.target.value})});_defineProperty(_this,"parseResult",function(response,layer,format,clickPoint){var newResults=IdentifyUtils.parseResponse(response,layer,format,clickPoint,_this.props.map.projection,_this.props.featureInfoReturnsLayerName);// Merge with previous _this.setState(function(state){var identifyResults=_objectSpread({},state.identifyResults);Object.entries(newResults).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),layername=_ref4[0],features=_ref4[1];var key=layer.url+"#"+layername;identifyResults[key]=features.reduce(function(result,feature){if(result.find(function(f){return f.id===feature.id})===undefined){result.push(feature)}return result},identifyResults[key]||[])});return{identifyResults:identifyResults}})});_defineProperty(_this,"onShow",function(mode,data){_this.setState({mode:mode||"Point",exitTaskOnResultsClose:data===null||data===void 0?void 0:data.exitTaskOnResultsClose});if(mode==="Point"&&data!==null&&data!==void 0&&data.pos){_this.identifyPoint(data.pos)}});_defineProperty(_this,"onToolClose",function(){_this.setState({mode:"Point",exitTaskOnResultsClose:null,filterGeom:null});if(_this.props.clearResultsOnClose){_this.clearResults()}});_defineProperty(_this,"onWindowClose",function(){_this.clearResults();if(_this.state.exitTaskOnResultsClose||_this.props.exitTaskOnResultsClose){_this.props.setCurrentTask(null)}});_defineProperty(_this,"clearResults",function(){_this.props.removeMarker("identify");_this.props.removeLayer("identifyslection");_this.props.removeLayer("identifyradiusbuffer");_this.setState({identifyResults:null,pendingRequests:0})});_defineProperty(_this,"updateRadius",function(radius,units){_this.setState(function(state){return{radius:radius,radiusUnits:units,filterGeom:_objectSpread(_objectSpread({},state.filterGeom),{},{radius:MeasureUtils.convertLength(radius,units,"m")})}})});_defineProperty(_this,"renderBody",function(){if(_this.state.mode==="Point"){return LocaleUtils.tr("infotool.clickhelpPoint")}else if(_this.state.mode==="Region"){return LocaleUtils.tr("infotool.clickhelpPolygon")}else if(_this.state.mode==="Radius"){var text=LocaleUtils.tr("infotool.clickhelpRadius");return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("div",null,text),/*#__PURE__*/React.createElement("div",{className:"identify-radius-controls controlgroup"},/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("infotool.radius"),":\xA0"),/*#__PURE__*/React.createElement(NumberInput,{disabled:!_this.state.filterGeom,max:1000000,min:1,mobile:true,onChange:function onChange(rad){return _this.updateRadius(rad,_this.state.radiusUnits)},value:_this.state.radius}),/*#__PURE__*/React.createElement("select",{onChange:function onChange(ev){return _this.updateRadius(_this.state.radius,ev.target.value)},value:_this.state.radiusUnits},/*#__PURE__*/React.createElement("option",{value:"m"},"m"),/*#__PURE__*/React.createElement("option",{value:"ft"},"ft"),/*#__PURE__*/React.createElement("option",{value:"km"},"km"),/*#__PURE__*/React.createElement("option",{value:"mi"},"mi"))))}return null});return _this}_inherits(Identify,_React$Component);return _createClass(Identify,[{key:"componentDidUpdate",value:function componentDidUpdate(prevProps,prevState){if(this.props.enabled&&this.props.theme&&!prevProps.theme){var startupParams=this.props.startupParams;var haveIc=["1","true"].includes((startupParams.ic||"").toLowerCase());var c=(startupParams.c||"").split(/[;,]/g).map(function(x){return parseFloat(x)||0});if(haveIc&&c.length===2){var mapCrs=this.props.theme.mapCrs;this.identifyPoint(CoordinatesUtils.reproject(c,startupParams.crs||mapCrs,mapCrs))}}else if(this.props.theme!==prevProps.theme){this.clearResults()}else if(!this.props.enabled&&prevProps.enabled){if(this.props.clearResultsOnClose){this.clearResults()}}if(this.props.enabled){if(this.state.mode==="Point"){var clickPoint=this.queryPoint(prevProps);this.identifyPoint(clickPoint)}else if(this.state.mode==="Region"){if(this.state.filterGeom&&this.state.filterGeom!==prevState.filterGeom){this.identifyRegion()}}else if(this.state.mode==="Radius"){if(this.state.filterGeom&&this.state.filterGeom!==prevState.filterGeom){this.setState(function(state){return{radius:MeasureUtils.convertLength(state.filterGeom.radius,"m",state.radiusUnits)}});this.identifyRadius()}}}}},{key:"render",value:function render(){var _this2=this;var resultWindow=null;if(this.state.pendingRequests>0||this.state.identifyResults!==null){var body=null;if(isEmpty(this.state.identifyResults)){if(this.state.pendingRequests>0){body=/*#__PURE__*/React.createElement("div",{className:"identify-body",role:"body"},/*#__PURE__*/React.createElement("span",{className:"identify-body-message"},LocaleUtils.tr("identify.querying")))}else{body=/*#__PURE__*/React.createElement("div",{className:"identify-body",role:"body"},/*#__PURE__*/React.createElement("span",{className:"identify-body-message"},LocaleUtils.tr("identify.noresults")))}}else{body=/*#__PURE__*/React.createElement(IdentifyViewer,{attributeCalculator:this.props.attributeCalculator,attributeTransform:this.props.attributeTransform,customExporters:this.props.customExporters,displayResultTree:this.props.displayResultTree,enableAggregatedReports:this.props.enableAggregatedReports,enableExport:this.props.enableExport,exportGeometry:this.props.exportGeometry,highlightAllResults:this.props.highlightAllResults,identifyResults:this.state.identifyResults,iframeDialogsInitiallyDocked:this.props.iframeDialogsInitiallyDocked,longAttributesDisplay:this.props.longAttributesDisplay,replaceImageUrls:this.props.replaceImageUrls,role:"body",showLayerSelector:this.props.showLayerSelector})}resultWindow=/*#__PURE__*/React.createElement(ResizeableWindow,{busyIcon:this.state.pendingRequests>0,dockable:this.props.geometry.side,icon:"info-sign",initialHeight:this.props.geometry.initialHeight,initialWidth:this.props.geometry.initialWidth,initialX:this.props.geometry.initialX,initialY:this.props.geometry.initialY,initiallyDocked:this.props.geometry.initiallyDocked,key:"IdentifyWindow",onClose:this.onWindowClose,title:LocaleUtils.tr("identify.title")},body)}return[resultWindow,/*#__PURE__*/React.createElement(TaskBar,{key:"IdentifyTaskBar",onHide:this.onToolClose,onShow:this.onShow,task:"Identify"},function(){return{body:_this2.renderBody()}}),this.state.mode==="Region"||this.state.mode==="Radius"?/*#__PURE__*/React.createElement(MapSelection,{active:true,geomType:this.state.mode==="Radius"?"Circle":"Polygon",geometry:this.state.filterGeom,geometryChanged:function geometryChanged(geom,mod){return _this2.setState({filterGeom:geom,filterGeomModifiers:mod})},key:"MapSelection",measure:this.state.mode==="Radius"}):null]}}])}(React.Component);_defineProperty(Identify,"propTypes",{addLayerFeatures:PropTypes.func,addMarker:PropTypes.func,/** Optional function for computing derived attributes. See js/IdentifyExtensions.js for details. This prop can be specified in the appConfig.js cfg section. */attributeCalculator:PropTypes.func,/** Optional function for transforming attribute values. See js/IdentifyExtensions.js for details. This prop can be specified in the appConfig.js cfg section. */attributeTransform:PropTypes.func,/** Whether to clear the identify results when exiting the identify tool. */clearResultsOnClose:PropTypes.bool,click:PropTypes.object,currentIdentifyTool:PropTypes.string,currentTask:PropTypes.string,/** Optional list of custom exporters to offer along with the built-in exporters. See js/IdentifyExtensions.js for details. This prop can be specified in the appConfig.js cfg section. */customExporters:PropTypes.array,/** Whether to display a tree overview of results (as opposed to a flat list of results). */displayResultTree:PropTypes.bool,/** Whether to enable the aggregated report download button. */enableAggregatedReports:PropTypes.bool,/** Whether to enable the export functionality. Either `true|false` or a list of single allowed formats (builtin formats: `json`, `geojson`, `csv`, `csvzip`) */enableExport:PropTypes.oneOfType([PropTypes.bool,PropTypes.array]),enabled:PropTypes.bool,/** Whether to clear the task when the results window is closed. */exitTaskOnResultsClose:PropTypes.bool,/** Whether to include the geometry in exported features. Default: `true`. */exportGeometry:PropTypes.bool,/** Whether to assume that XML GetFeatureInfo responses specify the technical layer name in the `name` attribute, rather than the layer title. */featureInfoReturnsLayerName:PropTypes.bool,/** Default window geometry with size, position and docking status. Positive position values (including '0') are related to top (InitialY) and left (InitialX), negative values (including '-0') to bottom (InitialY) and right (InitialX). */geometry:PropTypes.shape({initialWidth:PropTypes.number,initialHeight:PropTypes.number,initialX:PropTypes.number,initialY:PropTypes.number,initiallyDocked:PropTypes.bool,side:PropTypes.string}),/** Whether to highlight all results if no result is hovered */highlightAllResults:PropTypes.bool,iframeDialogsInitiallyDocked:PropTypes.bool,/** The initial radius units of the identify dialog in radius mode. One of 'm', 'ft', 'km', 'mi'. */initialRadiusUnits:PropTypes.string,layers:PropTypes.array,longAttributesDisplay:PropTypes.string,map:PropTypes.object,/** Extra params to append to the GetFeatureInfo request (i.e. `FI_POINT_TOLERANCE`, `FI_LINE_TOLERANCE`, `feature_count`, ...). Additionally, `region_feature_count` and `radius_feature_count` are supported. */params:PropTypes.object,removeLayer:PropTypes.func,removeMarker:PropTypes.func,/** Whether to replace an attribute value containing an URL to an image with an inline image. */replaceImageUrls:PropTypes.bool,selection:PropTypes.object,setCurrentTask:PropTypes.func,/** Whether to show a layer selector to filter the identify results by layer. */showLayerSelector:PropTypes.bool,startupParams:PropTypes.object,theme:PropTypes.object});_defineProperty(Identify,"defaultProps",{enableAggregatedReports:true,enableExport:true,exportGeometry:true,clearResultsOnClose:true,customExporters:[],longAttributesDisplay:"ellipsis",displayResultTree:true,replaceImageUrls:true,featureInfoReturnsLayerName:true,geometry:{initialWidth:240,initialHeight:320,initialX:0,initialY:0,initiallyDocked:false,side:"left"},initialRadiusUnits:"m",highlightAllResults:true,showLayerSelector:true});export default connect(function(state){var enabled=state.task.id==="Identify"||state.task.identifyEnabled&&ConfigUtils.getConfigProp("identifyTool",state.theme.current,"Identify")==="Identify";return{click:state.map.click||{modifiers:{}},enabled:enabled,layers:state.layers.flat,map:state.map,selection:state.selection,theme:state.theme.current,startupParams:state.localConfig.startupParams}},{addLayerFeatures:addLayerFeatures,addMarker:addMarker,removeMarker:removeMarker,removeLayer:removeLayer,setCurrentTask:setCurrentTask})(Identify);