qwc2 2025.10.2 → 2025.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/plugins/Print.js CHANGED
@@ -10,7 +10,7 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
10
10
  * Uses the print layouts defined in the QGIS project.
11
11
  */var Print=/*#__PURE__*/function(_React$Component){function Print(props){var _this;_classCallCheck(this,Print);_this=_callSuper(this,Print,[props]);_defineProperty(_this,"state",{center:null,extents:[],layout:null,layouts:[],rotation:0,scale:0,dpi:300,grid:false,legend:false,minimized:false,printOutputVisible:false,outputLoaded:false,printing:false,atlasFeatures:[],geoPdf:false,selectedFormat:"",printOutputData:undefined,pdfData:null,pdfDataUrl:null,downloadMode:"onepdf",printSeriesEnabled:false,printSeriesOverlap:0,printSeriesSelected:[]});_defineProperty(_this,"onShow",function(){// setup initial extent
12
12
  var scale=Math.round(MapUtils.computeForZoom(_this.props.map.scales,_this.props.map.zoom)*_this.props.defaultScaleFactor);if(_this.props.theme.printScales&&_this.props.theme.printScales.length>0){var closestVal=Math.abs(scale-_this.props.theme.printScales[0]);var closestIdx=0;for(var i=1;i<_this.props.theme.printScales.length;++i){var currVal=Math.abs(scale-_this.props.theme.printScales[i]);if(currVal<closestVal){closestVal=currVal;closestIdx=i}}scale=_this.props.theme.printScales[closestIdx]}var bounds=_this.props.map.bbox.bounds;var center=_this.state.center||[0,0];var resetCenter=center[0]<bounds[0]||center[0]>bounds[2]||center[1]<bounds[1]||center[1]>bounds[3];var resetScale=_this.state.scale/scale<0.01||_this.state.scale/scale>10;if(resetCenter||resetScale){_this.setState({center:null,rotation:0,scale:scale})}_this.props.setSnappingConfig(false,false)});_defineProperty(_this,"onHide",function(){_this.setState({minimized:false,printSeriesEnabled:false,atlasFeatures:[]})});_defineProperty(_this,"renderBody",function(){var _this$state$extents$a,_this$state$layout$la,_this$state$layout;if(!_this.state.layout){return/*#__PURE__*/React.createElement("div",{className:"print-body",role:"body"},LocaleUtils.tr("print.nolayouts"))}var haveThemeLayers=_this.props.layers.find(function(layer){return layer.role===LayerRole.THEME})!==undefined;if(!_this.props.theme||!_this.props.printExternalLayers&&!haveThemeLayers){return/*#__PURE__*/React.createElement("div",{className:"print-body",role:"body"},LocaleUtils.tr("print.notheme"))}var mapName=_this.state.layout.map.name;var printLegend=_this.state.layout.legendLayout;var formattedExtent=!isEmpty(_this.state.atlasFeatures)?"":_this.formatExtent((_this$state$extents$a=_this.state.extents.at(0))!==null&&_this$state$extents$a!==void 0?_this$state$extents$a:[0,0,0,0]);var resolutionChooser=null;var resolutionInput=null;if(!isEmpty(_this.props.theme.printResolutions)){if(_this.props.theme.printResolutions.length>1){resolutionChooser=/*#__PURE__*/React.createElement("select",{name:"DPI",onChange:function onChange(ev){return _this.changeResolution(ev.target.value)},value:_this.state.dpi||""},_this.props.theme.printResolutions.map(function(res){return/*#__PURE__*/React.createElement("option",{key:res,value:res},res," dpi")}))}else{resolutionInput=/*#__PURE__*/React.createElement("input",{name:"DPI",readOnly:true,type:"hidden",value:_this.props.theme.printResolutions[0]})}}else{resolutionChooser=/*#__PURE__*/React.createElement(NumberInput,{max:1200,min:50,mobile:true,name:"DPI",onChange:_this.changeResolution,suffix:" dpi",value:_this.state.dpi||""})}var formatMap={"application/pdf":"PDF","image/jpeg":"JPEG","image/png":"PNG","image/svg":"SVG"};var allowGeoPdfExport=_this.state.selectedFormat==="application/pdf"&&_this.props.allowGeoPdfExport;return/*#__PURE__*/React.createElement("div",{className:"print-body"},/*#__PURE__*/React.createElement("form",{action:_this.props.theme.printUrl,method:"POST",onSubmit:_this.print,ref:function ref(el){_this.printForm=el}},/*#__PURE__*/React.createElement("input",{name:"TEMPLATE",type:"hidden",value:printLegend&&_this.state.legend?printLegend:_this.state.layout.name}),/*#__PURE__*/React.createElement("table",{className:"options-table"},/*#__PURE__*/React.createElement("tbody",null,/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.layout")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{onChange:_this.changeLayout,value:_this.state.layout.name},_this.state.layouts.map(function(item){return/*#__PURE__*/React.createElement("option",{key:item.name,value:item.name},_this.translateLayoutName(item.name))})))),_this.props.formats.length>1?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.format")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{disabled:_this.state.printSeriesEnabled,name:"FORMAT",onChange:_this.formatChanged,value:_this.state.selectedFormat},_this.props.formats.map(function(format){return/*#__PURE__*/React.createElement("option",{key:format,value:format},formatMap[format]||format)})))):null,_this.state.layout.atlasCoverageLayer&&!_this.state.printSeriesEnabled?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.atlasfeature")),/*#__PURE__*/React.createElement("td",null,!isEmpty(_this.state.atlasFeatures)?/*#__PURE__*/React.createElement("div",{className:"print-atlas-features"},_this.state.atlasFeatures.map(function(feature){return/*#__PURE__*/React.createElement("span",{key:feature.id},/*#__PURE__*/React.createElement("span",null,feature.properties[feature.displayfield]),/*#__PURE__*/React.createElement(Icon,{icon:"remove",onClick:function onClick(){return _this.deselectAtlasFeature(feature)}}))}),/*#__PURE__*/React.createElement("input",{name:"ATLAS_PK",type:"hidden",value:_this.state.atlasFeatures.map(function(feature){var _feature$properties$_;return(_feature$properties$_=feature.properties[_this.state.layout.atlas_pk])!==null&&_feature$properties$_!==void 0?_feature$properties$_:feature.id}).join(",")})):/*#__PURE__*/React.createElement("input",{disabled:true,placeholder:LocaleUtils.tr("print.pickatlasfeature",_this.state.layout.atlasCoverageLayer),type:"text"}))):null,isEmpty(_this.state.atlasFeatures)?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.scale")),/*#__PURE__*/React.createElement("td",null,!isEmpty(_this.props.theme.printScales)?/*#__PURE__*/React.createElement(InputContainer,null,/*#__PURE__*/React.createElement("span",{role:"prefix"},"1\xA0:\xA0"),/*#__PURE__*/React.createElement(EditableSelect,{name:mapName+":scale",onChange:_this.changeScale,options:_this.props.theme.printScales,role:"input",value:_this.state.scale||""})):/*#__PURE__*/React.createElement(NumberInput,{min:1,mobile:true,name:mapName+":scale",onChange:_this.changeScale,prefix:"1 : ",value:_this.state.scale||null}))):null,resolutionChooser?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.resolution")),/*#__PURE__*/React.createElement("td",null,resolutionChooser)):null,_this.props.displayRotation?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.rotation")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(InputContainer,null,/*#__PURE__*/React.createElement(NumberInput,{decimals:1,mobile:true,name:mapName+":rotation",onChange:_this.changeRotation,role:"input",value:_this.state.rotation}),/*#__PURE__*/React.createElement("span",{role:"suffix",style:{transform:"rotate(-"+_this.state.rotation+"deg)"}},/*#__PURE__*/React.createElement(Icon,{icon:"arrow-up",onClick:function onClick(){return _this.setState({rotation:0})},title:LocaleUtils.tr("map.resetrotation")}))))):null,!isEmpty(_this.props.theme.printGrid)?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.grid")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(ToggleSwitch,{active:_this.state.grid,onChange:function onChange(newstate){return _this.setState({grid:newstate})}}))):null,printLegend?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.legend")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(ToggleSwitch,{active:_this.state.legend,onChange:function onChange(newstate){return _this.setState({legend:newstate})}}))):null,_this.props.displayPrintSeries?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.series")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(ToggleSwitch,{active:_this.state.printSeriesEnabled,onChange:function onChange(newstate){return _this.setState({printSeriesEnabled:newstate,atlasFeatures:[]})}}))):null,_this.state.printSeriesEnabled?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.overlap")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(InputContainer,null,/*#__PURE__*/React.createElement("input",{max:"20",min:"0",onChange:_this.changeSeriesOverlap,role:"input",type:"range",value:_this.state.printSeriesOverlap}),/*#__PURE__*/React.createElement("span",{role:"suffix"},_this.state.printSeriesOverlap,"\xA0%")))):null,!_this.props.inlinePrintOutput&&_this.state.printSeriesEnabled?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("print.download")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{onChange:_this.changeDownloadMode,role:"input",value:_this.state.downloadMode||""},/*#__PURE__*/React.createElement("option",{key:"onepdf",value:"onepdf"},LocaleUtils.tr("print.download_as_onepdf")),/*#__PURE__*/React.createElement("option",{key:"onezip",value:"onezip"},LocaleUtils.tr("print.download_as_onezip")),/*#__PURE__*/React.createElement("option",{key:"single",value:"single"},LocaleUtils.tr("print.download_as_single"))))):null,((_this$state$layout$la=(_this$state$layout=_this.state.layout)===null||_this$state$layout===void 0?void 0:_this$state$layout.labels)!==null&&_this$state$layout$la!==void 0?_this$state$layout$la:[]).map(function(label){var _this$props$theme$pri;// Omit labels which start with __
13
- if(label.startsWith("__")){return null}var opts=_objectSpread({rows:1,name:label.toUpperCase()},(_this$props$theme$pri=_this.props.theme.printLabelConfig)===null||_this$props$theme$pri===void 0?void 0:_this$props$theme$pri[label]);return _this.renderPrintLabelField(label,opts)}),allowGeoPdfExport?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,"GeoPDF"),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(ToggleSwitch,{active:_this.state.geoPdf,onChange:function onChange(newstate){return _this.setState({geoPdf:newstate})}}))):null)),/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("input",{name:"csrf_token",type:"hidden",value:MiscUtils.getCsrfToken()}),/*#__PURE__*/React.createElement("input",{name:mapName+":extent",readOnly:true,type:"hidden",value:formattedExtent}),/*#__PURE__*/React.createElement("input",{name:"SERVICE",readOnly:true,type:"hidden",value:"WMS"}),/*#__PURE__*/React.createElement("input",{name:"VERSION",readOnly:true,type:"hidden",value:_this.props.theme.version}),/*#__PURE__*/React.createElement("input",{name:"REQUEST",readOnly:true,type:"hidden",value:"GetPrint"}),/*#__PURE__*/React.createElement("input",{name:"FORMAT",readOnly:true,type:"hidden",value:_this.state.selectedFormat}),/*#__PURE__*/React.createElement("input",{name:"TRANSPARENT",readOnly:true,type:"hidden",value:"true"}),/*#__PURE__*/React.createElement("input",{name:"SRS",readOnly:true,type:"hidden",value:_this.props.map.projection}),/*#__PURE__*/React.createElement("input",{name:"CONTENT_DISPOSITION",readOnly:true,type:"hidden",value:_this.props.inlinePrintOutput?"inline":"attachment"}),allowGeoPdfExport?/*#__PURE__*/React.createElement("input",{name:"FORMAT_OPTIONS",readOnly:true,type:"hidden",value:_this.state.geoPdf?"WRITE_GEO_PDF:true":"WRITE_GEO_PDF:false"}):null,resolutionInput),/*#__PURE__*/React.createElement("div",{className:"button-bar"},/*#__PURE__*/React.createElement("button",{className:"button",disabled:_this.state.printing,type:"submit"},_this.state.printing?/*#__PURE__*/React.createElement("span",{className:"print-wait"},/*#__PURE__*/React.createElement(Spinner,null)," ",LocaleUtils.tr("print.wait")):LocaleUtils.tr("print.submit")))))});_defineProperty(_this,"renderPrintLabelField",function(label,opts){var defaultValue=opts.defaultValue||"";var autopopulated=false;if(label===_this.props.theme.printLabelForSearchResult){defaultValue=_this.getSearchMarkerLabel();autopopulated=true}else if(label===_this.props.theme.printLabelForAttribution){defaultValue=_this.getAttributionLabel();autopopulated=true}if(autopopulated&&_this.props.hideAutopopulatedFields){return/*#__PURE__*/React.createElement("tr",{key:"label."+label},/*#__PURE__*/React.createElement("td",{colSpan:"2"},/*#__PURE__*/React.createElement("input",{defaultValue:defaultValue,name:opts.name,type:"hidden"})))}else{if(opts.options){return/*#__PURE__*/React.createElement("tr",{key:"label."+label},/*#__PURE__*/React.createElement("td",null,MiscUtils.capitalizeFirst(label)),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{defaultValue:defaultValue,name:opts.name},opts.options.map(function(value){return/*#__PURE__*/React.createElement("option",{key:value,value:value},value)}))))}else{var style={};if(opts.rows||opts.cols){style.resize="none"}if(opts.cols){style.width="initial"}return/*#__PURE__*/React.createElement("tr",{key:"label."+label},/*#__PURE__*/React.createElement("td",null,MiscUtils.capitalizeFirst(label)),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("textarea",_extends({},opts,{defaultValue:defaultValue,readOnly:autopopulated,style:style}))))}}});_defineProperty(_this,"getSearchMarkerLabel",function(){var _feature$properties;var searchsellayer=_this.props.layers.find(function(layer){return layer.id==="searchselection"});var feature=((searchsellayer===null||searchsellayer===void 0?void 0:searchsellayer.features)||[]).find(function(f){return f.id==="searchmarker"});return(feature===null||feature===void 0||(_feature$properties=feature.properties)===null||_feature$properties===void 0?void 0:_feature$properties.label)||""});_defineProperty(_this,"getAttributionLabel",function(){var copyrights=_this.props.layers.reduce(function(res,layer){return _objectSpread(_objectSpread({},res),LayerUtils.getAttribution(layer,_this.props.map))},{});var el=document.createElement("span");return Object.entries(copyrights).map(function(_ref){var _ref2=_slicedToArray(_ref,2),key=_ref2[0],value=_ref2[1];if(value.title){el.innerHTML=value.title;return el.innerText}else{el.innerHTML=key;return el.innerText}}).join(" | ")});_defineProperty(_this,"renderPrintSelection",function(){var printSelection=null;if(_this.state.layout&&isEmpty(_this.state.atlasFeatures)){var frame={width:_this.state.layout.map.width,height:_this.state.layout.map.height};printSelection=/*#__PURE__*/React.createElement(PrintSelection,{allowRotation:_this.props.displayRotation&&!_this.state.printSeriesEnabled,allowScaling:!_this.state.printSeriesEnabled,allowTranslation:!_this.state.printSeriesEnabled,center:_this.state.center||_this.props.map.center,fixedFrame:frame,geometryChanged:_this.geometryChanged,key:"PrintSelection",printSeriesChanged:_this.printSeriesChanged,printSeriesEnabled:_this.props.displayPrintSeries&&_this.state.printSeriesEnabled,printSeriesOverlap:_this.state.printSeriesOverlap/100,printSeriesSelected:_this.state.printSeriesSelected,rotation:_this.state.rotation,scale:_this.state.scale})}return printSelection});_defineProperty(_this,"formatExtent",function(extent){var mapCrs=_this.props.map.projection;var version=_this.props.theme.version;if(CoordinatesUtils.getAxisOrder(mapCrs).substring(0,2)==="ne"&&version==="1.3.0"){return extent[1]+","+extent[0]+","+extent[3]+","+extent[2]}return extent.join(",")});_defineProperty(_this,"geometryChanged",function(center,extents,rotation,scale){_this.setState({center:center,extents:extents,rotation:rotation,scale:scale})});_defineProperty(_this,"printSeriesChanged",function(selected){_this.setState({printSeriesSelected:selected})});_defineProperty(_this,"renderPrintOutputWindow",function(){var extraControls=[{icon:"save",title:LocaleUtils.tr("print.save"),callback:_this.savePrintOutput}];return/*#__PURE__*/React.createElement(ResizeableWindow,{extraControls:extraControls,icon:"print",initialHeight:0.75*window.innerHeight,initialWidth:0.5*window.innerWidth,key:"PrintOutputWindow",onClose:function onClose(){return _this.setState({printOutputVisible:false,outputLoaded:false,pdfData:null,pdfDataUrl:null})},title:LocaleUtils.tr("print.output"),visible:_this.state.printOutputVisible},/*#__PURE__*/React.createElement("div",{className:"print-output-window-body",role:"body"},!_this.state.outputLoaded?/*#__PURE__*/React.createElement("span",{className:"print-output-window-wait"},/*#__PURE__*/React.createElement(Spinner,null)," ",LocaleUtils.tr("print.wait")):null,/*#__PURE__*/React.createElement("iframe",{name:"print-output-window",src:_this.state.pdfDataUrl})))});_defineProperty(_this,"savePrintOutput",function(){FileSaver.saveAs(_this.state.pdfData.content,_this.state.pdfData.fileName)});_defineProperty(_this,"selectAtlasFeature",function(layer,feature){if(!feature){return}_this.setState(function(state){var index=state.atlasFeatures.findIndex(function(f){return f.id===feature.id});if(index>=0){var newAtlasFeatures=state.atlasFeatures.slice(0);newAtlasFeatures.splice(index,1);return{atlasFeatures:newAtlasFeatures}}else{return{atlasFeatures:[].concat(_toConsumableArray(state.atlasFeatures),[feature])}}})});_defineProperty(_this,"deselectAtlasFeature",function(feature){_this.setState(function(state){var index=state.atlasFeatures.find(function(f){return f.id===feature.id});var newAtlasFeatures=state.atlasFeatures.slice(0);newAtlasFeatures.splice(index,1);return{atlasFeatures:newAtlasFeatures}})});_defineProperty(_this,"changeLayout",function(ev){var layout=_this.props.theme.print.find(function(item){return item.name===ev.target.value});_this.setState({layout:layout,atlasFeature:null})});_defineProperty(_this,"changeScale",function(value){_this.setState({scale:Math.max(1,parseInt(value,10)||0)})});_defineProperty(_this,"changeResolution",function(value){_this.setState({dpi:value||300})});_defineProperty(_this,"changeRotation",function(value){var angle=value||0;_this.setState({rotation:(angle%360+360)%360})});_defineProperty(_this,"changeSeriesOverlap",function(ev){_this.setState({printSeriesOverlap:parseInt(ev.target.value,10)||0})});_defineProperty(_this,"changeDownloadMode",function(ev){_this.setState({downloadMode:ev.target.value})});_defineProperty(_this,"formatChanged",function(ev){_this.setState({selectedFormat:ev.target.value})});_defineProperty(_this,"print",function(ev){ev.preventDefault();_this.setState({printing:true});if(_this.props.inlinePrintOutput){_this.setState({printOutputVisible:true,outputLoaded:false,pdfDataUrl:null,pdfData:null})}var formData=formDataEntries(new FormData(_this.printForm));var mapCrs=_this.props.map.projection;var mapName=_this.state.layout.map.name;// Add base print params
13
+ if(label.startsWith("__")){return null}var opts=_objectSpread({rows:1,name:label.toUpperCase()},(_this$props$theme$pri=_this.props.theme.printLabelConfig)===null||_this$props$theme$pri===void 0?void 0:_this$props$theme$pri[label]);return _this.renderPrintLabelField(label,opts)}),allowGeoPdfExport?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,"GeoPDF"),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(ToggleSwitch,{active:_this.state.geoPdf,onChange:function onChange(newstate){return _this.setState({geoPdf:newstate})}}))):null)),/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("input",{name:"csrf_token",type:"hidden",value:MiscUtils.getCsrfToken()}),/*#__PURE__*/React.createElement("input",{name:mapName+":extent",readOnly:true,type:"hidden",value:formattedExtent}),/*#__PURE__*/React.createElement("input",{name:"SERVICE",readOnly:true,type:"hidden",value:"WMS"}),/*#__PURE__*/React.createElement("input",{name:"VERSION",readOnly:true,type:"hidden",value:_this.props.theme.version}),/*#__PURE__*/React.createElement("input",{name:"REQUEST",readOnly:true,type:"hidden",value:"GetPrint"}),/*#__PURE__*/React.createElement("input",{name:"FORMAT",readOnly:true,type:"hidden",value:_this.state.selectedFormat}),/*#__PURE__*/React.createElement("input",{name:"TRANSPARENT",readOnly:true,type:"hidden",value:"true"}),/*#__PURE__*/React.createElement("input",{name:"SRS",readOnly:true,type:"hidden",value:_this.props.map.projection}),/*#__PURE__*/React.createElement("input",{name:"CONTENT_DISPOSITION",readOnly:true,type:"hidden",value:_this.props.inlinePrintOutput?"inline":"attachment"}),allowGeoPdfExport?/*#__PURE__*/React.createElement("input",{name:"FORMAT_OPTIONS",readOnly:true,type:"hidden",value:_this.state.geoPdf?"WRITE_GEO_PDF:true":"WRITE_GEO_PDF:false"}):null,resolutionInput),/*#__PURE__*/React.createElement("div",{className:"button-bar"},/*#__PURE__*/React.createElement("button",{className:"button",disabled:_this.state.printing,type:"submit"},_this.state.printing?/*#__PURE__*/React.createElement("span",{className:"print-wait"},/*#__PURE__*/React.createElement(Spinner,null)," ",LocaleUtils.tr("print.wait")):LocaleUtils.tr("print.submit")))))});_defineProperty(_this,"renderPrintLabelField",function(label,opts){var defaultValue=opts.defaultValue||"";var autopopulated=false;if(label===_this.props.theme.printLabelForSearchResult){defaultValue=_this.getSearchMarkerLabel();autopopulated=true}else if(label===_this.props.theme.printLabelForAttribution){defaultValue=_this.getAttributionLabel();autopopulated=true}if(autopopulated&&_this.props.hideAutopopulatedFields){return/*#__PURE__*/React.createElement("tr",{key:"label."+label},/*#__PURE__*/React.createElement("td",{colSpan:"2"},/*#__PURE__*/React.createElement("input",{defaultValue:defaultValue,name:opts.name,type:"hidden"})))}else{if(opts.options){return/*#__PURE__*/React.createElement("tr",{key:"label."+label},/*#__PURE__*/React.createElement("td",null,MiscUtils.capitalizeFirst(label)),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{defaultValue:defaultValue,name:opts.name},opts.options.map(function(value){return/*#__PURE__*/React.createElement("option",{key:value,value:value},value)}))))}else{var style={};if(opts.rows||opts.cols){style.resize="none"}if(opts.cols){style.width="initial"}return/*#__PURE__*/React.createElement("tr",{key:"label."+label},/*#__PURE__*/React.createElement("td",null,MiscUtils.capitalizeFirst(label)),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("textarea",_extends({},opts,{defaultValue:defaultValue,readOnly:autopopulated,style:style}))))}}});_defineProperty(_this,"getSearchMarkerLabel",function(){var _feature$properties;var searchsellayer=_this.props.layers.find(function(layer){return layer.id==="searchselection"});var feature=((searchsellayer===null||searchsellayer===void 0?void 0:searchsellayer.features)||[]).find(function(f){return f.id==="searchmarker"});return(feature===null||feature===void 0||(_feature$properties=feature.properties)===null||_feature$properties===void 0?void 0:_feature$properties.label)||""});_defineProperty(_this,"getAttributionLabel",function(){var copyrights=_this.props.layers.reduce(function(res,layer){return _objectSpread(_objectSpread({},res),LayerUtils.getAttribution(layer,_this.props.map))},{});var el=document.createElement("span");return Object.entries(copyrights).map(function(_ref){var _ref2=_slicedToArray(_ref,2),key=_ref2[0],value=_ref2[1];if(value.title){el.innerHTML=value.title;return el.innerText}else{el.innerHTML=key;return el.innerText}}).join(" | ")});_defineProperty(_this,"renderPrintSelection",function(){var printSelection=null;if(_this.state.layout&&isEmpty(_this.state.atlasFeatures)){var frame={width:_this.state.layout.map.width,height:_this.state.layout.map.height};printSelection=/*#__PURE__*/React.createElement(PrintSelection,{allowRotation:_this.props.displayRotation&&(!_this.state.printSeriesEnabled||_this.props.movePrintSeries),allowScaling:!_this.state.printSeriesEnabled||_this.props.movePrintSeries,allowTranslation:!_this.state.printSeriesEnabled||_this.props.movePrintSeries,center:_this.state.center||_this.props.map.center,fixedFrame:frame,geometryChanged:_this.geometryChanged,key:"PrintSelection",printSeriesChanged:_this.printSeriesChanged,printSeriesEnabled:_this.props.displayPrintSeries&&_this.state.printSeriesEnabled,printSeriesOverlap:_this.state.printSeriesOverlap/100,printSeriesSelected:_this.state.printSeriesSelected,rotation:_this.state.rotation,scale:_this.state.scale})}return printSelection});_defineProperty(_this,"formatExtent",function(extent){var mapCrs=_this.props.map.projection;var version=_this.props.theme.version;if(CoordinatesUtils.getAxisOrder(mapCrs).substring(0,2)==="ne"&&version==="1.3.0"){return extent[1]+","+extent[0]+","+extent[3]+","+extent[2]}return extent.join(",")});_defineProperty(_this,"geometryChanged",function(center,extents,rotation,scale){_this.setState({center:center,extents:extents,rotation:rotation,scale:scale})});_defineProperty(_this,"printSeriesChanged",function(selected){_this.setState({printSeriesSelected:selected})});_defineProperty(_this,"renderPrintOutputWindow",function(){var extraControls=[{icon:"save",title:LocaleUtils.tr("print.save"),callback:_this.savePrintOutput}];return/*#__PURE__*/React.createElement(ResizeableWindow,{extraControls:extraControls,icon:"print",initialHeight:0.75*window.innerHeight,initialWidth:0.5*window.innerWidth,key:"PrintOutputWindow",onClose:function onClose(){return _this.setState({printOutputVisible:false,outputLoaded:false,pdfData:null,pdfDataUrl:null})},title:LocaleUtils.tr("print.output"),visible:_this.state.printOutputVisible},/*#__PURE__*/React.createElement("div",{className:"print-output-window-body",role:"body"},!_this.state.outputLoaded?/*#__PURE__*/React.createElement("span",{className:"print-output-window-wait"},/*#__PURE__*/React.createElement(Spinner,null)," ",LocaleUtils.tr("print.wait")):null,/*#__PURE__*/React.createElement("iframe",{name:"print-output-window",src:_this.state.pdfDataUrl})))});_defineProperty(_this,"savePrintOutput",function(){FileSaver.saveAs(_this.state.pdfData.content,_this.state.pdfData.fileName)});_defineProperty(_this,"selectAtlasFeature",function(layer,feature){if(!feature){return}_this.setState(function(state){var index=state.atlasFeatures.findIndex(function(f){return f.id===feature.id});if(index>=0){var newAtlasFeatures=state.atlasFeatures.slice(0);newAtlasFeatures.splice(index,1);return{atlasFeatures:newAtlasFeatures}}else{return{atlasFeatures:[].concat(_toConsumableArray(state.atlasFeatures),[feature])}}})});_defineProperty(_this,"deselectAtlasFeature",function(feature){_this.setState(function(state){var index=state.atlasFeatures.find(function(f){return f.id===feature.id});var newAtlasFeatures=state.atlasFeatures.slice(0);newAtlasFeatures.splice(index,1);return{atlasFeatures:newAtlasFeatures}})});_defineProperty(_this,"changeLayout",function(ev){var layout=_this.props.theme.print.find(function(item){return item.name===ev.target.value});_this.setState({layout:layout,atlasFeature:null})});_defineProperty(_this,"changeScale",function(value){_this.setState({scale:Math.max(1,parseInt(value,10)||0)})});_defineProperty(_this,"changeResolution",function(value){_this.setState({dpi:value||300})});_defineProperty(_this,"changeRotation",function(value){var angle=value||0;_this.setState({rotation:(angle%360+360)%360})});_defineProperty(_this,"changeSeriesOverlap",function(ev){_this.setState({printSeriesOverlap:parseInt(ev.target.value,10)||0})});_defineProperty(_this,"changeDownloadMode",function(ev){_this.setState({downloadMode:ev.target.value})});_defineProperty(_this,"formatChanged",function(ev){_this.setState({selectedFormat:ev.target.value})});_defineProperty(_this,"print",function(ev){ev.preventDefault();_this.setState({printing:true});if(_this.props.inlinePrintOutput){_this.setState({printOutputVisible:true,outputLoaded:false,pdfDataUrl:null,pdfData:null})}var formData=formDataEntries(new FormData(_this.printForm));var mapCrs=_this.props.map.projection;var mapName=_this.state.layout.map.name;// Add base print params
14
14
  var printParams=LayerUtils.collectPrintParams(_this.props.layers,_this.props.theme,_this.state.scale,mapCrs,_this.props.printExternalLayers);Object.entries(printParams).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),key=_ref4[0],value=_ref4[1];formData[key]=value});formData[mapName+":LAYERS"]=printParams.LAYERS;formData[mapName+":STYLES"]=printParams.STYLES;formData[mapName+":FILTER"]=printParams.FILTER;formData[mapName+":FILTER_GEOM"]=printParams.FILTER_GEOM;// Add highlight params
