qwc2
Version:
QGIS Web Client
26 lines • 28.1 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 _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 _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 _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 _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 _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 _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{TextEncoder,TextDecoder}from"@kayahr/text-encoding";import axios from"axios";import dayjs from"dayjs";import FileSaver from"file-saver";import isEmpty from"lodash.isempty";import PropTypes from"prop-types";import{LayerRole}from"../actions/layers";import{setSnappingConfig}from"../actions/map";import Icon from"../components/Icon";import PrintSelection from"../components/PrintSelection";import SideBar from"../components/SideBar";import NumberInput from"../components/widgets/NumberInput";import Spinner from"../components/widgets/Spinner";import ConfigUtils from"../utils/ConfigUtils";import CoordinatesUtils from"../utils/CoordinatesUtils";import{explodeDxf,implodeDxf,mergeDxf}from"../utils/DxfUtils";import LayerUtils from"../utils/LayerUtils";import LocaleUtils from"../utils/LocaleUtils";import MapUtils from"../utils/MapUtils";import VectorLayerUtils from"../utils/VectorLayerUtils";import"./style/MapExport.css";import"@kayahr/text-encoding/encodings/windows-1252";/**
* Allows exporting a selected portion of the map to a variety of formats.
*/var MapExport=/*#__PURE__*/function(_React$Component){function MapExport(props){var _this;_classCallCheck(this,MapExport);_this=_callSuper(this,MapExport,[props]);_defineProperty(_this,"state",{extents:[],exporting:false,availableFormats:[],selectedFormat:null,selectedFormatConfiguration:"",exportProjection:null,scale:null,pageSize:null,dpi:96});_defineProperty(_this,"changeFormat",function(ev){var _this$props$formatCon,_formatConfigurations,_formatConfigurations2;var selectedFormat=ev.target.value;var formatConfigurations=((_this$props$formatCon=_this.props.formatConfiguration)===null||_this$props$formatCon===void 0?void 0:_this$props$formatCon[selectedFormat.split(";")[0]])||[];_this.setState({selectedFormat:selectedFormat,selectedFormatConfiguration:(_formatConfigurations=formatConfigurations[0])===null||_formatConfigurations===void 0?void 0:_formatConfigurations.name,exportProjection:_this.getExportProjection((_formatConfigurations2=formatConfigurations[0])===null||_formatConfigurations2===void 0?void 0:_formatConfigurations2.projections)})});_defineProperty(_this,"setSelectedFormatConfiguration",function(ev){var _this$props$formatCon2;var selectedFormatConfiguration=ev.target.value;var formatConfigurations=((_this$props$formatCon2=_this.props.formatConfiguration)===null||_this$props$formatCon2===void 0?void 0:_this$props$formatCon2[_this.state.selectedFormat.split(";")[0]])||[];var formatConfiguration=formatConfigurations.find(function(entry){return entry.name===selectedFormatConfiguration});_this.setState({selectedFormatConfiguration:selectedFormatConfiguration,exportProjection:_this.getExportProjection(formatConfiguration.projections)})});_defineProperty(_this,"getExportProjection",function(projections){if(isEmpty(projections)){return _this.props.map.projection}else{return projections.indexOf(_this.props.map.projection)!==-1?_this.props.map.projection:projections[0]}});_defineProperty(_this,"changeScale",function(value){_this.setState({scale:Math.max(1,parseInt(value,10)||0)})});_defineProperty(_this,"changeResolution",function(ev){_this.setState({dpi:parseInt(ev.target.value,10)||0})});_defineProperty(_this,"renderBody",function(){var _this$props$formatCon3;if(!_this.props.theme||!_this.state.selectedFormat){return null}var formatMap={"image/jpeg":"JPEG","image/png":"PNG","image/png; mode=16bit":"PNG 16bit","image/png; mode=8bit":"PNG 8bit","image/png; mode=1bit":"PNG 1bit","image/geotiff":"GeoTIFF","image/tiff":"GeoTIFF","application/dxf":"DXF","application/pdf":"GeoPDF"};var formatConfigurations=((_this$props$formatCon3=_this.props.formatConfiguration)===null||_this$props$formatCon3===void 0?void 0:_this$props$formatCon3[_this.state.selectedFormat.split(";")[0]])||[];var formatConfiguration=formatConfigurations.find(function(entry){return entry.name===_this.state.selectedFormatConfiguration});var scaleChooser=null;if(!isEmpty(_this.props.allowedScales)){scaleChooser=/*#__PURE__*/React.createElement("select",{onChange:_this.changeScale,value:_this.state.scale||""},/*#__PURE__*/React.createElement("option",{hidden:true,value:_this.state.scale||""},_this.state.scale||""),_this.props.allowedScales.map(function(scale){return/*#__PURE__*/React.createElement("option",{key:scale,value:scale},"1 : ",scale)}))}else if(_this.props.allowedScales!==false){scaleChooser=/*#__PURE__*/React.createElement(NumberInput,{min:1,mobile:true,onChange:_this.changeScale,prefix:"1 : ",value:_this.state.scale||null})}return/*#__PURE__*/React.createElement("div",{className:"mapexport-body"},/*#__PURE__*/React.createElement("form",{action:"#",method:"POST",onSubmit:_this["export"],ref:function ref(el){_this.form=el}},/*#__PURE__*/React.createElement("table",{className:"options-table"},/*#__PURE__*/React.createElement("tbody",null,/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("mapexport.format")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{onChange:_this.changeFormat,value:_this.state.selectedFormat},_this.state.availableFormats.map(function(format){return/*#__PURE__*/React.createElement("option",{key:format,value:format},formatMap[format]||format)})))),formatConfigurations.length>1?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("mapexport.configuration")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{onChange:_this.setSelectedFormatConfiguration,value:_this.state.selectedFormatConfiguration},formatConfigurations.map(function(config){return/*#__PURE__*/React.createElement("option",{key:config.name,value:config.name},config.labelMsgId?LocaleUtils.tr(config.labelMsgId):config.name)})))):null,!isEmpty(_this.props.pageSizes)?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("mapexport.size")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{onChange:function onChange(ev){return _this.setState({pageSize:ev.target.value||null})},value:_this.state.pageSize||""},/*#__PURE__*/React.createElement("option",{value:""},LocaleUtils.tr("mapexport.usersize")),_this.props.pageSizes.map(function(entry,idx){return/*#__PURE__*/React.createElement("option",{key:"size_"+idx,value:idx},entry.name)})))):null,scaleChooser&&_this.state.pageSize!==null?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("mapexport.scale")),/*#__PURE__*/React.createElement("td",null,scaleChooser)):null,_this.props.dpis&&_this.state.selectedFormat!=="application/dxf"?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("mapexport.resolution")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{onChange:_this.changeResolution,value:_this.state.dpi},_this.props.dpis.map(function(dpi){return/*#__PURE__*/React.createElement("option",{key:dpi+"dpi",value:dpi},dpi+" dpi")})))):null,((formatConfiguration===null||formatConfiguration===void 0?void 0:formatConfiguration.projections)||[]).length>1?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("mapexport.projection")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{onChange:function onChange(ev){return _this.setState({exportProjection:ev.target.value})},value:_this.state.exportProjection},formatConfiguration.projections.map(function(proj){return/*#__PURE__*/React.createElement("option",{key:proj,value:proj},proj)})))):null)),/*#__PURE__*/React.createElement("div",{className:"button-bar"},/*#__PURE__*/React.createElement("button",{className:"button",disabled:_this.state.exporting||isEmpty(_this.state.extents),type:"submit"},_this.state.exporting?/*#__PURE__*/React.createElement("span",{className:"mapexport-wait"},/*#__PURE__*/React.createElement(Spinner,null)," ",LocaleUtils.tr("mapexport.wait")):LocaleUtils.tr("mapexport.submit")))))});_defineProperty(_this,"renderPrintSelection",function(){if(_this.state.pageSize!==null){var pageSize=_this.props.pageSizes[_this.state.pageSize];var frame={width:pageSize.width,height:pageSize.height};return/*#__PURE__*/React.createElement(PrintSelection,{allowRotation:false,allowScaling:_this.props.allowedScales!==false,center:_this.props.map.center,fixedFrame:frame,geometryChanged:_this.geometryChanged,key:"PrintSelection",scale:_this.state.scale})}else{return/*#__PURE__*/React.createElement(PrintSelection,{allowRotation:false,geometryChanged:_this.geometryChanged,key:"PrintSelection"})}});_defineProperty(_this,"onShow",function(){var _this$props$formatCon4,_formatConfigurations3,_formatConfigurations4;var scale=Math.round(MapUtils.computeForZoom(_this.props.map.scales,_this.props.map.zoom)*_this.props.defaultScaleFactor);if(!isEmpty(_this.props.allowedScales)){var closestVal=Math.abs(scale-_this.props.allowedScales[0]);var closestIdx=0;for(var i=1;i<_this.props.allowedScales.length;++i){var currVal=Math.abs(scale-_this.props.allowedScales[i]);if(currVal<closestVal){closestVal=currVal;closestIdx=i}}scale=_this.props.allowedScales[closestIdx]}var availableFormats=_toConsumableArray(_this.props.theme.availableFormats);(_this.props.forceAvailableFormats||[]).forEach(function(format){if(!availableFormats.includes(format)){availableFormats.push(format)}});if(!isEmpty(_this.props.allowedFormats)){availableFormats=_this.props.allowedFormats.filter(function(fmt){return availableFormats.includes(fmt)})}var selectedFormat=_this.props.defaultFormat&&availableFormats.includes(_this.props.defaultFormat)?_this.props.defaultFormat:availableFormats[0];var formatConfigurations=((_this$props$formatCon4=_this.props.formatConfiguration)===null||_this$props$formatCon4===void 0?void 0:_this$props$formatCon4[selectedFormat.split(";")[0]])||[];_this.setState({scale:scale,availableFormats:availableFormats,selectedFormat:selectedFormat,selectedFormatConfiguration:(_formatConfigurations3=formatConfigurations[0])===null||_formatConfigurations3===void 0?void 0:_formatConfigurations3.name,exportProjection:_this.getExportProjection((_formatConfigurations4=formatConfigurations[0])===null||_formatConfigurations4===void 0?void 0:_formatConfigurations4.projections)});_this.props.setSnappingConfig(false,false)});_defineProperty(_this,"onHide",function(){_this.setState({extents:[],width:0,height:0,scale:null,pageSize:null})});_defineProperty(_this,"geometryChanged",function(center,extents,rotation,scale){_this.setState(function(state){return{extents:extents,scale:scale!==null&&scale!==void 0?scale:state.scale}})});_defineProperty(_this,"export",function(ev){var _this$props$formatCon5,_this$state$extents$a;ev.preventDefault();_this.setState({exporting:true});var format=_this.state.selectedFormat.split(";")[0];var formatConfiguration=(((_this$props$formatCon5=_this.props.formatConfiguration)===null||_this$props$formatCon5===void 0?void 0:_this$props$formatCon5[format])||[]).find(function(entry){return entry.name===_this.state.selectedFormatConfiguration});var version=_this.props.theme.version;var crs=_this.state.exportProjection;var extent=CoordinatesUtils.reprojectBbox((_this$state$extents$a=_this.state.extents.at(0))!==null&&_this$state$extents$a!==void 0?_this$state$extents$a:[0,0,0,0],_this.props.map.projection,crs);var formattedExtent=CoordinatesUtils.getAxisOrder(crs).substring(0,2)==="ne"&&version==="1.3.0"?extent[1]+","+extent[0]+","+extent[3]+","+extent[2]:extent.join(",");var getPixelFromCoordinate=MapUtils.getHook(MapUtils.GET_PIXEL_FROM_COORDINATES_HOOK);var p1=getPixelFromCoordinate(extent.slice(0,2));var p2=getPixelFromCoordinate(extent.slice(2,4));var width=Math.round(Math.abs(p1[0]-p2[0])*_this.state.dpi/96);var height=Math.round(Math.abs(p1[1]-p2[1])*_this.state.dpi/96);var ext=format.split("/").pop();var timestamp=dayjs(new Date).format("YYYYMMDD_HHmmss");var fileName=_this.props.fileNameTemplate.replace("{username}",ConfigUtils.getConfigProp("username",null,"")).replace("{tenant}",ConfigUtils.getConfigProp("tenant",null,"")).replace("{theme}",_this.props.theme.id).replace("{themeTitle}",_this.props.theme.title||"").replace("{timestamp}",timestamp)+"."+ext;var params={};// Base request params
params.SERVICE="WMS";params.VERSION=version;params.REQUEST="GetMap";params.FORMAT=_this.state.selectedFormat;params.DPI=_this.state.dpi;params.TRANSPARENT=true;params.TILED=false;params.CRS=crs;params.BBOX=formattedExtent;params.WIDTH=width;params.HEIGHT=height;params.filename=fileName;// Dimension values
_this.props.layers.forEach(function(layer){if(layer.role===LayerRole.THEME){Object.entries(layer.dimensionValues||{}).forEach(function(_ref){var _ref2=_slicedToArray(_ref,2),key=_ref2[0],value=_ref2[1];if(value!==undefined){params[key]=value}})}});// Add parameters from custom format configuration
if(formatConfiguration){var _formatConfiguration$;var keyCaseMap=Object.keys(params).reduce(function(res,key){return _objectSpread(_objectSpread({},res),{},_defineProperty({},key.toLowerCase(),key))},{});(formatConfiguration.extraQuery||"").split(/[?&]/).filter(Boolean).forEach(function(entry){var _entry$split=entry.split("="),_entry$split2=_slicedToArray(_entry$split,2),key=_entry$split2[0],value=_entry$split2[1];var caseKey=keyCaseMap[key.toLowerCase()]||key;params[caseKey]=value!==null&&value!==void 0?value:""});params.FORMAT_OPTIONS=(_formatConfiguration$=formatConfiguration.formatOptions)!==null&&_formatConfiguration$!==void 0?_formatConfiguration$:"";if(formatConfiguration.baseLayer){var layers=params[keyCaseMap.layers].split(",");if(!layers.includes(formatConfiguration.baseLayer)){params[keyCaseMap.layers]=[formatConfiguration.baseLayer].concat(_toConsumableArray(layers))}}}if(_this.state.selectedFormat==="application/dxf"){_this.dxfExport(params,fileName,formatConfiguration)}else{_this.genericExport(params,fileName,formatConfiguration)}});_defineProperty(_this,"genericExport",function(params,fileName,formatConfiguration){var _formatConfiguration$2;// Layer params
var exportExternalLayers=_this.props.exportExternalLayers&&ConfigUtils.getConfigProp("qgisServerVersion",null,3)>=3;var exportParams=LayerUtils.collectPrintParams(_this.props.layers,_this.props.theme,_this.state.scale,_this.state.exportProjection,exportExternalLayers,!!(formatConfiguration!==null&&formatConfiguration!==void 0&&formatConfiguration.baseLayer));Object.assign(params,exportParams);// Highlight params
var highlightParams=VectorLayerUtils.createPrintHighlighParams(_this.props.layers,_this.state.exportProjection,_this.state.scale,_this.state.dpi);params.HIGHLIGHT_GEOM=highlightParams.geoms.join(";");params.HIGHLIGHT_SYMBOL=highlightParams.styles.join(";");params.HIGHLIGHT_LABELSTRING=highlightParams.labels.join(";");params.HIGHLIGHT_LABELCOLOR=highlightParams.labelFillColors.join(";");params.HIGHLIGHT_LABELBUFFERCOLOR=highlightParams.labelOutlineColors.join(";");params.HIGHLIGHT_LABELBUFFERSIZE=highlightParams.labelOutlineSizes.join(";");params.HIGHLIGHT_LABELSIZE=highlightParams.labelSizes.join(";");params.HIGHLIGHT_LABEL_DISTANCE=highlightParams.labelDist.join(";");params.HIGHLIGHT_LABEL_ROTATION=highlightParams.labelRotations.join(";");// Watermark params
Object.keys(_this.props.theme.watermark||{}).forEach(function(key){params["WATERMARK_"+key.toUpperCase()]=_this.props.theme.watermark[key]});var data=Object.entries(params).map(function(pair){return pair.map(function(entry){return encodeURIComponent(entry).replace(/%20/g,"+")}).join("=")}).join("&");var config={headers:{"Content-Type":"application/x-www-form-urlencoded"},responseType:"arraybuffer"};axios.post((_formatConfiguration$2=formatConfiguration.serviceUrl)!==null&&_formatConfiguration$2!==void 0?_formatConfiguration$2:_this.props.theme.url,data,config).then(function(response){_this.setState({exporting:false});var contentType=response.headers["content-type"];FileSaver.saveAs(new Blob([response.data],{type:contentType}),fileName)})["catch"](function(e){_this.setState({exporting:false});if(e.response){/* eslint-disable-next-line */console.log(new TextDecoder().decode(e.response.data))}/* eslint-disable-next-line */alert("Export failed")})});_defineProperty(_this,"dxfExport",function(baseParams,fileName,formatConfiguration){var promises=_this.props.layers.filter(function(layer){var _layer$mapFormats;return layer.type==="wms"&&layer.role>LayerRole.BACKGROUND&&((_layer$mapFormats=layer.mapFormats)===null||_layer$mapFormats===void 0?void 0:_layer$mapFormats.includes("application/dxf"))}).reverse().map(function(layer){var _layer$params$FILTER,_layer$params$FILTER_;var params=_objectSpread(_objectSpread({},baseParams),{},{LAYERS:layer.params.LAYERS,OPACITIES:layer.params.OPACITIES,STYLES:layer.params.STYLES,FILTER:(_layer$params$FILTER=layer.params.FILTER)!==null&&_layer$params$FILTER!==void 0?_layer$params$FILTER:"",FILTER_GEOM:(_layer$params$FILTER_=layer.params.FILTER_GEOM)!==null&&_layer$params$FILTER_!==void 0?_layer$params$FILTER_:""});var data=Object.entries(params).map(function(pair){return pair.map(function(entry){return encodeURIComponent(entry).replace(/%20/g,"+")}).join("=")}).join("&");var config={headers:{"Content-Type":"application/x-www-form-urlencoded"},responseType:"arraybuffer"};return new Promise(function(resolve,reject){var _formatConfiguration$3;axios.post((_formatConfiguration$3=formatConfiguration.serviceUrl)!==null&&_formatConfiguration$3!==void 0?_formatConfiguration$3:layer.url,data,config).then(function(response){resolve(response)})["catch"](function(e){/* eslint-disable-next-line */console.warn(e);resolve(null)})})});Promise.all(promises).then(function(responses){var decoder=new TextDecoder("iso-8859-1");var dxfDocuments=responses.filter(function(response){return response.headers["content-type"]==="application/dxf"}).map(function(response){return explodeDxf(decoder.decode(response.data))});var dxfDocument=mergeDxf(dxfDocuments);var result=implodeDxf(dxfDocument);var encoder=new TextEncoder("iso-8859-1");FileSaver.saveAs(new Blob([encoder.encode(result)],{type:"application/dxf"}),fileName);/*
responses.forEach((response, idx) => {
FileSaver.saveAs(new Blob([response.data], {type: "application/dxf"}), "orig_" + idx + "_" + fileName);
});
*/_this.setState({exporting:false})})});_this.form=null;_this.state.dpi=(props.dpis||[])[0]||96;return _this}_inherits(MapExport,_React$Component);return _createClass(MapExport,[{key:"componentDidUpdate",value:function componentDidUpdate(prevProps,prevState){if(this.state.pageSize===null&&prevState.pageSize!==null){this.setState({extents:[]})}}},{key:"render",value:function render(){var _this2=this;var minMaxTooltip=this.state.minimized?LocaleUtils.tr("print.maximize"):LocaleUtils.tr("print.minimize");var extraTitlebarContent=/*#__PURE__*/React.createElement(Icon,{className:"mapexport-minimize-maximize",icon:this.state.minimized?"chevron-down":"chevron-up",onClick:function onClick(){return _this2.setState(function(state){return{minimized:!state.minimized}})},title:minMaxTooltip});return/*#__PURE__*/React.createElement(SideBar,{extraClasses:"MapExport",extraTitlebarContent:extraTitlebarContent,icon:"rasterexport",id:"MapExport",key:"MapExport",onHide:this.onHide,onShow:this.onShow,side:this.props.side,title:LocaleUtils.tr("appmenu.items.MapExport"),width:"20em"},function(){return{body:_this2.state.minimized?null:_this2.renderBody(),extra:[_this2.renderPrintSelection()]}})}}])}(React.Component);_defineProperty(MapExport,"propTypes",{/** Whitelist of allowed export format mimetypes. If empty, supported formats are listed. */allowedFormats:PropTypes.arrayOf(PropTypes.string),/** List of scales at which to export the map. If empty, scale can be freely specified. If `false`, the map can only be exported at the current scale. */allowedScales:PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number),PropTypes.bool]),/** Default export format mimetype. If empty, first available format is used. */defaultFormat:PropTypes.string,/** The factor to apply to the map scale to determine the initial export map scale (if `allowedScales` is not `false`). */defaultScaleFactor:PropTypes.number,/** List of dpis at which to export the map. If empty, the default server dpi is used. */dpis:PropTypes.arrayOf(PropTypes.number),/** Whether to include external layers in the image. Requires QGIS Server 3.x! */exportExternalLayers:PropTypes.bool,/** Template for the name of the generated files when downloading. Can contain the placeholders `{username}`, `{tenant}`, `{theme}`, `{themeTitle}`, `{timestamp}`. */fileNameTemplate:PropTypes.string,/** Formats to force as available even if the map capabilities report otherwise. Useful if a serviceUrl is defined in a format configuration. */forceAvailableFormats:PropTypes.array,/** Custom export configuration per format.
* If more than one configuration per format is provided, a selection combo will be displayed.
* `labelMsgId` is a translation string message id for the combo label. If not defined, `name` will be displayed.
* `extraQuery` will be appended to the query string (replacing any existing parameters).
* `formatOptions` will be passed as FORMAT_OPTIONS.
* `baseLayer` will be appended to the LAYERS instead of the background layer.
* `projections` is a list of export projections. If empty, the map projection is automatically used.
* `serviceUrl` is the address of a custom service to use instead of the layer OWS service url. */formatConfiguration:PropTypes.shape({format:PropTypes.arrayOf(PropTypes.shape({name:PropTypes.string,labelMsgId:PropTypes.string,extraQuery:PropTypes.string,formatOptions:PropTypes.string,baseLayer:PropTypes.string,projections:PropTypes.array,serviceUrl:PropTypes.string}))}),layers:PropTypes.array,map:PropTypes.object,/** List of image sizes to offer, in addition to the free-hand selection. The width and height are in millimeters. */pageSizes:PropTypes.arrayOf(PropTypes.shape({name:PropTypes.string,width:PropTypes.number,height:PropTypes.number})),setIdentifyEnabled:PropTypes.func,setSnappingConfig:PropTypes.func,/** The side of the application on which to display the sidebar. */side:PropTypes.string,theme:PropTypes.object});_defineProperty(MapExport,"defaultProps",{defaultScaleFactor:1,exportExternalLayers:true,fileNameTemplate:"{theme}_{timestamp}",side:"right",pageSizes:[]});var selector=function selector(state){return{theme:state.theme.current,map:state.map,layers:state.layers.flat}};export default connect(selector,{setSnappingConfig:setSnappingConfig})(MapExport);