15
15
  var printDpi=parseInt(_this.state.dpi,10)||0;if(_this.props.printMapHighlights){var highlightParams=VectorLayerUtils.createPrintHighlighParams(_this.props.layers,mapCrs,_this.state.scale,printDpi,_this.props.scaleFactor);formData[mapName+":HIGHLIGHT_GEOM"]=highlightParams.geoms.join(";");formData[mapName+":HIGHLIGHT_SYMBOL"]=highlightParams.styles.join(";");formData[mapName+":HIGHLIGHT_LABELSTRING"]=highlightParams.labels.join(";");formData[mapName+":HIGHLIGHT_LABELCOLOR"]=highlightParams.labelFillColors.join(";");formData[mapName+":HIGHLIGHT_LABELBUFFERCOLOR"]=highlightParams.labelOutlineColors.join(";");formData[mapName+":HIGHLIGHT_LABELBUFFERSIZE"]=highlightParams.labelOutlineSizes.join(";");formData[mapName+":HIGHLIGHT_LABELSIZE"]=highlightParams.labelSizes.join(";");formData[mapName+":HIGHLIGHT_LABEL_DISTANCE"]=highlightParams.labelDist.join(";");formData[mapName+":HIGHLIGHT_LABEL_ROTATION"]=highlightParams.labelRotations.join(";")}// Add grid params
16
16
  var printGrid=_this.props.theme.printGrid;if(!isEmpty(printGrid)){if(_this.state.grid){var cur=0;while(cur<printGrid.length-1&&_this.state.scale<printGrid[cur].s){cur+=1}formData[mapName+":GRID_INTERVAL_X"]=printGrid[cur].x;formData[mapName+":GRID_INTERVAL_Y"]=printGrid[cur].y}else{formData[mapName+":GRID_INTERVAL_X"]=0;formData[mapName+":GRID_INTERVAL_Y"]=0}}// Add dimension values
@@ -19,5 +19,5 @@ var extraOptions=Object.fromEntries((_this.props.theme.extraPrintParameters||"")
19
19
  _this.batchPrint(pages,fileName)["catch"](function(e){_this.setState({outputLoaded:true,printOutputVisible:false});if(e.response){/* eslint-disable-next-line */console.warn(new TextDecoder().decode(e.response.data))}/* eslint-disable-next-line */alert("Print failed")})["finally"](function(){_this.setState({printing:false})})});_defineProperty(_this,"translateLayoutName",function(name){var _this$props$theme$tra,_this$props$theme$tra2;return(_this$props$theme$tra=(_this$props$theme$tra2=_this.props.theme.translations)===null||_this$props$theme$tra2===void 0||(_this$props$theme$tra2=_this$props$theme$tra2.layouts)===null||_this$props$theme$tra2===void 0?void 0:_this$props$theme$tra2[name])!==null&&_this$props$theme$tra!==void 0?_this$props$theme$tra:name});_this.printForm=null;_this.state.grid=props.gridInitiallyEnabled;_this.state.dpi=props.defaultDpi;_this.state.selectedFormat=props.formats[0];return _this}_inherits(Print,_React$Component);return _createClass(Print,[{key:"componentDidUpdate",value:function componentDidUpdate(prevProps,prevState){var _this2=this;if(prevProps.theme!==this.props.theme){if(this.props.theme&&!isEmpty(this.props.theme.print)){var sortDir=this.props.layoutSortOrder==="desc"?-1:1;var layouts=this.props.theme.print.filter(function(l){return l.map&&!l.name.split("/").pop().startsWith(_this2.props.layoutHidePrefix)}).sort(function(a,b){return sortDir*a.name.split("/").pop().localeCompare(b.name.split("/").pop(),undefined,{numeric:true})});var layout=layouts.find(function(l){return l["default"]})||layouts[0];this.setState({layouts:layouts,layout:layout,atlasFeatures:[]})}else{this.setState({layouts:[],layout:null,atlasFeatures:[]})}}if(this.state.atlasFeatures!==prevState.atlasFeatures){if(!isEmpty(this.state.atlasFeatures)){var layer={id:"print-pick-selection",role:LayerRole.SELECTION,skipPrint:true};this.props.addLayerFeatures(layer,this.state.atlasFeatures,true)}else if(!isEmpty(prevState.atlasFeatures)){this.props.clearLayer("print-pick-selection")}}if(this.state.printSeriesEnabled&&this.state.selectedFormat!=="application/pdf"){this.setState({selectedFormat:"application/pdf"})}}},{key:"render",value:function render(){var _this3=this;var minMaxTooltip=this.state.minimized?LocaleUtils.tr("print.maximize"):LocaleUtils.tr("print.minimize");var extraTitlebarContent=/*#__PURE__*/React.createElement(Icon,{className:"print-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 themeLayer=this.props.layers.find(function(layer){return layer.role===LayerRole.THEME});return[/*#__PURE__*/React.createElement(SideBar,{extraTitlebarContent:extraTitlebarContent,icon:"print",id:"Print",key:"Print",onHide:this.onHide,onShow:this.onShow,side:this.props.side,title:LocaleUtils.tr("appmenu.items.Print"),width:"20em"},function(){return{body:_this3.state.minimized?null:_this3.renderBody(),extra:[_this3.renderPrintSelection()]}}),this.renderPrintOutputWindow(),this.props.active&&this.state.layout&&this.state.layout.atlasCoverageLayer&&!this.state.printSeriesEnabled?/*#__PURE__*/React.createElement(PickFeature,{featurePicked:this.selectAtlasFeature,key:"FeaturePicker",layerFilter:{url:themeLayer===null||themeLayer===void 0?void 0:themeLayer.url,name:this.state.layout.atlasCoverageLayer}}):null]}},{key:"batchPrint",value:function(){var _batchPrint=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(pages,fileName){var _this4=this;var promises,docs,files,file,fileURL,_iterator,_step,_file;return _regeneratorRuntime().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:// Print pages on server
20
20
  promises=pages.map(function(formData){return _this4.printRequest(formData)});// Collect printing results
21
21
  _context.next=3;return Promise.all(promises);case 3:docs=_context.sent;_context.next=6;return this.collectFiles(docs,fileName);case 6:files=_context.sent;// Download or display files
22
- if(this.props.inlinePrintOutput&&files.length===1){file=files.pop();fileURL=URL.createObjectURL(file.content);this.setState({pdfData:file,pdfDataUrl:fileURL,outputLoaded:true})}else{_iterator=_createForOfIteratorHelper(files);try{for(_iterator.s();!(_step=_iterator.n()).done;){_file=_step.value;FileSaver.saveAs(_file.content,_file.fileName)}}catch(err){_iterator.e(err)}finally{_iterator.f()}}case 8:case"end":return _context.stop()}},_callee,this)}));function batchPrint(_x,_x2){return _batchPrint.apply(this,arguments)}return batchPrint}()},{key:"printRequest",value:function(){var _printRequest=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(formData){var data,config,response,contentType;return _regeneratorRuntime().wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:data=Object.entries(formData).map(function(pair){return pair.map(function(entry){return encodeURIComponent(entry).replace(/%20/g,"+")}).join("=")}).join("&");config={headers:{"Content-Type":"application/x-www-form-urlencoded"},responseType:"arraybuffer"};_context2.next=4;return axios.post(this.props.theme.printUrl,data,config);case 4:response=_context2.sent;contentType=response.headers["content-type"];return _context2.abrupt("return",{name:formData.name,data:response.data,contentType:contentType});case 7:case"end":return _context2.stop()}},_callee2,this)}));function printRequest(_x3){return _printRequest.apply(this,arguments)}return printRequest}()},{key:"collectFiles",value:function(){var _collectFiles=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(docs,fileName){var _this5=this;var data,content,_data,_content;return _regeneratorRuntime().wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:if(!(docs.length>1&&this.state.downloadMode==="onepdf")){_context3.next=6;break}_context3.next=3;return this.collectOnePdf(docs);case 3:data=_context3.sent;content=new Blob([data],{type:"application/pdf"});return _context3.abrupt("return",[{content:content,fileName:fileName+".pdf"}]);case 6:if(!(docs.length>1&&this.state.downloadMode==="onezip")){_context3.next=12;break}_context3.next=9;return this.collectOneZip(docs,fileName);case 9:_data=_context3.sent;_content=new Blob([_data],{type:"application/zip"});return _context3.abrupt("return",[{content:_content,fileName:fileName+".zip"}]);case 12:return _context3.abrupt("return",docs.map(function(doc){var content=new Blob([doc.data],{type:doc.contentType});var ext=_this5.state.selectedFormat.split(";")[0].split("/").pop();var appendix=doc.name?"_"+doc.name:"";return{content:content,fileName:fileName+appendix+"."+ext}}));case 13:case"end":return _context3.stop()}},_callee3,this)}));function collectFiles(_x4,_x5){return _collectFiles.apply(this,arguments)}return collectFiles}()},{key:"collectOnePdf",value:function(){var _collectOnePdf=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(docs){var _yield$import,PDFDocument,mergedDoc,_iterator2,_step2,doc,pdfBytes,copiedPages,_iterator3,_step3,page;return _regeneratorRuntime().wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:_context4.next=2;return import("pdf-lib");case 2:_yield$import=_context4.sent;PDFDocument=_yield$import.PDFDocument;_context4.next=6;return PDFDocument.create();case 6:mergedDoc=_context4.sent;_iterator2=_createForOfIteratorHelper(docs);_context4.prev=8;_iterator2.s();case 10:if((_step2=_iterator2.n()).done){_context4.next=22;break}doc=_step2.value;_context4.next=14;return PDFDocument.load(doc.data);case 14:pdfBytes=_context4.sent;_context4.next=17;return mergedDoc.copyPages(pdfBytes,pdfBytes.getPageIndices());case 17:copiedPages=_context4.sent;_iterator3=_createForOfIteratorHelper(copiedPages);try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){page=_step3.value;mergedDoc.addPage(page)}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}case 20:_context4.next=10;break;case 22:_context4.next=27;break;case 24:_context4.prev=24;_context4.t0=_context4["catch"](8);_iterator2.e(_context4.t0);case 27:_context4.prev=27;_iterator2.f();return _context4.finish(27);case 30:_context4.next=32;return mergedDoc.save();case 32:return _context4.abrupt("return",_context4.sent);case 33:case"end":return _context4.stop()}},_callee4,null,[[8,24,27,30]])}));function collectOnePdf(_x6){return _collectOnePdf.apply(this,arguments)}return collectOnePdf}()},{key:"collectOneZip",value:function(){var _collectOneZip=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(docs,fileName){var mergedDoc,_iterator4,_step4,doc,file,ext,appendix;return _regeneratorRuntime().wrap(function _callee5$(_context5){while(1)switch(_context5.prev=_context5.next){case 0:mergedDoc=new JSZip;_iterator4=_createForOfIteratorHelper(docs);try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){doc=_step4.value;file=new Blob([doc.data],{type:doc.contentType});ext=this.state.selectedFormat.split(";")[0].split("/").pop();appendix=doc.name?"_"+doc.name:"";mergedDoc.file(fileName+appendix+"."+ext,file)}}catch(err){_iterator4.e(err)}finally{_iterator4.f()}_context5.next=5;return mergedDoc.generateAsync({type:"arraybuffer"});case 5:return _context5.abrupt("return",_context5.sent);case 6:case"end":return _context5.stop()}},_callee5,this)}));function collectOneZip(_x7,_x8){return _collectOneZip.apply(this,arguments)}return collectOneZip}()}])}(React.Component);_defineProperty(Print,"propTypes",{active:PropTypes.bool,addLayerFeatures:PropTypes.func,/** Whether to allow GeoPDF export. Requires QGIS Server 3.32 or newer. */allowGeoPdfExport:PropTypes.bool,clearLayer:PropTypes.func,/** The default print dpi. */defaultDpi:PropTypes.number,/** The factor to apply to the map scale to determine the initial print map scale. */defaultScaleFactor:PropTypes.number,/** Show an option to print a series of extents. */displayPrintSeries:PropTypes.bool,/** Whether to display the printing rotation control. */displayRotation:PropTypes.bool,/** Template for the name of the generated files when downloading. Can contain the placeholders `{layout}`, `{username}`, `{tenant}`, `{theme}`, `{themeTitle}`, `{timestamp}`. */fileNameTemplate:PropTypes.string,/** Export layout format mimetypes. If format is not supported by QGIS Server, print will fail. */formats:PropTypes.arrayOf(PropTypes.string),/** Whether the grid is enabled by default. */gridInitiallyEnabled:PropTypes.bool,/** Whether to hide form fields which contain autopopulated values (i.e. search result label). */hideAutopopulatedFields:PropTypes.bool,/** Whether to display the print output in an inline dialog instead triggering a download. */inlinePrintOutput:PropTypes.bool,layers:PropTypes.array,/** Hide layouts which begin with this prefix. */layoutHidePrefix:PropTypes.string,/** Layout sort order, asc or desc. */layoutSortOrder:PropTypes.string,map:PropTypes.object,/** Whether to print external layers. Requires QGIS Server 3.x! */printExternalLayers:PropTypes.bool,/** Whether to print highlights on the map, e.g. selected features or redlining. */printMapHighlights:PropTypes.bool,/** Scale factor to apply to line widths, font sizes, ... of redlining drawings passed to GetPrint. */scaleFactor: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(Print,"defaultProps",{defaultDpi:300,defaultScaleFactor:0.5,displayPrintSeries:false,displayRotation:true,fileNameTemplate:"{theme}_{timestamp}",gridInitiallyEnabled:false,layoutSortOrder:"asc",formats:["application/pdf","image/jpeg","image/png","image/svg"],inlinePrintOutput:false,printExternalLayers:true,printMapHighlights:true,scaleFactor:1.9,// Experimentally determined...
22
+ if(this.props.inlinePrintOutput&&files.length===1){file=files.pop();fileURL=URL.createObjectURL(file.content);this.setState({pdfData:file,pdfDataUrl:fileURL,outputLoaded:true})}else{_iterator=_createForOfIteratorHelper(files);try{for(_iterator.s();!(_step=_iterator.n()).done;){_file=_step.value;FileSaver.saveAs(_file.content,_file.fileName)}}catch(err){_iterator.e(err)}finally{_iterator.f()}}case 8:case"end":return _context.stop()}},_callee,this)}));function batchPrint(_x,_x2){return _batchPrint.apply(this,arguments)}return batchPrint}()},{key:"printRequest",value:function(){var _printRequest=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(formData){var data,config,response,contentType;return _regeneratorRuntime().wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:data=Object.entries(formData).map(function(pair){return pair.map(function(entry){return encodeURIComponent(entry).replace(/%20/g,"+")}).join("=")}).join("&");config={headers:{"Content-Type":"application/x-www-form-urlencoded"},responseType:"arraybuffer"};_context2.next=4;return axios.post(this.props.theme.printUrl,data,config);case 4:response=_context2.sent;contentType=response.headers["content-type"];return _context2.abrupt("return",{name:formData.name,data:response.data,contentType:contentType});case 7:case"end":return _context2.stop()}},_callee2,this)}));function printRequest(_x3){return _printRequest.apply(this,arguments)}return printRequest}()},{key:"collectFiles",value:function(){var _collectFiles=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(docs,fileName){var _this5=this;var data,content,_data,_content;return _regeneratorRuntime().wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:if(!(docs.length>1&&this.state.downloadMode==="onepdf")){_context3.next=6;break}_context3.next=3;return this.collectOnePdf(docs);case 3:data=_context3.sent;content=new Blob([data],{type:"application/pdf"});return _context3.abrupt("return",[{content:content,fileName:fileName+".pdf"}]);case 6:if(!(docs.length>1&&this.state.downloadMode==="onezip")){_context3.next=12;break}_context3.next=9;return this.collectOneZip(docs,fileName);case 9:_data=_context3.sent;_content=new Blob([_data],{type:"application/zip"});return _context3.abrupt("return",[{content:_content,fileName:fileName+".zip"}]);case 12:return _context3.abrupt("return",docs.map(function(doc){var content=new Blob([doc.data],{type:doc.contentType});var ext=_this5.state.selectedFormat.split(";")[0].split("/").pop();var appendix=doc.name?"_"+doc.name:"";return{content:content,fileName:fileName+appendix+"."+ext}}));case 13:case"end":return _context3.stop()}},_callee3,this)}));function collectFiles(_x4,_x5){return _collectFiles.apply(this,arguments)}return collectFiles}()},{key:"collectOnePdf",value:function(){var _collectOnePdf=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(docs){var _yield$import,PDFDocument,mergedDoc,_iterator2,_step2,doc,pdfBytes,copiedPages,_iterator3,_step3,page;return _regeneratorRuntime().wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:_context4.next=2;return import("pdf-lib");case 2:_yield$import=_context4.sent;PDFDocument=_yield$import.PDFDocument;_context4.next=6;return PDFDocument.create();case 6:mergedDoc=_context4.sent;_iterator2=_createForOfIteratorHelper(docs);_context4.prev=8;_iterator2.s();case 10:if((_step2=_iterator2.n()).done){_context4.next=22;break}doc=_step2.value;_context4.next=14;return PDFDocument.load(doc.data);case 14:pdfBytes=_context4.sent;_context4.next=17;return mergedDoc.copyPages(pdfBytes,pdfBytes.getPageIndices());case 17:copiedPages=_context4.sent;_iterator3=_createForOfIteratorHelper(copiedPages);try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){page=_step3.value;mergedDoc.addPage(page)}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}case 20:_context4.next=10;break;case 22:_context4.next=27;break;case 24:_context4.prev=24;_context4.t0=_context4["catch"](8);_iterator2.e(_context4.t0);case 27:_context4.prev=27;_iterator2.f();return _context4.finish(27);case 30:_context4.next=32;return mergedDoc.save();case 32:return _context4.abrupt("return",_context4.sent);case 33:case"end":return _context4.stop()}},_callee4,null,[[8,24,27,30]])}));function collectOnePdf(_x6){return _collectOnePdf.apply(this,arguments)}return collectOnePdf}()},{key:"collectOneZip",value:function(){var _collectOneZip=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(docs,fileName){var mergedDoc,_iterator4,_step4,doc,file,ext,appendix;return _regeneratorRuntime().wrap(function _callee5$(_context5){while(1)switch(_context5.prev=_context5.next){case 0:mergedDoc=new JSZip;_iterator4=_createForOfIteratorHelper(docs);try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){doc=_step4.value;file=new Blob([doc.data],{type:doc.contentType});ext=this.state.selectedFormat.split(";")[0].split("/").pop();appendix=doc.name?"_"+doc.name:"";mergedDoc.file(fileName+appendix+"."+ext,file)}}catch(err){_iterator4.e(err)}finally{_iterator4.f()}_context5.next=5;return mergedDoc.generateAsync({type:"arraybuffer"});case 5:return _context5.abrupt("return",_context5.sent);case 6:case"end":return _context5.stop()}},_callee5,this)}));function collectOneZip(_x7,_x8){return _collectOneZip.apply(this,arguments)}return collectOneZip}()}])}(React.Component);_defineProperty(Print,"propTypes",{active:PropTypes.bool,addLayerFeatures:PropTypes.func,/** Whether to allow GeoPDF export. Requires QGIS Server 3.32 or newer. */allowGeoPdfExport:PropTypes.bool,clearLayer:PropTypes.func,/** The default print dpi. */defaultDpi:PropTypes.number,/** The factor to apply to the map scale to determine the initial print map scale. */defaultScaleFactor:PropTypes.number,/** Show an option to print a series of extents. */displayPrintSeries:PropTypes.bool,/** Whether to display the printing rotation control. */displayRotation:PropTypes.bool,/** Template for the name of the generated files when downloading. Can contain the placeholders `{layout}`, `{username}`, `{tenant}`, `{theme}`, `{themeTitle}`, `{timestamp}`. */fileNameTemplate:PropTypes.string,/** Export layout format mimetypes. If format is not supported by QGIS Server, print will fail. */formats:PropTypes.arrayOf(PropTypes.string),/** Whether the grid is enabled by default. */gridInitiallyEnabled:PropTypes.bool,/** Whether to hide form fields which contain autopopulated values (i.e. search result label). */hideAutopopulatedFields:PropTypes.bool,/** Whether to display the print output in an inline dialog instead triggering a download. */inlinePrintOutput:PropTypes.bool,layers:PropTypes.array,/** Hide layouts which begin with this prefix. */layoutHidePrefix:PropTypes.string,/** Layout sort order, asc or desc. */layoutSortOrder:PropTypes.string,map:PropTypes.object,/** Whether to allow moving the extent while selecting the print series. */movePrintSeries:PropTypes.bool,/** Whether to print external layers. Requires QGIS Server 3.x! */printExternalLayers:PropTypes.bool,/** Whether to print highlights on the map, e.g. selected features or redlining. */printMapHighlights:PropTypes.bool,/** Scale factor to apply to line widths, font sizes, ... of redlining drawings passed to GetPrint. */scaleFactor: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(Print,"defaultProps",{defaultDpi:300,defaultScaleFactor:0.5,displayPrintSeries:false,displayRotation:true,fileNameTemplate:"{theme}_{timestamp}",gridInitiallyEnabled:false,layoutSortOrder:"asc",movePrintSeries:false,formats:["application/pdf","image/jpeg","image/png","image/svg"],inlinePrintOutput:false,printExternalLayers:true,printMapHighlights:true,scaleFactor:1.9,// Experimentally determined...
23
23
  side:"right"});var selector=function selector(state){return{active:state.task.id==="Print",theme:state.theme.current,map:state.map,layers:state.layers.flat}};export default connect(selector,{addLayerFeatures:addLayerFeatures,clearLayer:clearLayer,setSnappingConfig:setSnappingConfig})(Print);
@@ -12,4 +12,4 @@ _this.measureLayer=new ol.layer.Vector({source:new ol.source.Vector,zIndex:10000
12
12
  _this.drawInteraction=new ol.interaction.Draw({stopClick:true,source:_this.measureLayer.getSource(),condition:function condition(event){return event.originalEvent.buttons===1},type:geometryType,style:function style(){return _this.modifyInteraction?[]:FeatureStyles.sketchInteraction()}});_this.drawInteraction.on("drawstart",function(ev){_this.leaveTemporaryPickMode();_this.measureLayer.getSource().clear();_this.sketchFeature=ev.feature;_this.sketchFeature.setStyle(_this.featureStyleFunction);_this.sketchFeature.on("change",function(evt){return _this.updateMeasurementResults(evt.target)})});_this.drawInteraction.on("drawend",function(){_this.updateMeasurementResults(_this.sketchFeature,false);_this.enterTemporaryPickMode()});_this.props.map.addInteraction(_this.drawInteraction)});_defineProperty(_this,"reset",function(){if(_this.drawInteraction!==null){_this.props.map.removeInteraction(_this.drawInteraction);_this.drawInteraction=null;_this.leaveTemporaryPickMode();_this.props.map.removeLayer(_this.measureLayer);_this.measureLayer=null;_this.sketchFeature=null}});_defineProperty(_this,"enterTemporaryPickMode",function(){_this.modifyInteraction=new ol.interaction.Modify({features:new ol.Collection([_this.sketchFeature]),condition:function condition(event){return event.originalEvent.buttons===1},insertVertexCondition:function insertVertexCondition(){return _this.props.measurement.geomType==="Bearing"?false:true},deleteCondition:function deleteCondition(event){return ol.events.condition.shiftKeyOnly(event)&&ol.events.condition.singleClick(event)},style:function style(feature){// Hack to get cursor position over geometry...
13
13
  if(_this.props.measurement.pickPositionCallback){clearTimeout(_this.pickPositionCallbackTimeout);_this.props.measurement.pickPositionCallback(feature.getGeometry().getCoordinates())}return FeatureStyles.sketchInteraction()}});_this.props.map.on("pointermove",_this.clearPickPosition);_this.modifyInteraction.on("modifyend",function(){_this.updateMeasurementResults(_this.sketchFeature,false)});_this.props.map.addInteraction(_this.modifyInteraction)});_defineProperty(_this,"leaveTemporaryPickMode",function(){if(_this.modifyInteraction){_this.props.map.un("pointermove",_this.clearPickPosition);_this.props.map.removeInteraction(_this.modifyInteraction);_this.modifyInteraction=null}});_defineProperty(_this,"clearPickPosition",function(){if(_this.props.measurement.pickPositionCallback){clearTimeout(_this.pickPositionCallbackTimeout);// Works because style function clears timeout if marker is rendered, i.e. if mouse is over measure geometry
14
14
  _this.pickPositionCallbackTimeout=setTimeout(function(){if(_this.props.measurement.pickPositionCallback){_this.props.measurement.pickPositionCallback(null)}},50)}});_defineProperty(_this,"updateMeasurementResults",function(feature){var drawing=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var geomType=_this.props.measurement.geomType;var settings={lenUnit:_this.props.measurement.lenUnit,areaUnit:_this.props.measurement.areaUnit,displayCrs:_this.props.displayCrs};MeasureUtils.updateFeatureMeasurements(feature,geomType,_this.props.projection,settings);// Only one segment for bearing measurement
15
- if(geomType==="Bearing"&&feature.getGeometry().getCoordinates().length>2){_this.drawInteraction.finishDrawing()}_this.measureLayer.getSource().changed();_this.props.changeMeasurementState(_objectSpread({geomType:_this.props.measurement.geomType,drawing:drawing,coordinates:feature.getGeometry().getCoordinates()},structuredClone(feature.get("measurements"))))});_defineProperty(_this,"featureStyleFunction",function(feature){var geometryFunction=function geometryFunction(f){if(f.getGeometry().getType()==="Point"){return new ol.geom.MultiPoint([f.getGeometry().getCoordinates()])}else if(f.getGeometry().getType()==="LineString"){return new ol.geom.MultiPoint(f.getGeometry().getCoordinates())}return new ol.geom.MultiPoint(f.getGeometry().getCoordinates()[0])};return[].concat(_toConsumableArray(FeatureStyles.measureInteraction(feature)),[FeatureStyles.measureInteractionVertex({geometryFunction:geometryFunction})])});_this.pickPositionCallbackTimeout=null;_this.measureLayer=null;return _this}_inherits(MeasurementSupport,_React$Component);return _createClass(MeasurementSupport,[{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){if(this.props.measurement.geomType&&this.props.measurement.geomType!==prevProps.measurement.geomType){this.addDrawInteraction(this.props)}else if(!this.props.measurement.geomType){this.reset()}else if(this.sketchFeature&&(this.props.measurement.lenUnit!==prevProps.measurement.lenUnit||this.props.measurement.areaUnit!==prevProps.measurement.areaUnit||this.props.displayCrs!==prevProps.displayCrs)){this.updateMeasurementResults(this.sketchFeature,this.props.measurement.drawing)}}},{key:"render",value:function render(){return null}}])}(React.Component);_defineProperty(MeasurementSupport,"propTypes",{changeMeasurementState:PropTypes.func,displayCrs:PropTypes.string,map:PropTypes.object,measurement:PropTypes.object,projection:PropTypes.string});export default connect(function(state){return{displayCrs:state.map.displayCrs,measurement:state.measurement}},{changeMeasurementState:changeMeasurementState})(MeasurementSupport);
15
+ if(geomType==="Bearing"&&feature.getGeometry().getCoordinates().length>2){_this.drawInteraction.finishDrawing()}_this.measureLayer.getSource().changed();_this.props.changeMeasurementState(_objectSpread({geomType:_this.props.measurement.geomType,drawing:drawing,coordinates:feature.getGeometry().getCoordinates()},structuredClone(feature.get("measurements"))))});_defineProperty(_this,"featureStyleFunction",function(feature){var geometryFunction=function geometryFunction(f){if(f.getGeometry().getType()==="Point"){return new ol.geom.MultiPoint([f.getGeometry().getCoordinates()])}else if(f.getGeometry().getType()==="LineString"){return new ol.geom.MultiPoint(f.getGeometry().getCoordinates())}return new ol.geom.MultiPoint(f.getGeometry().getCoordinates()[0])};var opts={};if(_this.props.measurement.geomType==="LineString"){opts.headmarker=_this.props.measurement.lineHeadMarker;opts.tailmarker=_this.props.measurement.lineHeadMarker}else if(_this.props.measurement.geomType==="Bearing"){opts.headmarker=_this.props.measurement.bearingHeadMarker;opts.tailmarker=_this.props.measurement.bearingHeadMarker}return[].concat(_toConsumableArray(FeatureStyles.measureInteraction(feature,opts)),[FeatureStyles.measureInteractionVertex({geometryFunction:geometryFunction})])});_this.pickPositionCallbackTimeout=null;_this.measureLayer=null;return _this}_inherits(MeasurementSupport,_React$Component);return _createClass(MeasurementSupport,[{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){if(this.props.measurement.geomType&&this.props.measurement.geomType!==prevProps.measurement.geomType){this.addDrawInteraction(this.props)}else if(!this.props.measurement.geomType){this.reset()}else if(this.sketchFeature&&(this.props.measurement.lenUnit!==prevProps.measurement.lenUnit||this.props.measurement.areaUnit!==prevProps.measurement.areaUnit||this.props.displayCrs!==prevProps.displayCrs)){this.updateMeasurementResults(this.sketchFeature,this.props.measurement.drawing)}}},{key:"render",value:function render(){return null}}])}(React.Component);_defineProperty(MeasurementSupport,"propTypes",{changeMeasurementState:PropTypes.func,displayCrs:PropTypes.string,map:PropTypes.object,measurement:PropTypes.object,projection:PropTypes.string});export default connect(function(state){return{displayCrs:state.map.displayCrs,measurement:state.measurement}},{changeMeasurementState:changeMeasurementState})(MeasurementSupport);
@@ -5,4 +5,4 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
5
5
  * This source code is licensed under the BSD-style license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */import React from"react";import{connect}from"react-redux";import PropTypes from"prop-types";import{v4 as uuidv4}from"uuid";import{LayerRole,addLayer,addLayerFeatures}from"../../actions/layers";import NumberInput from"../../components/widgets/NumberInput";import VectorLayerPicker from"../../components/widgets/VectorLayerPicker";import LocaleUtils from"../../utils/LocaleUtils";import VectorLayerUtils from"../../utils/VectorLayerUtils";var RedliningBufferSupport=/*#__PURE__*/function(_React$Component){function RedliningBufferSupport(props){var _this;_classCallCheck(this,RedliningBufferSupport);_this=_callSuper(this,RedliningBufferSupport,[props]);_defineProperty(_this,"state",{bufferDistance:0,bufferLayer:null,bufferUnit:"meters"});_defineProperty(_this,"changeBufferUnit",function(ev){_this.setState({bufferUnit:ev.target.value})});_defineProperty(_this,"computeBuffer",function(){var feature=_this.props.redlining.selectedFeature;if(!feature||!feature.geometry||!_this.state.bufferLayer){return}import("@turf/buffer").then(function(bufferMod){var buffer=bufferMod["default"];if(feature.circleParams){var _feature$circleParams=feature.circleParams,center=_feature$circleParams.center,radius=_feature$circleParams.radius;var deg2rad=Math.PI/180;feature=_objectSpread(_objectSpread({},feature),{},{geometry:{type:"Polygon",coordinates:[Array.apply(null,Array(91)).map(function(item,index){return[center[0]+radius*Math.cos(4*index*deg2rad),center[1]+radius*Math.sin(4*index*deg2rad)]})]}})}var wgsGeometry=VectorLayerUtils.reprojectGeometry(feature.geometry,_this.props.projection,"EPSG:4326");var wgsFeature=_objectSpread(_objectSpread({},feature),{},{geometry:wgsGeometry});var output=buffer(wgsFeature,_this.state.bufferDistance,{units:_this.state.bufferUnit});if(output&&output.geometry){output.geometry=VectorLayerUtils.reprojectGeometry(output.geometry,"EPSG:4326",_this.props.projection);output.id=uuidv4();output.styleName="default";output.styleOptions={fillColor:[0,0,255,0.5],strokeColor:[0,0,255,1]};_this.props.addLayerFeatures(_this.state.bufferLayer,[output])}})});_this.state.bufferLayer={id:"buffer",title:LocaleUtils.tr("redlining.bufferlayername"),role:LayerRole.USERLAYER};return _this}_inherits(RedliningBufferSupport,_React$Component);return _createClass(RedliningBufferSupport,[{key:"componentDidUpdate",value:function componentDidUpdate(){var _this2=this;if(this.state.bufferLayer&&this.state.bufferLayer.id!=="buffer"&&!this.props.layers.find(function(layer){return layer.id===_this2.state.bufferLayer.id})){this.setState({bufferLayer:{id:"buffer",title:LocaleUtils.tr("redlining.bufferlayername"),role:LayerRole.USERLAYER}})}}},{key:"render",value:function render(){var _this3=this;if(!this.props.redlining.selectedFeature){return/*#__PURE__*/React.createElement("div",{className:"redlining-message"},LocaleUtils.tr("redlining.bufferselectfeature"))}var enabled=this.state.bufferDistance!==0;var layers=this.props.layers.filter(function(layer){return layer.type==="vector"&&layer.role===LayerRole.USERLAYER});// Ensure list contains current target layer
8
- if(!layers.find(function(layer){return layer.id===_this3.state.bufferLayer.id})){layers=[this.state.bufferLayer].concat(_toConsumableArray(layers))}return/*#__PURE__*/React.createElement("div",{className:"redlining-controlsbar"},/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("redlining.bufferdistance")," \xA0"),/*#__PURE__*/React.createElement(NumberInput,{max:99999,min:-99999,mobile:true,onChange:function onChange(nr){return _this3.setState({bufferDistance:nr})},value:this.state.bufferDistance}),/*#__PURE__*/React.createElement("select",{onChange:this.changeBufferUnit,value:this.state.bufferUnit},/*#__PURE__*/React.createElement("option",{value:"meters"},"m"),/*#__PURE__*/React.createElement("option",{value:"feet"},"ft"),/*#__PURE__*/React.createElement("option",{value:"kilometers"},"km"),/*#__PURE__*/React.createElement("option",{value:"miles"},"mi"))),/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("redlining.bufferlayer"),":\xA0"),/*#__PURE__*/React.createElement(VectorLayerPicker,{addLayer:this.props.addLayer,layers:layers,onChange:function onChange(layer){return _this3.setState({bufferLayer:layer})},value:this.state.bufferLayer.id})),/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement("button",{className:"button",disabled:!enabled,onClick:this.computeBuffer},LocaleUtils.tr("redlining.buffercompute"))))}}])}(React.Component);_defineProperty(RedliningBufferSupport,"propTypes",{addLayer:PropTypes.func,addLayerFeatures:PropTypes.func,layers:PropTypes.array,projection:PropTypes.string,redlining:PropTypes.object});export default{cfg:{key:"Buffer",tooltip:LocaleUtils.trmsg("redlining.buffer"),icon:"buffer",data:{action:"Buffer",geomType:null}},controls:connect(function(state){return{projection:state.map.projection,layers:state.layers.flat,redlining:state.redlining}},{addLayerFeatures:addLayerFeatures,addLayer:addLayer})(RedliningBufferSupport)};
8
+ if(!layers.find(function(layer){return layer.id===_this3.state.bufferLayer.id})){layers=[this.state.bufferLayer].concat(_toConsumableArray(layers))}return/*#__PURE__*/React.createElement("div",{className:"redlining-controlsbar"},/*#__PURE__*/React.createElement("div",{className:"redlining-control"},/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("redlining.bufferdistance")," \xA0"),/*#__PURE__*/React.createElement(NumberInput,{max:99999,min:-99999,mobile:true,onChange:function onChange(nr){return _this3.setState({bufferDistance:nr})},value:this.state.bufferDistance}),/*#__PURE__*/React.createElement("select",{onChange:this.changeBufferUnit,value:this.state.bufferUnit},/*#__PURE__*/React.createElement("option",{value:"meters"},"m"),/*#__PURE__*/React.createElement("option",{value:"feet"},"ft"),/*#__PURE__*/React.createElement("option",{value:"kilometers"},"km"),/*#__PURE__*/React.createElement("option",{value:"miles"},"mi"))),/*#__PURE__*/React.createElement("div",{className:"redlining-control"},/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("redlining.bufferlayer"),":\xA0"),/*#__PURE__*/React.createElement(VectorLayerPicker,{addLayer:this.props.addLayer,layers:layers,onChange:function onChange(layer){return _this3.setState({bufferLayer:layer})},value:this.state.bufferLayer.id})),/*#__PURE__*/React.createElement("div",{className:"redlining-control"},/*#__PURE__*/React.createElement("button",{className:"button",disabled:!enabled,onClick:this.computeBuffer},LocaleUtils.tr("redlining.buffercompute"))))}}])}(React.Component);_defineProperty(RedliningBufferSupport,"propTypes",{addLayer:PropTypes.func,addLayerFeatures:PropTypes.func,layers:PropTypes.array,projection:PropTypes.string,redlining:PropTypes.object});export default{cfg:{key:"Buffer",tooltip:LocaleUtils.trmsg("redlining.buffer"),icon:"buffer",data:{action:"Buffer",geomType:null}},controls:connect(function(state){return{projection:state.map.projection,layers:state.layers.flat,redlining:state.redlining}},{addLayerFeatures:addLayerFeatures,addLayer:addLayer})(RedliningBufferSupport)};
@@ -5,4 +5,4 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
5
5
  *
6
6
  * This source code is licensed under the BSD-style license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
- */import{CHANGE_MEASUREMENT_STATE}from"../actions/measurement";var defaultState={geomType:null,coordinates:null,length:null,area:0,bearing:0,lenUnit:"metric",areaUnit:"metric"};export default function measurement(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case CHANGE_MEASUREMENT_STATE:{return _objectSpread({lenUnit:state.lenUnit,areaUnit:state.areaUnit},action.data)}default:return state}}
8
+ */import{CHANGE_MEASUREMENT_STATE}from"../actions/measurement";var defaultState={geomType:null,coordinates:null,length:null,area:0,bearing:0,lenUnit:"metric",areaUnit:"metric",bearingHeadMarker:null,bearingTailMarker:null,lineHeadMarker:null,lineTailMarker:null};export default function measurement(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case CHANGE_MEASUREMENT_STATE:{return _objectSpread({lenUnit:state.lenUnit,areaUnit:state.areaUnit,bearingHeadMarker:state.bearingHeadMarker,bearingTailMarker:state.bearingTailMarker,lineHeadMarker:state.lineHeadMarker,lineTailMarker:state.lineTailMarker},action.data)}default:return state}}
@@ -7,4 +7,4 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
7
7
  */import ol from"openlayers";import minus from"../icons/minus.svg";import plus from"../icons/plus.svg";import ConfigUtils from"./ConfigUtils";import ResourceRegistry from"./ResourceRegistry";import arrowhead from"./img/arrowhead.svg";import markerIcon from"./img/marker-icon.png";import measurehead from"./img/measurehead.svg";ResourceRegistry.addResource("arrowhead",arrowhead);ResourceRegistry.addResource("measurehead",measurehead);ResourceRegistry.addResource("marker",markerIcon);ResourceRegistry.addResource("minus",minus);ResourceRegistry.addResource("plus",plus);var DEFAULT_FEATURE_STYLE={strokeColor:[0,0,255,1],strokeWidth:1,strokeDash:[4],fillColor:[255,0,255,0.33],circleRadius:10,textFill:"black",textStroke:"white",textFont:"11pt sans-serif"};var DEFAULT_MARKER_STYLE={iconAnchor:[0.5,1],opacity:1,iconSrc:markerIcon,color:undefined,scale:undefined,crossOrigin:undefined,textColor:"#000000",textStroke:"#FFFFFF"};var DEFAULT_INTERACTION_STYLE={fillColor:[255,0,0,0.5],strokeColor:"red",strokeWidth:1.5,vertexFillColor:"white",vertexStrokeColor:"red",snapFillColor:[255,255,255,0.05],snapStrokeColor:"#3399CC",snapStrokeWidth:1,snapVertexFillColor:[255,255,255,0.05],snapVertexStrokeColor:"#3399CC",measureFillColor:[255,0,0,0.25],measureStrokeColor:"red",measureStrokeWidth:4,measureVertexFillColor:"white",measureVertexStrokeColor:"red",measureVertexStrokeWidth:2,measurePointRadius:6,sketchPointFillColor:"#0099FF",sketchPointStrokeColor:"white",sketchPointRadius:6,printStrokeColor:"#3399CC",printStrokeWidth:3,printVertexColor:"#FFFFFF",printVertexRadius:6,printBackgroundColor:[0,0,0,0.5]};export var END_MARKERS={OUTARROW:{src:arrowhead,anchor:[0.05,0.5],baserotation:0},INARROW:{src:arrowhead,anchor:[0.05,0.5],baserotation:180},LINE:{src:measurehead,anchor:[0.05,0.5],baserotation:0}};export function computeFeatureStyle(layer,feature){return _objectSpread(_objectSpread(_objectSpread(_objectSpread({},DEFAULT_FEATURE_STYLE),ConfigUtils.getConfigProp("defaultFeatureStyle")),layer.styleOptions),feature.styleOptions)}var defaultStyle=function defaultStyle(feature,options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_FEATURE_STYLE),ConfigUtils.getConfigProp("defaultFeatureStyle")),options);var styles=[];styles.push(new ol.style.Style({fill:new ol.style.Fill({color:opts.fillColor}),stroke:new ol.style.Stroke({color:opts.strokeColor,width:opts.strokeWidth,lineDash:opts.strokeDash}),image:opts.circleRadius>0?new ol.style.Circle({radius:opts.circleRadius,fill:new ol.style.Fill({color:opts.fillColor}),stroke:new ol.style.Stroke({color:opts.strokeColor,width:opts.strokeWidth})}):null}));if(feature.getProperties().label){styles.push(new ol.style.Style({geometry:function geometry(f){if(f.getGeometry().getType().startsWith("Multi")){// Only label middle point
8
8
  var extent=f.getGeometry().getExtent();return new ol.geom.Point(f.getGeometry().getClosestPoint(ol.extent.getCenter(extent)))}return f.getGeometry()},text:new ol.style.Text({font:opts.textFont||"11pt sans-serif",text:feature.getProperties().label||"",overflow:true,fill:new ol.style.Fill({color:opts.textFill}),stroke:new ol.style.Stroke({color:opts.textStroke,width:3}),textAlign:feature.getGeometry().getType()==="Point"?"left":"center",textBaseline:feature.getGeometry().getType()==="Point"?"bottom":"middle",offsetX:feature.getGeometry().getType()==="Point"?5+opts.circleRadius:0})}))}if(feature.getProperties().segment_labels){var segmentLabels=feature.getProperties().segment_labels;var coo=feature.getGeometry().getCoordinates();for(var i=0;i<coo.length-1;++i){var p1=coo[i];var p2=coo[i+1];var angle=-Math.atan2(p2[1]-p1[1],p2[0]-p1[0]);while(angle<-0.5*Math.PI){angle+=Math.PI}while(angle>0.5*Math.PI){angle-=Math.PI}styles.push(new ol.style.Style({geometry:new ol.geom.Point([0.5*(p1[0]+p2[0]),0.5*(p1[1]+p2[1])]),text:new ol.style.Text({font:opts.textFont||"11pt sans-serif",text:segmentLabels[i],fill:new ol.style.Fill({color:opts.textFill}),stroke:new ol.style.Stroke({color:opts.textStroke,width:3}),rotation:angle,offsetY:10})}))}}if(feature.getGeometry().getType()==="LineString"&&opts.headmarker in END_MARKERS){var _p=feature.getGeometry().getCoordinates()[0];var _p2=feature.getGeometry().getCoordinates()[1];var rotation=0.5*Math.PI+Math.atan2(_p[0]-_p2[0],_p[1]-_p2[1]);styles.push(new ol.style.Style({geometry:new ol.geom.Point(_p),image:new ol.style.Icon(_objectSpread(_objectSpread({},END_MARKERS[opts.headmarker]),{},{anchorXUnits:"fraction",anchorYUnits:"fraction",color:opts.strokeColor,rotation:END_MARKERS[opts.headmarker].baserotation/180*Math.PI+rotation,scale:0.125*(1+opts.strokeWidth)// Also update in VectorLayerUtils.generateMarkerGeometry
9
9
  }))}))}if(feature.getGeometry().getType()==="LineString"&&opts.tailmarker in END_MARKERS){var l=feature.getGeometry().getCoordinates().length;var _p3=feature.getGeometry().getCoordinates()[l-1];var _p4=feature.getGeometry().getCoordinates()[l-2];var _rotation=0.5*Math.PI+Math.atan2(_p3[0]-_p4[0],_p3[1]-_p4[1]);styles.push(new ol.style.Style({geometry:new ol.geom.Point(_p3),image:new ol.style.Icon(_objectSpread(_objectSpread({},END_MARKERS[opts.tailmarker]),{},{anchorXUnits:"fraction",anchorYUnits:"fraction",color:opts.strokeColor,rotation:END_MARKERS[opts.tailmarker].baserotation/180*Math.PI+_rotation,scale:0.125*(1+opts.strokeWidth)// Also update in VectorLayerUtils.generateMarkerGeometry
10
- }))}))}return styles};export default{"default":defaultStyle,marker:function marker(feature,options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_MARKER_STYLE),ConfigUtils.getConfigProp("defaultMarkerStyle")),options);return[new ol.style.Style({image:new ol.style.Icon({anchor:opts.iconAnchor,anchorXUnits:"fraction",anchorYUnits:"fraction",opacity:opts.opacity,crossOrigin:opts.crossOrigin,src:opts.iconSrc,scale:opts.scale,color:opts.color}),text:new ol.style.Text({font:opts.textFont||"11pt sans-serif",text:feature.getProperties().label||"",offsetY:8,fill:new ol.style.Fill({color:opts.textColor}),stroke:new ol.style.Stroke({color:opts.textStroke,width:3})})})]},interaction:function interaction(options,isSnap){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);var fillColor=opts.fillColor;var strokeColor=opts.strokeColor;var strokeWidth=opts.strokeWidth;if(isSnap){fillColor=opts.snapFillColor;strokeColor=opts.snapStrokeColor;strokeWidth=opts.snapStrokeWidth}return new ol.style.Style({fill:new ol.style.Fill({color:fillColor}),stroke:new ol.style.Stroke({color:strokeColor,width:strokeWidth})})},interactionVertex:function interactionVertex(options,isSnap){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);var strokeWidth=opts.strokeWidth;var vertexFill=opts.vertexFillColor;var vertexStroke=opts.vertexStrokeColor;if(isSnap){strokeWidth=opts.snapStrokeWidth;vertexFill=opts.snapVertexFillColor;vertexStroke=opts.snapVertexStrokeColor}return new ol.style.Style({image:options.img?new ol.style.Icon({src:ResourceRegistry.getResource(options.img),rotation:options.rotation,anchor:[0.5,1],imgSize:options.size,rotateWithView:true}):new ol.style.RegularShape({fill:new ol.style.Fill({color:vertexFill}),stroke:new ol.style.Stroke({color:vertexStroke,width:strokeWidth}),points:4,radius:5,angle:Math.PI/4}),geometry:opts.geometryFunction})},measureInteraction:function measureInteraction(feature,options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);var styleOptions={strokeColor:opts.measureStrokeColor,strokeWidth:opts.measureStrokeWidth,fillColor:opts.measureFillColor,strokeDash:[]};return defaultStyle(feature,styleOptions)},measureInteractionVertex:function measureInteractionVertex(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({image:new ol.style.Circle({radius:opts.measurePointRadius,fill:new ol.style.Fill({color:opts.measureVertexFillColor}),stroke:new ol.style.Stroke({color:opts.measureVertexStrokeColor,width:opts.measureVertexStrokeWidth})}),geometry:opts.geometryFunction})},sketchInteraction:function sketchInteraction(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({image:new ol.style.Circle({fill:new ol.style.Fill({color:opts.sketchPointFillColor}),stroke:new ol.style.Stroke({color:opts.sketchPointStrokeColor,width:opts.strokeWidth}),radius:opts.sketchPointRadius})})},printInteraction:function printInteraction(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({geometry:opts.geometryFunction,fill:new ol.style.Fill({color:[0,0,0,0]}),stroke:new ol.style.Stroke({color:opts.printStrokeColor,width:opts.printStrokeWidth})})},printInteractionVertex:function printInteractionVertex(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({geometry:opts.geometryFunction,image:new ol.style.Circle({radius:opts.printVertexRadius,fill:new ol.style.Fill({color:opts.fill?opts.printStrokeColor:opts.printVertexColor}),stroke:new ol.style.Stroke({color:opts.printStrokeColor,width:opts.printStrokeWidth})})})},printInteractionBackground:function printInteractionBackground(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({geometry:opts.geometryFunction,fill:new ol.style.Fill({color:opts.printBackgroundColor})})},printInteractionSeries:function printInteractionSeries(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({geometry:opts.geometryFunction,stroke:new ol.style.Stroke({color:opts.printStrokeColor,width:opts.printStrokeWidth})})},printInteractionSeriesIcon:function printInteractionSeriesIcon(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return[new ol.style.Style({geometry:opts.geometryFunction,image:new ol.style.Circle({radius:20*opts.radius,fill:new ol.style.Fill({color:opts.printVertexColor}),stroke:new ol.style.Stroke({color:opts.printStrokeColor,width:opts.printStrokeWidth})})}),new ol.style.Style({geometry:opts.geometryFunction,image:new ol.style.Icon({src:ResourceRegistry.getResource(opts.img),opacity:0.5,rotation:opts.rotation,scale:opts.radius,rotateWithView:true})})]},image:function image(feature,options){return new ol.style.Style({image:new ol.style.Icon({src:ResourceRegistry.getResource(options.img),rotation:options.rotation,anchor:options.anchor,imgSize:options.size,rotateWithView:true})})},text:function text(feature,options){return[new ol.style.Style({text:new ol.style.Text({font:"10pt sans-serif",text:feature.getProperties().label||"",rotation:feature.getProperties().rotation||0,scale:options.strokeWidth,fill:new ol.style.Fill({color:options.fillColor}),stroke:new ol.style.Stroke({color:options.strokeColor,width:2})})})]}};
10
+ }))}))}return styles};export default{"default":defaultStyle,marker:function marker(feature,options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_MARKER_STYLE),ConfigUtils.getConfigProp("defaultMarkerStyle")),options);return[new ol.style.Style({image:new ol.style.Icon({anchor:opts.iconAnchor,anchorXUnits:"fraction",anchorYUnits:"fraction",opacity:opts.opacity,crossOrigin:opts.crossOrigin,src:opts.iconSrc,scale:opts.scale,color:opts.color}),text:new ol.style.Text({font:opts.textFont||"11pt sans-serif",text:feature.getProperties().label||"",offsetY:8,fill:new ol.style.Fill({color:opts.textColor}),stroke:new ol.style.Stroke({color:opts.textStroke,width:3})})})]},interaction:function interaction(options,isSnap){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);var fillColor=opts.fillColor;var strokeColor=opts.strokeColor;var strokeWidth=opts.strokeWidth;if(isSnap){fillColor=opts.snapFillColor;strokeColor=opts.snapStrokeColor;strokeWidth=opts.snapStrokeWidth}return new ol.style.Style({fill:new ol.style.Fill({color:fillColor}),stroke:new ol.style.Stroke({color:strokeColor,width:strokeWidth})})},interactionVertex:function interactionVertex(options,isSnap){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);var strokeWidth=opts.strokeWidth;var vertexFill=opts.vertexFillColor;var vertexStroke=opts.vertexStrokeColor;if(isSnap){strokeWidth=opts.snapStrokeWidth;vertexFill=opts.snapVertexFillColor;vertexStroke=opts.snapVertexStrokeColor}return new ol.style.Style({image:options.img?new ol.style.Icon({src:ResourceRegistry.getResource(options.img),rotation:options.rotation,anchor:[0.5,1],imgSize:options.size,rotateWithView:true}):new ol.style.RegularShape({fill:new ol.style.Fill({color:vertexFill}),stroke:new ol.style.Stroke({color:vertexStroke,width:strokeWidth}),points:4,radius:5,angle:Math.PI/4}),geometry:opts.geometryFunction})},measureInteraction:function measureInteraction(feature,options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);var styleOptions={strokeColor:opts.measureStrokeColor,strokeWidth:opts.measureStrokeWidth,fillColor:opts.measureFillColor,headmarker:opts.headmarker,tailmarker:opts.tailmarker,strokeDash:[]};return defaultStyle(feature,styleOptions)},measureInteractionVertex:function measureInteractionVertex(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({image:new ol.style.Circle({radius:opts.measurePointRadius,fill:new ol.style.Fill({color:opts.measureVertexFillColor}),stroke:new ol.style.Stroke({color:opts.measureVertexStrokeColor,width:opts.measureVertexStrokeWidth})}),geometry:opts.geometryFunction})},sketchInteraction:function sketchInteraction(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({image:new ol.style.Circle({fill:new ol.style.Fill({color:opts.sketchPointFillColor}),stroke:new ol.style.Stroke({color:opts.sketchPointStrokeColor,width:opts.strokeWidth}),radius:opts.sketchPointRadius})})},printInteraction:function printInteraction(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({geometry:opts.geometryFunction,fill:new ol.style.Fill({color:[0,0,0,0]}),stroke:new ol.style.Stroke({color:opts.printStrokeColor,width:opts.printStrokeWidth})})},printInteractionVertex:function printInteractionVertex(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({geometry:opts.geometryFunction,image:new ol.style.Circle({radius:opts.printVertexRadius,fill:new ol.style.Fill({color:opts.fill?opts.printStrokeColor:opts.printVertexColor}),stroke:new ol.style.Stroke({color:opts.printStrokeColor,width:opts.printStrokeWidth})})})},printInteractionBackground:function printInteractionBackground(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({geometry:opts.geometryFunction,fill:new ol.style.Fill({color:opts.printBackgroundColor})})},printInteractionSeries:function printInteractionSeries(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return new ol.style.Style({geometry:opts.geometryFunction,stroke:new ol.style.Stroke({color:opts.printStrokeColor,width:opts.printStrokeWidth})})},printInteractionSeriesIcon:function printInteractionSeriesIcon(options){var opts=_objectSpread(_objectSpread(_objectSpread({},DEFAULT_INTERACTION_STYLE),ConfigUtils.getConfigProp("defaultInteractionStyle")),options);return[new ol.style.Style({geometry:opts.geometryFunction,image:new ol.style.Circle({radius:20*opts.radius,fill:new ol.style.Fill({color:opts.printVertexColor}),stroke:new ol.style.Stroke({color:opts.printStrokeColor,width:opts.printStrokeWidth})})}),new ol.style.Style({geometry:opts.geometryFunction,image:new ol.style.Icon({src:ResourceRegistry.getResource(opts.img),opacity:0.5,rotation:opts.rotation,scale:opts.radius,rotateWithView:true})})]},image:function image(feature,options){return new ol.style.Style({image:new ol.style.Icon({src:ResourceRegistry.getResource(options.img),rotation:options.rotation,anchor:options.anchor,imgSize:options.size,rotateWithView:true})})},text:function text(feature,options){return[new ol.style.Style({text:new ol.style.Text({font:"10pt sans-serif",text:feature.getProperties().label||"",rotation:feature.getProperties().rotation||0,scale:options.strokeWidth,fill:new ol.style.Fill({color:options.fillColor}),stroke:new ol.style.Stroke({color:options.strokeColor,width:2})})})]}};
@@ -30,9 +30,7 @@ var fglayers=layers.filter(function(layer){return layer.role!==LayerRole.BACKGRO
30
30
  var exploded=LayerUtils.explodeLayers(fglayers);// Find entry to move
31
31
  if(movelayer){var indices=exploded.reduce(function(result,entry,index){if(entry.layer.id===movelayer.id&&LayerUtils.pathEqualOrBelow(sublayerpath,entry.path)){return[].concat(_toConsumableArray(result),[index])}return result},[]);if(isEmpty(indices)){return layers}indices.sort(function(a,b){return a-b});if(delta<0&&indices[0]<=0||delta>0&&indices[indices.length-1]>=exploded.length-1){return layers}if(preventSplittingGroups){// Prevent moving an entry out of a containing group
32
32
  var idx=delta<0?indices[0]:indices[indices.length-1];var level=sublayerpath.length;if(level>exploded[idx+delta].path.length||level>0&&!isEqual(exploded[idx+delta].path.slice(0,level-1),sublayerpath.slice(0,-1))){return layers}// Avoid splitting sibling groups when reordering
33
- if(exploded[idx+delta].path.length>level||!isEqual(exploded[idx+delta].path.slice(0,-1),sublayerpath.slice(0,-1))){// Find next slot
34
- var siblinggrouppath=exploded[idx+delta].path.slice(0,level);siblinggrouppath[siblinggrouppath.length-1]+=delta;while(idx+delta>=0&&idx+delta<exploded.length&&(exploded[idx+delta].path.length>level||!isEqual(exploded[idx+delta].path.slice(0,level),siblinggrouppath))){delta+=delta>0?1:-1}// The above logic adds the number of items to skip to the delta which is already -1 or +1, so we need to decrease delta by one accordingly
35
- if(Math.abs(delta)>1){delta+=delta>0?-1:1}if(idx+delta<0||idx+delta>=exploded.length){return layers}}}// Reorder layer
33
+ var siblinggrouppath=exploded[idx+delta].path.length>level?exploded[idx+delta].path.slice(0,level):null;if(siblinggrouppath!==null){var dir=delta>0?1:-1;while(idx+delta+dir>=0&&idx+delta+dir<exploded.length&&LayerUtils.pathEqualOrBelow(siblinggrouppath,exploded[idx+delta+dir].path)){delta+=dir}}}// Reorder layer
36
34
  if(delta<0){var _iterator7=_createForOfIteratorHelper(indices),_step7;try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){var _idx=_step7.value;exploded.splice(_idx+delta,0,exploded.splice(_idx,1)[0])}}catch(err){_iterator7.e(err)}finally{_iterator7.f()}}else{var _iterator8=_createForOfIteratorHelper(indices.reverse()),_step8;try{for(_iterator8.s();!(_step8=_iterator8.n()).done;){var _idx2=_step8.value;exploded.splice(_idx2+delta,0,exploded.splice(_idx2,1)[0])}}catch(err){_iterator8.e(err)}finally{_iterator8.f()}}}// Re-assemble layers
37
35
  var newlayers=LayerUtils.implodeLayers(exploded);// Re-add background layers
38
36
  return[].concat(_toConsumableArray(newlayers),_toConsumableArray(layers.filter(function(layer){return layer.role===LayerRole.BACKGROUND})))},replacePlaceholderLayer:function replacePlaceholderLayer(layers,layerid,newlayer){var filter=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{};var newLayers=layers;if(newlayer){newLayers=layers.map(function(layer){if(layer.type==="placeholder"&&layer.id===layerid){var _layer$attribution,_layer$opacity2,_layer$visibility,_layer$tristate,_layer$style2;var newLayer=_objectSpread(_objectSpread(_objectSpread({},layer),newlayer),{},{attribution:(_layer$attribution=layer.attribution)!==null&&_layer$attribution!==void 0?_layer$attribution:newlayer.attribution,opacity:(_layer$opacity2=layer.opacity)!==null&&_layer$opacity2!==void 0?_layer$opacity2:newlayer.opacity,visibility:(_layer$visibility=layer.visibility)!==null&&_layer$visibility!==void 0?_layer$visibility:newlayer.visibility,tristate:(_layer$tristate=layer.tristate)!==null&&_layer$tristate!==void 0?_layer$tristate:newlayer.tristate,style:(_layer$style2=layer.style)!==null&&_layer$style2!==void 0?_layer$style2:newlayer.style,role:layer.role,id:layer.id});// For background layers, preserve any custom name/title/attribution/opacity
@@ -9,7 +9,7 @@ console.warn("Could not determine axis order for projection "+tileMatrices[tileM
9
9
  matrixIds.push(entry.Identifier);return entry.ScaleDenominator*0.00028});var format=(_MiscUtils$ensureArra=MiscUtils.ensureArray(layer.Format).find(function(fmt){return fmt==="image/png"}))!==null&&_MiscUtils$ensureArra!==void 0?_MiscUtils$ensureArra:MiscUtils.ensureArray(layer.Format)[0];var getTile=MiscUtils.ensureArray((_capabilities$Operati=capabilities.OperationsMetadata)===null||_capabilities$Operati===void 0||(_capabilities$Operati=_capabilities$Operati.GetTile)===null||_capabilities$Operati===void 0||(_capabilities$Operati=_capabilities$Operati.DCP)===null||_capabilities$Operati===void 0||(_capabilities$Operati=_capabilities$Operati.HTTP)===null||_capabilities$Operati===void 0?void 0:_capabilities$Operati.Get)[0];var getEncoding=MiscUtils.ensureArray(getTile===null||getTile===void 0?void 0:getTile.Constraint).find(function(c){return c.name==="GetEncoding"});var requestEncoding=MiscUtils.ensureArray(getEncoding===null||getEncoding===void 0?void 0:getEncoding.AllowedValues.Value)[0];var serviceUrl=null;if(requestEncoding==="KVP"){serviceUrl=getTile.href}else{serviceUrl=layer.ResourceURL.find(function(u){return u.resourceType==="tile"}).template;(layer.Dimension||[]).forEach(function(dim){serviceUrl=serviceUrl.replace("{"+dim.Identifier+"}",dim.Default)})}return{type:"wmts",url:serviceUrl,capabilitiesUrl:capabilitiesUrl,title:layer.Title+" - "+tileMatrixSet,name:layer.Identifier,tileMatrixPrefix:tileMatrixPrefix,tileMatrixSet:tileMatrixSet,originX:origin[0],originY:origin[1],projection:tileMatrices[tileMatrixSet].crs,tileSize:[topMatrix.TileWidth,topMatrix.TileHeight],style:style,bbox:{crs:"EPSG:4326",bounds:layer.WGS84BoundingBox},format:format,requestEncoding:requestEncoding,resolutions:resolutions,matrixIds:matrixIds,"abstract":layer.Abstract,attribution:{Title:((_capabilities$Service4=capabilities.ServiceProvider)===null||_capabilities$Service4===void 0?void 0:_capabilities$Service4.ProviderName)||((_capabilities$Service5=capabilities.ServiceIdentification)===null||_capabilities$Service5===void 0?void 0:_capabilities$Service5.Title)||"",OnlineResource:((_capabilities$Service6=capabilities.ServiceProvider)===null||_capabilities$Service6===void 0?void 0:_capabilities$Service6.ProviderSite)||""}}}).filter(Boolean);return layerLinks},getWMSLayers:function getWMSLayers(capabilities,calledServiceUrl){var _capabilities,_capabilities2,_capabilities$WMS_Cap,_this3=this;var asGroup=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(!((_capabilities=capabilities)!==null&&_capabilities!==void 0&&_capabilities.WMS_Capabilities)&&!((_capabilities2=capabilities)!==null&&_capabilities2!==void 0&&_capabilities2.WMT_MS_Capabilities)){return[]}capabilities=(_capabilities$WMS_Cap=capabilities.WMS_Capabilities)!==null&&_capabilities$WMS_Cap!==void 0?_capabilities$WMS_Cap:capabilities.WMT_MS_Capabilities;var calledUrlParts=url.parse(calledServiceUrl,true);var extwmsparams={};calledUrlParts.query=Object.keys(calledUrlParts.query).filter(function(key){// Extract extwms params
10
10
  if(key.toUpperCase().startsWith("EXTWMS.")){extwmsparams[key.substring(7)]=calledUrlParts.query[key];return false}// Filter service and request from calledServiceUrl, but keep other parameters (i.e. MAP)
11
11
  return!["service","request"].includes(key.toLowerCase())}).reduce(function(res,key){return _objectSpread(_objectSpread({},res),{},_defineProperty({},key,calledUrlParts.query[key]))},{});delete calledUrlParts.search;var topLayer=capabilities.Capability.Layer;var getMapUrl=this.mergeCalledServiceUrlQuery(ServiceLayerUtils.getDCPTypes(capabilities.Capability.Request.GetMap.DCPType).HTTP.Get.OnlineResource.href,calledUrlParts);var featureInfoUrl=getMapUrl;try{featureInfoUrl=this.mergeCalledServiceUrlQuery(ServiceLayerUtils.getDCPTypes(capabilities.Capability.Request.GetFeatureInfo.DCPType).HTTP.Get.OnlineResource.href,calledUrlParts)}catch(e){// pass
12
- }var mapFormats=null;try{mapFormats=MiscUtils.ensureArray(capabilities.Capability.Request.GetMap.Format)}catch(e){mapFormats=["image/png"]}var infoFormats=null;try{infoFormats=MiscUtils.ensureArray(capabilities.Capability.Request.GetFeatureInfo.Format)}catch(e){infoFormats=["text/plain"]}var externalLayerFeatureInfoFormats=ConfigUtils.getConfigProp("externalLayerFeatureInfoFormats")||{};for(var _i=0,_Object$keys=Object.keys(externalLayerFeatureInfoFormats);_i<_Object$keys.length;_i++){var entry=_Object$keys[_i];if(featureInfoUrl.toLowerCase().includes(entry.toLowerCase())){infoFormats=[externalLayerFeatureInfoFormats[entry]];break}}var version=capabilities.version;var supportedCrs=MiscUtils.ensureArray(topLayer.crs);var topLayerExtent=null;if(topLayer.EX_GeographicBoundingBox){topLayerExtent={crs:"EPSG:4326",bounds:[parseFloat(topLayer.EX_GeographicBoundingBox.westBoundLongitude),parseFloat(topLayer.EX_GeographicBoundingBox.southBoundLatitude),parseFloat(topLayer.EX_GeographicBoundingBox.eastBoundLongitude),parseFloat(topLayer.EX_GeographicBoundingBox.northBoundLatitude)]}}if(!topLayer.Layer||asGroup){return[this.getWMSLayerParams(topLayer,supportedCrs,calledUrlParts,version,getMapUrl,featureInfoUrl,mapFormats,infoFormats,extwmsparams,topLayerExtent)].filter(function(entry){return entry})}else{var entries=MiscUtils.ensureArray(topLayer.Layer).map(function(layer){return _this3.getWMSLayerParams(layer,supportedCrs,calledUrlParts,version,getMapUrl,featureInfoUrl,mapFormats,infoFormats,extwmsparams,topLayerExtent)}).filter(function(entry){return entry});return entries.sort(function(a,b){return strcmp(a.title,b.title)})}},getWMSLayerParams:function getWMSLayerParams(layer,parentCrs,calledUrlParts,version,getMapUrl,featureInfoUrl,mapFormats,infoFormats,extwmsparams,topLayerExtent){var _this4=this,_Object$keys$,_layer$Attribution,_layer$Attribution2,_layer$opacity;var groupbbox=arguments.length>10&&arguments[10]!==undefined?arguments[10]:null;var supportedCrs=MiscUtils.ensureArray(layer.CRS);if(isEmpty(supportedCrs)){supportedCrs=_toConsumableArray(parentCrs||[])}else{supportedCrs=[].concat(_toConsumableArray(parentCrs||[]),_toConsumableArray(supportedCrs))}var sublayers=[];var sublayerbounds={};if(!isEmpty(layer.Layer)){sublayers=MiscUtils.ensureArray(layer.Layer).map(function(sublayer){return _this4.getWMSLayerParams(sublayer,supportedCrs,calledUrlParts,version,getMapUrl,featureInfoUrl,mapFormats,infoFormats,extwmsparams,topLayerExtent,sublayerbounds)}).filter(function(entry){return entry})}var bbox=null;if(isEmpty(layer.BoundingBox)){if(!isEmpty(sublayerbounds)){bbox=sublayerbounds}else if(topLayerExtent){bbox=topLayerExtent}}else{var _boundingBox$CRS;var boundingBox=MiscUtils.ensureArray(layer.BoundingBox)[0];bbox={crs:(_boundingBox$CRS=boundingBox.CRS)!==null&&_boundingBox$CRS!==void 0?_boundingBox$CRS:boundingBox.SRS,bounds:[boundingBox.minx,boundingBox.miny,boundingBox.maxx,boundingBox.maxy].map(Number)}}if(groupbbox!==null){if(isEmpty(groupbbox)){Object.assign(groupbbox,bbox)}else if(bbox&&bbox.crs===groupbbox.crs){groupbbox.bounds[0]=Math.min(bbox.bounds[0],groupbbox.bounds[0]);groupbbox.bounds[1]=Math.min(bbox.bounds[1],groupbbox.bounds[1]);groupbbox.bounds[2]=Math.max(bbox.bounds[2],groupbbox.bounds[2]);groupbbox.bounds[3]=Math.max(bbox.bounds[3],groupbbox.bounds[3])}}var legendUrl=getMapUrl;try{legendUrl=this.mergeCalledServiceUrlQuery(MiscUtils.ensureArray(MiscUtils.ensureArray(layer.Style)[0].LegendURL)[0].OnlineResource.href,calledUrlParts)}catch(e){/* pass */}var styles=MiscUtils.ensureArray(layer.Style).reduce(function(res,entry){return _objectSpread(_objectSpread({},res),{},_defineProperty({},String(entry.Name),entry.Title))},{});var style=styles["default"]?"default":(_Object$keys$=Object.keys(styles)[0])!==null&&_Object$keys$!==void 0?_Object$keys$:"";var attribution={Title:(_layer$Attribution=layer.Attribution)===null||_layer$Attribution===void 0?void 0:_layer$Attribution.Title,OnlineResource:(_layer$Attribution2=layer.Attribution)===null||_layer$Attribution2===void 0||(_layer$Attribution2=_layer$Attribution2.OnlineResource)===null||_layer$Attribution2===void 0?void 0:_layer$Attribution2.href};return{type:"wms",name:String(layer.Name),title:layer.Title,"abstract":layer.Abstract,attribution:attribution,url:getMapUrl,featureInfoUrl:featureInfoUrl,legendUrl:legendUrl,version:version,infoFormats:infoFormats,mapFormats:mapFormats,queryable:layer.queryable===1,sublayers:isEmpty(sublayers)?null:sublayers,expanded:false,bbox:bbox,visibility:layer.visibilityChecked!==0,opacity:((_layer$opacity=layer.opacity)!==null&&_layer$opacity!==void 0?_layer$opacity:1)*255,extwmsparams:extwmsparams,minScale:layer.MinScaleDenominator!==undefined?Number(layer.MinScaleDenominator):undefined,maxScale:layer.MinScaleDenominator!==undefined?Number(layer.MaxScaleDenominator):undefined,styles:styles,style:style}},getWFSLayers:function getWFSLayers(capabilities,calledServiceUrl,mapCrs){var _capabilities$WFS_Cap;var calledUrlParts=url.parse(calledServiceUrl,true);// Filter service and request from calledServiceUrl, but keep other parameters (i.e. MAP)
12
+ }var mapFormats=null;try{mapFormats=MiscUtils.ensureArray(capabilities.Capability.Request.GetMap.Format)}catch(e){mapFormats=["image/png"]}var infoFormats=null;try{infoFormats=MiscUtils.ensureArray(capabilities.Capability.Request.GetFeatureInfo.Format)}catch(e){infoFormats=["text/plain"]}var externalLayerFeatureInfoFormats=ConfigUtils.getConfigProp("externalLayerFeatureInfoFormats")||{};for(var _i=0,_Object$keys=Object.keys(externalLayerFeatureInfoFormats);_i<_Object$keys.length;_i++){var entry=_Object$keys[_i];if(featureInfoUrl.toLowerCase().includes(entry.toLowerCase())){infoFormats=[externalLayerFeatureInfoFormats[entry]];break}}var version=capabilities.version;var supportedCrs=MiscUtils.ensureArray(topLayer.crs);var topLayerExtent=null;if(topLayer.EX_GeographicBoundingBox){topLayerExtent={crs:"EPSG:4326",bounds:[parseFloat(topLayer.EX_GeographicBoundingBox.westBoundLongitude),parseFloat(topLayer.EX_GeographicBoundingBox.southBoundLatitude),parseFloat(topLayer.EX_GeographicBoundingBox.eastBoundLongitude),parseFloat(topLayer.EX_GeographicBoundingBox.northBoundLatitude)]}}if(!topLayer.Layer||asGroup){return[this.getWMSLayerParams(topLayer,supportedCrs,calledUrlParts,version,getMapUrl,featureInfoUrl,mapFormats,infoFormats,extwmsparams,topLayerExtent)].filter(function(entry){return entry})}else{var entries=MiscUtils.ensureArray(topLayer.Layer).map(function(layer){return _this3.getWMSLayerParams(layer,supportedCrs,calledUrlParts,version,getMapUrl,featureInfoUrl,mapFormats,infoFormats,extwmsparams,topLayerExtent)}).filter(function(entry){return entry});return entries.sort(function(a,b){return strcmp(a.title,b.title)})}},getWMSLayerParams:function getWMSLayerParams(layer,parentCrs,calledUrlParts,version,getMapUrl,featureInfoUrl,mapFormats,infoFormats,extwmsparams,topLayerExtent){var _this4=this,_Object$keys$,_layer$Attribution,_layer$Attribution2,_layer$opacity;var groupbbox=arguments.length>10&&arguments[10]!==undefined?arguments[10]:null;var supportedCrs=MiscUtils.ensureArray(layer.CRS);if(isEmpty(supportedCrs)){supportedCrs=_toConsumableArray(parentCrs||[])}else{supportedCrs=[].concat(_toConsumableArray(parentCrs||[]),_toConsumableArray(supportedCrs))}var sublayers=[];var sublayerbounds={};if(!isEmpty(layer.Layer)){sublayers=MiscUtils.ensureArray(layer.Layer).map(function(sublayer){return _this4.getWMSLayerParams(sublayer,supportedCrs,calledUrlParts,version,getMapUrl,featureInfoUrl,mapFormats,infoFormats,extwmsparams,topLayerExtent,sublayerbounds)}).filter(function(entry){return entry})}var bbox=null;if(isEmpty(layer.BoundingBox)){if(!isEmpty(sublayerbounds)){bbox=sublayerbounds}else if(topLayerExtent){bbox=topLayerExtent}}else{var _boundingBox$CRS;var boundingBox=MiscUtils.ensureArray(layer.BoundingBox)[0];bbox={crs:(_boundingBox$CRS=boundingBox.CRS)!==null&&_boundingBox$CRS!==void 0?_boundingBox$CRS:boundingBox.SRS,bounds:[boundingBox.minx,boundingBox.miny,boundingBox.maxx,boundingBox.maxy].map(Number)}}if(groupbbox!==null){if(isEmpty(groupbbox)){Object.assign(groupbbox,bbox)}else if(bbox&&bbox.crs===groupbbox.crs){groupbbox.bounds[0]=Math.min(bbox.bounds[0],groupbbox.bounds[0]);groupbbox.bounds[1]=Math.min(bbox.bounds[1],groupbbox.bounds[1]);groupbbox.bounds[2]=Math.max(bbox.bounds[2],groupbbox.bounds[2]);groupbbox.bounds[3]=Math.max(bbox.bounds[3],groupbbox.bounds[3])}}var legendUrl=getMapUrl;try{legendUrl=this.mergeCalledServiceUrlQuery(MiscUtils.ensureArray(MiscUtils.ensureArray(layer.Style)[0].LegendURL)[0].OnlineResource.href,calledUrlParts)}catch(e){/* pass */}var dimensions=[];MiscUtils.ensureArray(layer.Dimension).forEach(function(dim){var _dim$fieldName,_dim$endFieldName;dimensions.push({units:dim.units,name:dim.name,multiple:dim.multiple==="1",value:dim["#text"],fieldName:(_dim$fieldName=dim.fieldName)!==null&&_dim$fieldName!==void 0?_dim$fieldName:null,endFieldName:(_dim$endFieldName=dim.endFieldName)!==null&&_dim$endFieldName!==void 0?_dim$endFieldName:null})});var styles=MiscUtils.ensureArray(layer.Style).reduce(function(res,entry){return _objectSpread(_objectSpread({},res),{},_defineProperty({},String(entry.Name),entry.Title))},{});var style=styles["default"]?"default":(_Object$keys$=Object.keys(styles)[0])!==null&&_Object$keys$!==void 0?_Object$keys$:"";var attribution={Title:(_layer$Attribution=layer.Attribution)===null||_layer$Attribution===void 0?void 0:_layer$Attribution.Title,OnlineResource:(_layer$Attribution2=layer.Attribution)===null||_layer$Attribution2===void 0||(_layer$Attribution2=_layer$Attribution2.OnlineResource)===null||_layer$Attribution2===void 0?void 0:_layer$Attribution2.href};return{type:"wms",name:String(layer.Name),title:layer.Title,"abstract":layer.Abstract,attribution:attribution,url:getMapUrl,featureInfoUrl:featureInfoUrl,legendUrl:legendUrl,version:version,infoFormats:infoFormats,mapFormats:mapFormats,queryable:layer.queryable===1,sublayers:isEmpty(sublayers)?null:sublayers,expanded:false,bbox:bbox,visibility:layer.visibilityChecked!==0,opacity:((_layer$opacity=layer.opacity)!==null&&_layer$opacity!==void 0?_layer$opacity:1)*255,extwmsparams:extwmsparams,minScale:layer.MinScaleDenominator!==undefined?Number(layer.MinScaleDenominator):undefined,maxScale:layer.MinScaleDenominator!==undefined?Number(layer.MaxScaleDenominator):undefined,dimensions:dimensions,styles:styles,style:style}},getWFSLayers:function getWFSLayers(capabilities,calledServiceUrl,mapCrs){var _capabilities$WFS_Cap;var calledUrlParts=url.parse(calledServiceUrl,true);// Filter service and request from calledServiceUrl, but keep other parameters (i.e. MAP)
13
13
  calledUrlParts.query=Object.keys(calledUrlParts.query).filter(function(key){return!["service","request"].includes(key.toLowerCase())}).reduce(function(res,key){return _objectSpread(_objectSpread({},res),{},_defineProperty({},key,calledUrlParts.query[key]))},{});delete calledUrlParts.search;if(!(capabilities!==null&&capabilities!==void 0&&(_capabilities$WFS_Cap=capabilities.WFS_Capabilities)!==null&&_capabilities$WFS_Cap!==void 0&&_capabilities$WFS_Cap.version)){return[]}else if(capabilities.WFS_Capabilities.version<"1.1.0"){return ServiceLayerUtils.getWFS10Layers(capabilities.WFS_Capabilities,calledUrlParts)}else{return ServiceLayerUtils.getWFS11_20Layers(capabilities.WFS_Capabilities,calledUrlParts,mapCrs)}},getWFS10Layers:function getWFS10Layers(capabilities,calledUrlParts){var serviceUrl=null;var version=capabilities.version;var formats=null;try{serviceUrl=ServiceLayerUtils.getDCPTypes(MiscUtils.ensureArray(capabilities.Capability.Request.GetFeature.DCPType)).HTTP.Get.onlineResource;serviceUrl=this.mergeCalledServiceUrlQuery(serviceUrl,calledUrlParts);formats=Object.keys(capabilities.Capability.Request.GetFeature.ResultFormat);if(typeof formats==="string"){// convert to list if single entry
14
14
  formats=[formats]}}catch(e){return[]}var layers=[];var _iterator=_createForOfIteratorHelper(MiscUtils.ensureArray(capabilities.FeatureTypeList.FeatureType)),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var featureType=_step.value;var name=void 0;var bbox=void 0;try{name=featureType.Name;var llbbox=featureType.LatLongBoundingBox;bbox={crs:featureType.SRS,bounds:[llbbox.minx,llbbox.miny,llbbox.maxx,llbbox.maxy]}}catch(e){continue;// Name and bbox are required
15
15
  }var title=featureType.Title||name;var _abstract=featureType.Abstract||"";layers.push({type:"wfs",name:name,title:title,"abstract":_abstract,bbox:bbox,projection:featureType.SRS,url:serviceUrl,version:version,formats:formats,color:randomColor(),visibility:true})}}catch(err){_iterator.e(err)}finally{_iterator.f()}return layers},getWFS11_20Layers:function getWFS11_20Layers(capabilities,calledUrlParts,mapCrs){var serviceUrl=null;var version=capabilities.version;var formats=null;try{var getFeatureOp=MiscUtils.ensureArray(capabilities.OperationsMetadata.Operation).find(function(el){return el.name==="GetFeature"});serviceUrl=ServiceLayerUtils.getDCPTypes(MiscUtils.ensureArray(getFeatureOp.DCP)).HTTP.Get.href;serviceUrl=this.mergeCalledServiceUrlQuery(serviceUrl,calledUrlParts);var outputFormat=MiscUtils.ensureArray(getFeatureOp.Parameter).find(function(el){return el.name==="outputFormat"});formats=MiscUtils.ensureArray(outputFormat.AllowedValues?outputFormat.AllowedValues.Value:outputFormat.Value)}catch(e){return[]}var layers=[];var _iterator2=_createForOfIteratorHelper(MiscUtils.ensureArray(capabilities.FeatureTypeList.FeatureType)),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var featureType=_step2.value;var name=void 0;var bbox=void 0;try{name=featureType.Name;var lc=featureType.WGS84BoundingBox.LowerCorner.split(/\s+/);var uc=featureType.WGS84BoundingBox.UpperCorner.split(/\s+/);bbox={crs:"EPSG:4326",bounds:[lc[0],lc[1],uc[0],uc[1]]}}catch(e){continue;// Name and bbox are required