qwc2 2025.4.22 → 2025.5.0-7.1

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.
Files changed (55) hide show
  1. package/components/AttributeForm.js +1 -1
  2. package/components/IdentifyViewer.js +1 -1
  3. package/components/SearchBox.js +1 -1
  4. package/components/map/OlLayer.js +5 -5
  5. package/components/map/layers/MVTLayer.js +1 -1
  6. package/components/map/layers/WMTSLayer.js +2 -2
  7. package/components/map3d/Draw3D.js +4 -4
  8. package/components/map3d/ExportObjects3D.js +3 -2
  9. package/components/map3d/LayerTree3D.js +2 -2
  10. package/components/map3d/Map3D.js +5 -4
  11. package/components/map3d/Map3DLight.js +2 -2
  12. package/components/map3d/MapExport3D.js +1 -1
  13. package/components/map3d/SearchField3D.js +3 -3
  14. package/components/map3d/drawtool/EditTool3D.js +2 -2
  15. package/components/map3d/layers/VectorLayer3D.js +2 -2
  16. package/components/map3d/layers/WFSLayer3D.js +3 -3
  17. package/components/map3d/style/Draw3D.css +9 -0
  18. package/components/map3d/style/Map3D.css +2 -1
  19. package/components/map3d/utils/Tiles3DStyle.js +4 -4
  20. package/components/widgets/EditableSelect.js +2 -2
  21. package/components/widgets/NumberInput.js +2 -2
  22. package/components/widgets/style/NumberInput.css +4 -0
  23. package/package.json +1 -1
  24. package/plugins/API.js +5 -5
  25. package/plugins/Identify.js +1 -1
  26. package/plugins/Print.js +6 -6
  27. package/plugins/TopBar.js +1 -1
  28. package/plugins/style/Routing.css +1 -0
  29. package/scripts/themesConfig.js +2 -2
  30. package/scripts/themesConfig.py +4 -1
  31. package/static/translations/bg-BG.json +2 -0
  32. package/static/translations/ca-ES.json +2 -0
  33. package/static/translations/cs-CZ.json +2 -0
  34. package/static/translations/de-CH.json +2 -0
  35. package/static/translations/de-DE.json +2 -0
  36. package/static/translations/en-US.json +2 -0
  37. package/static/translations/es-ES.json +2 -0
  38. package/static/translations/fi-FI.json +2 -0
  39. package/static/translations/fr-FR.json +3 -1
  40. package/static/translations/hu-HU.json +2 -0
  41. package/static/translations/it-IT.json +2 -0
  42. package/static/translations/ja-JP.json +2 -0
  43. package/static/translations/nl-NL.json +2 -0
  44. package/static/translations/no-NO.json +2 -0
  45. package/static/translations/pl-PL.json +2 -0
  46. package/static/translations/pt-BR.json +2 -0
  47. package/static/translations/pt-PT.json +2 -0
  48. package/static/translations/ro-RO.json +2 -0
  49. package/static/translations/ru-RU.json +2 -0
  50. package/static/translations/sv-SE.json +2 -0
  51. package/static/translations/tr-TR.json +2 -0
  52. package/static/translations/tsconfig.json +2 -0
  53. package/utils/LayerUtils.js +2 -2
  54. package/utils/ServiceLayerUtils.js +2 -3
  55. package/components/map3d/style/SearchField3D.css +0 -8
@@ -11,7 +11,7 @@ if(["new","empty"].includes(fieldStatus)){newRelationValues[table].features.spli
11
11
  var changed=_this.props.editContext.changed;var fk=_this.state.relationTables[table].fk;if(_this.props.editContext.action!=="Draw"&&feature.properties[fk]!==_this.props.editContext.feature.id){newRelationValues[table].features[idx].properties[fk]=_this.props.editContext.feature.id;newRelationValues[table].features[idx].__status__="changed";changed=true}var newFeature=_objectSpread(_objectSpread({},_this.props.editContext.feature),{},{relationValues:newRelationValues});_this.props.setEditContext(_this.props.editContext.id,{feature:newFeature,changed:changed})}_this.setState({childEdit:null})});_defineProperty(_this,"onDiscard",function(action){if(action==="Discard"){_this.props.setCurrentTaskBlocked(false);if(!_this.props.onDiscard||!_this.props.onDiscard()){if(_this.props.editContext.action==="Pick"){// Re-query the original feature
12
12
  _this.setState({busy:true});_this.props.iface.getFeatureById(_this.props.editConfig.editDataset,_this.props.editContext.feature.id,_this.props.map.projection,function(feature){_this.setState({busy:false});if(!isEmpty(_this.state.relationTables)){// Re-load relation values
13
13
  _this.loadRelationValues(feature,function(newFeature){_this.props.setEditContext(_this.props.editContext.id,{feature:newFeature,changed:false})});// Re-validate feature field constraints
14
- _this.validateFieldConstraints(feature)}else{_this.props.setEditContext(_this.props.editContext.id,{feature:feature,changed:false})}})}else{var featureSkel={type:"Feature",properties:{}};var mapPrefix=(_this.props.editConfig.editDataset.match(/^[^.]+\./)||[""])[0];getFeatureTemplate(_this.props.editConfig,featureSkel,_this.props.iface,mapPrefix,_this.props.map.projection,function(feature){_this.props.setEditContext(_this.props.editContext.id,{feature:feature,changed:false})})}}}});_defineProperty(_this,"setupChangedObserver",function(form){_this.form=form;if(form){form.observer=new MutationObserver(function(){_this.setState({formValid:form.checkValidity()})});form.observer.observe(form,{subtree:true,childList:true})}});_defineProperty(_this,"formChanged",function(ev){var _ev$target;var form=ev.currentTarget;if((_ev$target=ev.target)!==null&&_ev$target!==void 0&&_ev$target.setCustomValidity){ev.target.setCustomValidity("")}if(form){_this.setState({formValid:form.checkValidity()});_this.props.setEditContext(_this.props.editContext.id,{changed:true})}});_defineProperty(_this,"validateFieldConstraints",function(feature){var validCallback=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var constraintExpressions=_this.props.editConfig.fields.reduce(function(res,cur){var _cur$constraints;if((_cur$constraints=cur.constraints)!==null&&_cur$constraints!==void 0&&_cur$constraints.expression){var _cur$constraints2;return _objectSpread(_objectSpread({},res),{},_defineProperty({},cur.id,(_cur$constraints2=cur.constraints)===null||_cur$constraints2===void 0?void 0:_cur$constraints2.expression))}return res},{});parseExpressionsAsync(constraintExpressions,feature,_this.props.iface,_this.editMapPrefix(),_this.props.map.projection,false).then(function(result){var valid=true;Object.entries(result).forEach(function(_ref5){var _ref6=_slicedToArray(_ref5,2),key=_ref6[0],value=_ref6[1];var element=_this.form.elements.namedItem(key);if(value===false){var _this$props$editConfi,_this$props$editConfi2;valid=false;element.setCustomValidity((_this$props$editConfi=(_this$props$editConfi2=_this.props.editConfig.fields.find(function(field){return field.id===key}))===null||_this$props$editConfi2===void 0||(_this$props$editConfi2=_this$props$editConfi2.constraints)===null||_this$props$editConfi2===void 0?void 0:_this$props$editConfi2.placeholder)!==null&&_this$props$editConfi!==void 0?_this$props$editConfi:LocaleUtils.tr("editing.contraintviolation"))}else{element.setCustomValidity("")}});if(!valid){_this.setState({formValid:false})}else{if(validCallback){validCallback()}}})});_defineProperty(_this,"onSubmit",function(ev){ev.preventDefault();_this.validateFieldConstraints(_this.props.editContext.feature,_this.doSubmit)});_defineProperty(_this,"doSubmit",function(){_this.setState({busy:true});var feature=_this.props.editContext.feature;// Ensure properties is not null
14
+ _this.validateFieldConstraints(feature)}else{_this.props.setEditContext(_this.props.editContext.id,{feature:feature,changed:false})}})}else{var featureSkel={type:"Feature",properties:{}};var mapPrefix=(_this.props.editConfig.editDataset.match(/^[^.]+\./)||[""])[0];getFeatureTemplate(_this.props.editConfig,featureSkel,_this.props.iface,mapPrefix,_this.props.map.projection,function(feature){_this.props.setEditContext(_this.props.editContext.id,{feature:feature,changed:false})})}}}});_defineProperty(_this,"setupChangedObserver",function(form){_this.form=form;if(form){form.observer=new MutationObserver(function(){_this.setState({formValid:form.checkValidity()})});form.observer.observe(form,{subtree:true,childList:true,attributes:true})}});_defineProperty(_this,"formChanged",function(ev){var _ev$target;var form=ev.currentTarget;if((_ev$target=ev.target)!==null&&_ev$target!==void 0&&_ev$target.setCustomValidity){ev.target.setCustomValidity("")}if(form){_this.setState({formValid:form.checkValidity()});_this.props.setEditContext(_this.props.editContext.id,{changed:true})}});_defineProperty(_this,"validateFieldConstraints",function(feature){var validCallback=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var invalidCallback=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;var constraintExpressions=_this.props.editConfig.fields.reduce(function(res,cur){var _cur$constraints;if((_cur$constraints=cur.constraints)!==null&&_cur$constraints!==void 0&&_cur$constraints.expression){var _cur$constraints2;return _objectSpread(_objectSpread({},res),{},_defineProperty({},cur.id,(_cur$constraints2=cur.constraints)===null||_cur$constraints2===void 0?void 0:_cur$constraints2.expression))}return res},{});parseExpressionsAsync(constraintExpressions,feature,_this.props.iface,_this.editMapPrefix(),_this.props.map.projection,false).then(function(result){var valid=true;Object.entries(result).forEach(function(_ref5){var _ref6=_slicedToArray(_ref5,2),key=_ref6[0],value=_ref6[1];var element=_this.form.elements.namedItem(key);if(value===false){var _this$props$editConfi,_this$props$editConfi2;valid=false;element.setCustomValidity((_this$props$editConfi=(_this$props$editConfi2=_this.props.editConfig.fields.find(function(field){return field.id===key}))===null||_this$props$editConfi2===void 0||(_this$props$editConfi2=_this$props$editConfi2.constraints)===null||_this$props$editConfi2===void 0?void 0:_this$props$editConfi2.placeholder)!==null&&_this$props$editConfi!==void 0?_this$props$editConfi:LocaleUtils.tr("editing.contraintviolation"))}else{element.setCustomValidity("")}});if(!valid){_this.setState({formValid:false});if(invalidCallback){invalidCallback()}}else{if(validCallback){validCallback()}}})});_defineProperty(_this,"onSubmit",function(ev){ev.preventDefault();_this.validateFieldConstraints(_this.props.editContext.feature,_this.doSubmit,function(){/* eslint-disable-next-line */alert(LocaleUtils.tr("editing.contraintviolation"))})});_defineProperty(_this,"doSubmit",function(){_this.setState({busy:true});var feature=_this.props.editContext.feature;// Ensure properties is not null
15
15
  feature=_objectSpread(_objectSpread({},feature),{},{type:"Feature",properties:_objectSpread({},feature.properties||{}),crs:{type:"name",properties:{name:CoordinatesUtils.toOgcUrnCrs(_this.props.map.projection)}}});var curConfig=_this.props.editConfig;var mapPrefix=_this.editMapPrefix();var textNullValue=ConfigUtils.getConfigProp("editTextNullValue");// Keep relation values separate
16
16
  var relationValues=clone(feature.relationValues||{});delete feature.relationValues;var relationUploads={};var featureUploads={};// Collect all values from form fields
17
17
  var fieldnames=Array.from(_this.form.elements).map(function(element){return element.name}).filter(function(x){return x&&x!=="g-recaptcha-response"});fieldnames.forEach(function(name){var fieldConfig=(curConfig.fields||[]).find(function(field){return field.id===name})||{};var element=_this.form.elements.namedItem(name);if(element){var parts=name.split("__");var value=element.type==="radio"||element.type==="checkbox"?element.checked:element.value;var nullElements=["date","number","radio"];var nullFieldTypes=["date","number"];if(parts.length>=3){var _nrelFieldConfig$data;// Relation value
@@ -13,4 +13,4 @@ match=LayerUtils.searchLayer(_this.props.layers,"title",result.layertitle)}if(ma
13
13
  text=_this.props.attributeTransform(attrName,text,layer,result);text=MiscUtils.addLinkAnchors(text);return _this.parsedContent(text)});_defineProperty(_this,"parsedContent",function(text){text=text.replace("&#10;","<br />");var options={replace:function replace(node){if(node.name==="a"){return/*#__PURE__*/React.createElement("a",{href:node.attribs.href,onClick:node.attribs.onclick?function(ev){return _this.evalOnClick(ev,node.attribs.onclick)}:_this.attributeLinkClicked,target:node.attribs.target||"_blank"},domToReact(node.children,options))}return undefined}};return htmlReactParser(text,options)});_defineProperty(_this,"evalOnClick",function(ev,onclick){// eslint-disable-next-line
14
14
  eval(onclick);ev.preventDefault()});_defineProperty(_this,"attributeLinkClicked",function(ev){_this.props.openExternalUrl(ev.target.href,ev.target.target,{docked:_this.props.iframeDialogsInitiallyDocked});ev.preventDefault()});_this.currentResultElRef=null;_this.scrollIntoView=false;_this.state.exportFormat=!Array.isArray(props.enableExport)||props.enableExport.includes("geojson")?"geojson":props.enableExport[0];return _this}_inherits(IdentifyViewer,_React$Component);return _createClass(IdentifyViewer,[{key:"componentDidMount",value:function componentDidMount(){this.updateResultTree()}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps,prevState){if(this.props.identifyResults!==prevProps.identifyResults){this.updateResultTree()}if(prevState.currentResult!==this.state.currentResult||prevState.resultTree!==this.state.resultTree){this.setHighlightedResults(this.state.currentResult===null?null:[this.state.currentResult],this.state.resultTree)}// Scroll to selected result
15
15
  if(this.state.currentResult&&this.state.currentResult!==prevState.currentResult&&this.currentResultElRef&&this.scrollIntoView){this.currentResultElRef.parentNode.scrollTop=this.currentResultElRef.offsetTop-this.currentResultElRef.parentNode.offsetTop;this.scrollIntoView=false;this.currentResultElRef=null}}},{key:"componentWillUnmount",value:function componentWillUnmount(){this.props.removeLayer("__identifyviewerhighlight")}},{key:"render",value:function render(){var _this2=this,_exporters$find;var tree=this.props.displayResultTree;var body=null;var reportFeatures={};if(tree){var contents=Object.keys(this.state.resultTree).map(function(layer){return _this2.renderLayer(layer)});var attributes=this.renderResultAttributes(this.state.currentLayer,this.state.currentResult,"identify-result-tree-frame",reportFeatures);var resultsContainerStyle={maxHeight:attributes?"10em":"initial"};body=[/*#__PURE__*/React.createElement("div",{className:"identify-results-container",key:"results-container",style:resultsContainerStyle},contents),attributes]}else{body=/*#__PURE__*/React.createElement("div",{className:"identify-flat-results-list"},this.props.showLayerSelector?/*#__PURE__*/React.createElement("div",{className:"identify-selectbox"},/*#__PURE__*/React.createElement("select",{className:"identify-layer-select",onChange:function onChange(e){var selectedLayer=e.target.value;_this2.setState({selectedLayer:selectedLayer})}},/*#__PURE__*/React.createElement("option",{value:""},LocaleUtils.tr("identify.layerall")),Object.keys(this.state.resultTree).sort().map(function(layer){return/*#__PURE__*/React.createElement("option",{key:layer,value:layer},layer)})),/*#__PURE__*/React.createElement("span",{className:"identify-buttonbox-spacer"}),/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("identify.featurecount"),": ",Object.values(this.state.selectedLayer!==""?this.state.resultTree[this.state.selectedLayer]:this.state.resultTree).flat().length)):null,Object.keys(this.state.selectedLayer!==""?_defineProperty({},this.state.selectedLayer,this.state.resultTree[this.state.selectedLayer]):this.state.resultTree).map(function(layer){var layerResults=_this2.state.resultTree[layer];return layerResults.map(function(result){var resultClass=_this2.state.currentResult===result?"identify-result-frame-highlighted":"identify-result-frame-normal";return/*#__PURE__*/React.createElement("div",{key:result.id,onMouseEnter:function onMouseEnter(){return _this2.setState({currentResult:result,currentLayer:layer})},onMouseLeave:function onMouseLeave(){return _this2.setState({currentResult:null,currentLayer:null})}},_this2.renderResultAttributes(layer,result,resultClass,reportFeatures))})}))}// "el.style.background='inherit'": HACK to trigger an additional repaint, since Safari/Chrome on iOS render the element cut off the first time
16
- var exporters=this.getExporters();var clipboardExportDisabled=((_exporters$find=exporters.find(function(entry){return entry.id===_this2.state.exportFormat}))===null||_exporters$find===void 0?void 0:_exporters$find.allowClipboard)!==true;return/*#__PURE__*/React.createElement("div",{className:"identify-body",ref:function ref(el){if(el)el.style.background="inherit"}},body,this.props.enableExport===true||!isEmpty(this.props.enableExport)?/*#__PURE__*/React.createElement("div",{className:"identify-buttonbox"},/*#__PURE__*/React.createElement("span",{className:"identify-buttonbox-spacer"}),/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("identify.export"),":\xA0"),/*#__PURE__*/React.createElement("div",{className:"controlgroup"},/*#__PURE__*/React.createElement("select",{className:"combo identify-export-format",onChange:function onChange(ev){return _this2.setState({exportFormat:ev.target.value})},value:this.state.exportFormat},exporters.filter(function(entry){return!Array.isArray(_this2.props.enableExport)||_this2.props.enableExport.includes(entry.id)}).map(function(entry){var _entry$title;return/*#__PURE__*/React.createElement("option",{key:entry.id,value:entry.id},(_entry$title=entry.title)!==null&&_entry$title!==void 0?_entry$title:LocaleUtils.tr(entry.titleMsgId))})),/*#__PURE__*/React.createElement("button",{className:"button",onClick:function onClick(){return _this2.exportResults()},title:LocaleUtils.tr("identify.download")},/*#__PURE__*/React.createElement(Icon,{icon:"export"})),/*#__PURE__*/React.createElement("button",{className:"button",disabled:clipboardExportDisabled,onClick:function onClick(){return _this2.exportResults(true)},title:LocaleUtils.tr("identify.clipboard")},/*#__PURE__*/React.createElement(Icon,{icon:"copy"})))):null,Object.values(reportFeatures).find(function(entry){return entry.length>1})!==undefined?/*#__PURE__*/React.createElement("div",{className:"identify-buttonbox"},/*#__PURE__*/React.createElement("span",{className:"identify-buttonbox-spacer"}),/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("identify.aggregatedreport"),":\xA0"),/*#__PURE__*/React.createElement("div",{className:"controlgroup"},/*#__PURE__*/React.createElement("select",{className:"combo identify-export-format",onChange:function onChange(ev){return _this2.setState({selectedAggregatedReport:ev.target.value})},value:this.state.selectedAggregatedReport||""},/*#__PURE__*/React.createElement("option",{disabled:true,value:""},LocaleUtils.tr("identify.selectlayer")),Object.entries(reportFeatures).map(function(_ref15){var _ref16=_slicedToArray(_ref15,2),layername=_ref16[0],results=_ref16[1];if(results.length>1){return/*#__PURE__*/React.createElement("option",{key:layername,value:layername},results[0].layertitle)}return null})),/*#__PURE__*/React.createElement("button",{className:"button",disabled:!this.state.selectedAggregatedReport||this.state.generatingReport,onClick:function onClick(){return _this2.downloadAggregatedReport(_this2.state.selectedAggregatedReport,reportFeatures[_this2.state.selectedAggregatedReport])}},this.state.generatingReport?/*#__PURE__*/React.createElement(Spinner,null):/*#__PURE__*/React.createElement(Icon,{icon:"report"})))):null)}}])}(React.Component);_defineProperty(IdentifyViewer,"propTypes",{addLayerFeatures:PropTypes.func,attributeCalculator:PropTypes.func,attributeTransform:PropTypes.func,collapsible:PropTypes.bool,customExporters:PropTypes.array,displayResultTree:PropTypes.bool,enableExport:PropTypes.oneOfType([PropTypes.bool,PropTypes.array]),exportGeometry:PropTypes.bool,highlightAllResults:PropTypes.bool,identifyResults:PropTypes.object,iframeDialogsInitiallyDocked:PropTypes.bool,layers:PropTypes.array,longAttributesDisplay:PropTypes.oneOf(["ellipsis","wrap"]),mapcrs:PropTypes.string,openExternalUrl:PropTypes.func,removeLayer:PropTypes.func,replaceImageUrls:PropTypes.bool,setActiveLayerInfo:PropTypes.func,showLayerSelector:PropTypes.bool,showLayerTitles:PropTypes.bool,theme:PropTypes.object,zoomToExtent:PropTypes.func});_defineProperty(IdentifyViewer,"defaultProps",{longAttributesDisplay:"ellipsis",customExporters:[],displayResultTree:true,attributeCalculator:function attributeCalculator(/* layer, feature */){return[]},attributeTransform:function attributeTransform(name,value/* , layer, feature */){return value},showLayerTitles:true,showLayerSelector:true,highlightAllResults:true});var selector=function selector(state){return{theme:state.theme.current,layers:state.layers.flat,mapcrs:state.map.projection}};export default connect(selector,{addLayerFeatures:addLayerFeatures,removeLayer:removeLayer,setActiveLayerInfo:setActiveLayerInfo,openExternalUrl:openExternalUrl,zoomToExtent:zoomToExtent})(IdentifyViewer);
16
+ var exporters=this.getExporters();var clipboardExportDisabled=((_exporters$find=exporters.find(function(entry){return entry.id===_this2.state.exportFormat}))===null||_exporters$find===void 0?void 0:_exporters$find.allowClipboard)!==true;return/*#__PURE__*/React.createElement("div",{className:"identify-body",ref:function ref(el){if(el)el.style.background="inherit"}},body,this.props.enableExport===true||!isEmpty(this.props.enableExport)?/*#__PURE__*/React.createElement("div",{className:"identify-buttonbox"},/*#__PURE__*/React.createElement("span",{className:"identify-buttonbox-spacer"}),/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("identify.export"),":\xA0"),/*#__PURE__*/React.createElement("div",{className:"controlgroup"},/*#__PURE__*/React.createElement("select",{className:"combo identify-export-format",onChange:function onChange(ev){return _this2.setState({exportFormat:ev.target.value})},value:this.state.exportFormat},exporters.filter(function(entry){return!Array.isArray(_this2.props.enableExport)||_this2.props.enableExport.includes(entry.id)}).map(function(entry){var _entry$title;return/*#__PURE__*/React.createElement("option",{key:entry.id,value:entry.id},(_entry$title=entry.title)!==null&&_entry$title!==void 0?_entry$title:LocaleUtils.tr(entry.titleMsgId))})),/*#__PURE__*/React.createElement("button",{className:"button",onClick:function onClick(){return _this2.exportResults()},title:LocaleUtils.tr("identify.download")},/*#__PURE__*/React.createElement(Icon,{icon:"export"})),/*#__PURE__*/React.createElement("button",{className:"button",disabled:clipboardExportDisabled,onClick:function onClick(){return _this2.exportResults(true)},title:LocaleUtils.tr("identify.clipboard")},/*#__PURE__*/React.createElement(Icon,{icon:"copy"})))):null,this.props.enableAggregatedReports&&Object.values(reportFeatures).find(function(entry){return entry.length>1})!==undefined?/*#__PURE__*/React.createElement("div",{className:"identify-buttonbox"},/*#__PURE__*/React.createElement("span",{className:"identify-buttonbox-spacer"}),/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("identify.aggregatedreport"),":\xA0"),/*#__PURE__*/React.createElement("div",{className:"controlgroup"},/*#__PURE__*/React.createElement("select",{className:"combo identify-export-format",onChange:function onChange(ev){return _this2.setState({selectedAggregatedReport:ev.target.value})},value:this.state.selectedAggregatedReport||""},/*#__PURE__*/React.createElement("option",{disabled:true,value:""},LocaleUtils.tr("identify.selectlayer")),Object.entries(reportFeatures).map(function(_ref15){var _ref16=_slicedToArray(_ref15,2),layername=_ref16[0],results=_ref16[1];if(results.length>1){return/*#__PURE__*/React.createElement("option",{key:layername,value:layername},results[0].layertitle)}return null})),/*#__PURE__*/React.createElement("button",{className:"button",disabled:!this.state.selectedAggregatedReport||this.state.generatingReport,onClick:function onClick(){return _this2.downloadAggregatedReport(_this2.state.selectedAggregatedReport,reportFeatures[_this2.state.selectedAggregatedReport])}},this.state.generatingReport?/*#__PURE__*/React.createElement(Spinner,null):/*#__PURE__*/React.createElement(Icon,{icon:"report"})))):null)}}])}(React.Component);_defineProperty(IdentifyViewer,"propTypes",{addLayerFeatures:PropTypes.func,attributeCalculator:PropTypes.func,attributeTransform:PropTypes.func,collapsible:PropTypes.bool,customExporters:PropTypes.array,displayResultTree:PropTypes.bool,enableAggregatedReports:PropTypes.bool,enableExport:PropTypes.oneOfType([PropTypes.bool,PropTypes.array]),exportGeometry:PropTypes.bool,highlightAllResults:PropTypes.bool,identifyResults:PropTypes.object,iframeDialogsInitiallyDocked:PropTypes.bool,layers:PropTypes.array,longAttributesDisplay:PropTypes.oneOf(["ellipsis","wrap"]),mapcrs:PropTypes.string,openExternalUrl:PropTypes.func,removeLayer:PropTypes.func,replaceImageUrls:PropTypes.bool,setActiveLayerInfo:PropTypes.func,showLayerSelector:PropTypes.bool,showLayerTitles:PropTypes.bool,theme:PropTypes.object,zoomToExtent:PropTypes.func});_defineProperty(IdentifyViewer,"defaultProps",{longAttributesDisplay:"ellipsis",customExporters:[],displayResultTree:true,attributeCalculator:function attributeCalculator(/* layer, feature */){return[]},attributeTransform:function attributeTransform(name,value/* , layer, feature */){return value},enableAggregatedReports:true,showLayerTitles:true,showLayerSelector:true,highlightAllResults:true});var selector=function selector(state){return{theme:state.theme.current,layers:state.layers.flat,mapcrs:state.map.projection}};export default connect(selector,{addLayerFeatures:addLayerFeatures,removeLayer:removeLayer,setActiveLayerInfo:setActiveLayerInfo,openExternalUrl:openExternalUrl,zoomToExtent:zoomToExtent})(IdentifyViewer);
@@ -14,7 +14,7 @@ var searchText=_this.state.searchText.trim();if(isEmpty(searchText)){_this.setSt
14
14
  results=results.filter(function(group){var _group$type3;return((_group$type3=group.type)!==null&&_group$type3!==void 0?_group$type3:SearchResultType.PLACE)===SearchResultType.PLACE})}_this.setState(function(state){if(searchSession!==state.searchSession){return{}}var searchResults=_objectSpread(_objectSpread({},state.searchResults),{},_defineProperty({},provKey,{results:results,result_counts:response.result_counts,tot_result_count:totResultCount}));var newPendingSearches=state.pendingSearches.filter(function(entry){return entry!==provKey});if(isEmpty(newPendingSearches)&&uniquePlaceResult){// eslint-disable-next-line no-unused-vars
15
15
  var providersWithResults=Object.entries(searchResults).filter(function(_ref7){var _ref8=_slicedToArray(_ref7,2),_=_ref8[0],providerResults=_ref8[1];return providerResults.tot_result_count>0});if(providersWithResults.length===1&&providersWithResults[0][1].tot_result_count===1){var group=providersWithResults[0][1].results[0];_this.selectPlaceResult(providersWithResults[0][0],group,group.items[0])}}return{searchResults:searchResults,pendingSearches:newPendingSearches}})},axios)})});_defineProperty(_this,"filterProviderResults",function(results){if(!_this.state.filterGeometry){return results}var filterPolygon=_this.state.filterGeometry.coordinates[0];return results.map(function(group){var _group$type4;var resultType=(_group$type4=group.type)!==null&&_group$type4!==void 0?_group$type4:SearchResultType.PLACE;if(resultType!==SearchResultType.PLACE){return group}var newItems=group.items.filter(function(item){var _item$crs;var geometry=null;var itemCrs=(_item$crs=item.crs)!==null&&_item$crs!==void 0?_item$crs:_this.props.map.projection;if(item.geometry){geometry=VectorLayerUtils.reprojectGeometry(item.geometry,itemCrs,_this.props.map.projection)}else{geometry={type:"Point",coordinates:CoordinatesUtils.reproject([item.x,item.y],itemCrs,_this.props.map.projection)}}if(geometry.type==="Polygon"){return polygonIntersectTest(geometry.coordinates[0],filterPolygon)}else if(item.bbox){var _CoordinatesUtils$rep=CoordinatesUtils.reprojectBbox(item.bbox,itemCrs,_this.props.map.projection),_CoordinatesUtils$rep2=_slicedToArray(_CoordinatesUtils$rep,4),xmin=_CoordinatesUtils$rep2[0],ymin=_CoordinatesUtils$rep2[1],xmax=_CoordinatesUtils$rep2[2],ymax=_CoordinatesUtils$rep2[3];return polygonIntersectTest([[xmin,ymin],[xmax,ymin],[xmax,ymax],[xmin,ymax],[xmin,ymin]],filterPolygon)}else if(geometry.type==="Point"){return pointInPolygon(geometry.coordinates,filterPolygon)}return true});return newItems.length>0?_objectSpread(_objectSpread({},group),{},{items:newItems}):null}).filter(Boolean)});_defineProperty(_this,"updateRecentSearches",function(){var text=_this.state.searchResults.query_text;if(text&&!_this.state.recentSearches.includes(text)){_this.setState(function(state){return{recentSearches:[text].concat(_toConsumableArray(state.recentSearches.slice(0,4)))}})}});_defineProperty(_this,"blur",function(){if(_this.searchBox){_this.searchBox.blur()}});_defineProperty(_this,"addThemeLayers",function(layer){// Check if layer is already in the LayerTree
16
16
  var sublayers=LayerUtils.getSublayerNames(layer);var existing=_this.props.layers.find(function(l){return l.type===layer.type&&l.url===layer.url&&!isEmpty(LayerUtils.getSublayerNames(l).filter(function(v){return sublayers.includes(v)}))});if(existing){var existingLayerName=(layer.sublayers||[]).length===1?layer.sublayers[0].title:layer.title;var text=LocaleUtils.tr("search.existinglayer")+": "+existingLayerName;_this.props.showNotification("existinglayer",text)}else{_this.props.addLayer(_objectSpread(_objectSpread({},layer),{},{role:LayerRole.USERLAYER}))}if(_this.props.searchOptions.zoomToLayers&&layer.bbox){_this.props.zoomToExtent(layer.bbox.bounds,layer.bbox.crs)}// Show layer tree to notify user that something has happened
17
- _this.props.setCurrentTask("LayerTree")});_defineProperty(_this,"showResultGeometry",function(item,response){var _ref10,_response$bbox,_item$crs3;var scale=arguments.length>2&&arguments[2]!==undefined?arguments[2]:undefined;if(response!==null&&response!==void 0&&response.feature){var _response$feature$fea;var features=(_response$feature$fea=response.feature.features)!==null&&_response$feature$fea!==void 0?_response$feature$fea:[response.feature];var layer={id:"searchselection",role:LayerRole.SELECTION};features.forEach(function(feature){var _response$crs,_feature$geometry;feature.geometry=VectorLayerUtils.reprojectGeometry(feature.geometry,(_response$crs=response.crs)!==null&&_response$crs!==void 0?_response$crs:_this.props.map.projection,_this.props.map.projection);feature.styleName=((_feature$geometry=feature.geometry)===null||_feature$geometry===void 0?void 0:_feature$geometry.type)==="Point"?"marker":"default";feature.styleOptions=_this.props.searchOptions.highlightStyle||{}});// If first feature is not a point(=marker), add a marker
17
+ _this.props.setCurrentTask("LayerTree")});_defineProperty(_this,"showResultGeometry",function(item,response){var _ref10,_response$bbox,_item$crs3;var scale=arguments.length>2&&arguments[2]!==undefined?arguments[2]:undefined;if(response!==null&&response!==void 0&&response.feature){var _response$feature$fea;var features=(_response$feature$fea=response.feature.features)!==null&&_response$feature$fea!==void 0?_response$feature$fea:[response.feature];var layer={id:"searchselection",role:LayerRole.SELECTION};features.forEach(function(feature){var _response$crs,_feature$geometry,_feature$crs;feature.geometry=VectorLayerUtils.reprojectGeometry(feature.geometry,(_response$crs=response.crs)!==null&&_response$crs!==void 0?_response$crs:_this.props.map.projection,_this.props.map.projection);feature.styleName=((_feature$geometry=feature.geometry)===null||_feature$geometry===void 0?void 0:_feature$geometry.type)==="Point"?"marker":"default";feature.styleOptions=_this.props.searchOptions.highlightStyle||{};if((_feature$crs=feature.crs)!==null&&_feature$crs!==void 0&&(_feature$crs=_feature$crs.properties)!==null&&_feature$crs!==void 0&&_feature$crs.name){feature.crs=CoordinatesUtils.fromOgcUrnCrs(feature.crs.properties.name)}});// If first feature is not a point(=marker), add a marker
18
18
  if(features[0].styleName!=="marker"&&!response.hidemarker){var _response$center,_item$crs2;features.unshift({geometry:{type:"Point",coordinates:CoordinatesUtils.reproject((_response$center=response.center)!==null&&_response$center!==void 0?_response$center:[item.x,item.y],(_item$crs2=item.crs)!==null&&_item$crs2!==void 0?_item$crs2:_this.props.map.projection,_this.props.map.projection)},styleName:"marker"})}// Label first feature
19
19
  if(!_this.props.searchOptions.hideResultLabels){var _ref9,_item$label;var label=((_ref9=(_item$label=item.label)!==null&&_item$label!==void 0?_item$label:item.text)!==null&&_ref9!==void 0?_ref9:"").replace(/<\/?\w+\s*\/?>/g,"");features[0].properties=_objectSpread(_objectSpread({},features[0].properties),{},{label:label})}// Mark first feature as searchmarker
20
20
  features[0].id="searchmarker";_this.props.addLayerFeatures(layer,features,true)}var bbox=(_ref10=(_response$bbox=response.bbox)!==null&&_response$bbox!==void 0?_response$bbox:item.bbox)!==null&&_ref10!==void 0?_ref10:[item.x,item.y,item.x,item.y];bbox=CoordinatesUtils.reprojectBbox(bbox,(_item$crs3=item.crs)!==null&&_item$crs3!==void 0?_item$crs3:_this.props.map.projection,_this.props.map.projection);_this.zoomToResultBBox(bbox,scale)});_defineProperty(_this,"zoomToResultBBox",function(bbox,scale){var zoom=0;if(scale){zoom=MapUtils.computeZoom(_this.props.map.scales,scale)}else{var maxZoom=MapUtils.computeZoom(_this.props.map.scales,_this.props.theme.minSearchScaleDenom||_this.props.searchOptions.minScaleDenom);if(bbox[0]!==bbox[2]&&bbox[1]!==bbox[3]){zoom=Math.max(0,MapUtils.getZoomForExtent(bbox,_this.props.map.resolutions,_this.props.map.size,0,maxZoom+1)-1)}else{zoom=maxZoom}}var x=0.5*(bbox[0]+bbox[2]);var y=0.5*(bbox[1]+bbox[3]);_this.props.zoomToPoint([x,y],zoom,_this.props.map.projection)});_defineProperty(_this,"showFeatureGeometry",function(data){var scale=arguments.length>1&&arguments[1]!==undefined?arguments[1]:undefined;var label=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"";// Zoom to bbox
@@ -5,8 +5,8 @@ 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 React from"react";import{connect}from"react-redux";import ol from"openlayers";import PropTypes from"prop-types";import{setLayerLoading}from"../../actions/layers";import CoordinatesUtils from"../../utils/CoordinatesUtils";import MapUtils from"../../utils/MapUtils";import Signal from"../../utils/Signal";import LayerRegistry from"./layers/index";export var OlLayerAdded=new Signal;export var OlLayerUpdated=new Signal;var OlLayer=/*#__PURE__*/function(_React$Component){function OlLayer(props){var _this;_classCallCheck(this,OlLayer);_this=_callSuper(this,OlLayer,[props]);_defineProperty(_this,"makeOptions",function(options){var _options$opacity,_options$visibility;var projection=options.srs||options.crs||options.projection||_this.props.projection;return _objectSpread(_objectSpread({},options),{},{projection:projection,opacity:(_options$opacity=options.opacity)!==null&&_options$opacity!==void 0?_options$opacity:255,visibility:(_options$visibility=options.visibility)!==null&&_options$visibility!==void 0?_options$visibility:true,minResolution:typeof options.minScale==="number"?MapUtils.getResolutionsForScales([options.minScale],projection)[0]:undefined,maxResolution:typeof options.maxScale==="number"?MapUtils.getResolutionsForScales([options.maxScale],projection)[0]:undefined})});_defineProperty(_this,"createLayer",function(options){if(options.type==="group"){_this.layer=new ol.layer.Group({zIndex:_this.props.zIndex});_this.layer.setLayers(new ol.Collection(options.items.map(function(item){var layerCreator=LayerRegistry[item.type];if(layerCreator){var sublayer=layerCreator.create(_this.makeOptions(item),_this.props.map);sublayer.set("id",options.id+"#"+item.name);return sublayer}else{return null}}).filter(function(x){return x})))}else{var layerCreator=LayerRegistry[options.type];if(layerCreator){_this.layer=layerCreator.create(options,_this.props.map)}}if(_this.layer){_this.layer.set("id",options.id);// WMS layer handles visibility and opacity internally
9
- if(options.type!=="wms"){_this.layer.setVisible(_this.layer.get("empty")!==true&&options.visibility);_this.layer.setOpacity(options.opacity/255)}_this.layer.setZIndex(_this.props.zIndex);_this.addLayer(_this.layer,options)}});_defineProperty(_this,"updateLayer",function(newOptions,oldOptions){// optimization to avoid to update the layer if not necessary
10
- if(newOptions===oldOptions){return}var layerCreator=LayerRegistry[_this.props.options.type];if(layerCreator&&layerCreator.update){layerCreator.update(_this.layer,newOptions,oldOptions,_this.props.map);OlLayerUpdated.notify(_this.layer)}});_defineProperty(_this,"addLayer",function(layer,options){_this.props.map.addLayer(layer);OlLayerAdded.notify(layer);layer.on("prerender",function(event){var ctx=event.context;ctx.save();ctx.beginPath();if(_this.props.swipe!==null&&_this.props.swipe!==undefined){var width=ctx.canvas.width*(_this.props.swipe/100);ctx.rect(0,0,width,ctx.canvas.height);ctx.clip()}});layer.on("postrender",function(event){event.context.restore()});if(options.zoomToExtent&&options.bbox&&options.bbox.bounds){var map=_this.props.map;var extent=CoordinatesUtils.reprojectBbox(options.bbox.bounds,options.bbox.crs,map.getView().getProjection());try{map.getView().fit(extent,map.getSize())}catch(e){/* pass */}}var sublayers={};if(layer instanceof ol.layer.Group){layer.getLayers().forEach(function(sublayer){sublayers[options.id+"#"+sublayer.get("id")]=sublayer})}else{sublayers[options.id]=layer}Object.entries(sublayers).map(function(_ref){var _ref2=_slicedToArray(_ref,2),id=_ref2[0],sublayer=_ref2[1];if(sublayer.getSource()&&sublayer.getSource().getImageLoadFunction){sublayer.getSource().on("imageloadstart",function(){_this.props.setLayerLoading(id,true)});sublayer.getSource().on("imageloadend",function(){_this.props.setLayerLoading(id,false)});sublayer.getSource().on("imageloaderror",function(){_this.props.setLayerLoading(id,false)})}else if(sublayer.getSource()&&sublayer.getSource().getTileLoadFunction){sublayer.getSource().on("tileloadstart",function(){if(_this.tilestoload===0){_this.props.setLayerLoading(id,true)}_this.tilestoload++});sublayer.getSource().on("tileloadend",function(){_this.tilestoload--;if(_this.tilestoload===0){_this.props.setLayerLoading(id,false)}});sublayer.getSource().on("tileloaderror",function(){_this.tilestoload--;if(_this.tilestoload===0){_this.props.setLayerLoading(id,false)}})}else if(sublayer.getSource()&&sublayer.getSource()instanceof ol.source.Vector&&sublayer.getSource().getUrl()){sublayer.getSource().on("featuresloadstart",function(){_this.props.setLayerLoading(id,true)});sublayer.getSource().on("featuresloadend",function(){_this.props.setLayerLoading(id,false)});sublayer.getSource().on("featuresloaderror",function(){_this.props.setLayerLoading(id,false)})}})});_this.layer=null;return _this}_inherits(OlLayer,_React$Component);return _createClass(OlLayer,[{key:"componentDidMount",value:function componentDidMount(){this.tilestoload=0;this.createLayer(this.makeOptions(this.props.options))}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){if(!this.layer){return}var newOptions=this.makeOptions(this.props.options);var oldOptions=this.makeOptions(prevProps.options);this.updateLayer(newOptions,oldOptions);// WMS layer handles visibility and opacity internally
11
- if(newOptions.type!=="wms"){this.layer.setVisible(newOptions.visibility);this.layer.setOpacity(newOptions.opacity/255)}this.layer.setZIndex(this.props.zIndex);if(this.props.swipe!==prevProps.swipe){this.props.map.render()}}},{key:"componentWillUnmount",value:function componentWillUnmount(){if(this.layer&&this.props.map){this.props.map.removeLayer(this.layer)}}},{key:"render",value:function render(){var layerCreator=LayerRegistry[this.props.options.type];if(layerCreator&&layerCreator.render){// NOTE: required for Google Maps layer
12
- return layerCreator.render(this.props.options,this.props.map,this.layer)}return null}}])}(React.Component);_defineProperty(OlLayer,"propTypes",{map:PropTypes.object,options:PropTypes.object,projection:PropTypes.string,setLayerLoading:PropTypes.func,swipe:PropTypes.number,zIndex:PropTypes.number});export default connect(function(){return{}},{setLayerLoading:setLayerLoading})(OlLayer);
8
+ */import React from"react";import{connect}from"react-redux";import ol from"openlayers";import PropTypes from"prop-types";import{refreshLayer,setLayerLoading}from"../../actions/layers";import CoordinatesUtils from"../../utils/CoordinatesUtils";import LayerUtils from"../../utils/LayerUtils";import MapUtils from"../../utils/MapUtils";import Signal from"../../utils/Signal";import LayerRegistry from"./layers/index";export var OlLayerAdded=new Signal;export var OlLayerUpdated=new Signal;var OlLayer=/*#__PURE__*/function(_React$Component){function OlLayer(props){var _this;_classCallCheck(this,OlLayer);_this=_callSuper(this,OlLayer,[props]);_defineProperty(_this,"makeOptions",function(options){var _options$opacity,_options$visibility;var projection=options.srs||options.crs||options.projection||_this.props.projection;return _objectSpread(_objectSpread({},options),{},{projection:projection,opacity:(_options$opacity=options.opacity)!==null&&_options$opacity!==void 0?_options$opacity:255,visibility:(_options$visibility=options.visibility)!==null&&_options$visibility!==void 0?_options$visibility:true,minResolution:typeof options.minScale==="number"?MapUtils.getResolutionsForScales([options.minScale],projection)[0]:undefined,maxResolution:typeof options.maxScale==="number"?MapUtils.getResolutionsForScales([options.maxScale],projection)[0]:undefined})});_defineProperty(_this,"createLayer",function(options){if(options.type==="group"){_this.layer=new ol.layer.Group({zIndex:_this.props.zIndex});_this.layer.setLayers(new ol.Collection(options.items.map(function(item){var layerCreator=LayerRegistry[item.type];if(layerCreator){var sublayer=layerCreator.create(_this.makeOptions(item),_this.props.map);sublayer.set("id",options.id+"#"+item.name);return sublayer}else{return null}}).filter(function(x){return x})))}else{var layerCreator=LayerRegistry[options.type];if(layerCreator){_this.layer=layerCreator.create(options,_this.props.map)}}if(_this.layer){_this.layer.set("id",options.id);// WMS layer handles visibility and opacity internally
9
+ if(options.type!=="wms"){_this.layer.setVisible(_this.layer.get("empty")!==true&&options.visibility);_this.layer.setOpacity(options.opacity/255)}_this.layer.setZIndex(_this.props.zIndex);_this.addLayer(_this.layer,options);var refreshInterval=LayerUtils.getLayerRefreshInterval(options);if(refreshInterval>0&&options.visibility){_this.updateInterval=setInterval(function(){_this.props.refreshLayer(function(layer){return layer.id===options.id})},refreshInterval)}}});_defineProperty(_this,"updateLayer",function(newOptions,oldOptions){// optimization to avoid to update the layer if not necessary
10
+ if(newOptions===oldOptions){return}var layerCreator=LayerRegistry[_this.props.options.type];if(layerCreator&&layerCreator.update){layerCreator.update(_this.layer,newOptions,oldOptions,_this.props.map);OlLayerUpdated.notify(_this.layer)}var oldRefreshInterval=LayerUtils.getLayerRefreshInterval(oldOptions);var newRefreshInterval=LayerUtils.getLayerRefreshInterval(newOptions);if(oldRefreshInterval!==newRefreshInterval||oldOptions.visibility!==newOptions.visibility){clearInterval(_this.updateInterval);_this.updateInterval=null;if(newRefreshInterval&&newOptions.visibility){_this.updateInterval=setInterval(function(){_this.props.refreshLayer(function(layer){return layer.id===newOptions.id})},newRefreshInterval)}}});_defineProperty(_this,"addLayer",function(layer,options){_this.props.map.addLayer(layer);OlLayerAdded.notify(layer);layer.on("prerender",function(event){var ctx=event.context;ctx.save();ctx.beginPath();if(_this.props.swipe!==null&&_this.props.swipe!==undefined){var width=ctx.canvas.width*(_this.props.swipe/100);ctx.rect(0,0,width,ctx.canvas.height);ctx.clip()}});layer.on("postrender",function(event){event.context.restore()});if(options.zoomToExtent&&options.bbox&&options.bbox.bounds){var map=_this.props.map;var extent=CoordinatesUtils.reprojectBbox(options.bbox.bounds,options.bbox.crs,map.getView().getProjection());try{map.getView().fit(extent,map.getSize())}catch(e){/* pass */}}var sublayers={};if(layer instanceof ol.layer.Group){layer.getLayers().forEach(function(sublayer){sublayers[options.id+"#"+sublayer.get("id")]=sublayer})}else{sublayers[options.id]=layer}Object.entries(sublayers).map(function(_ref){var _ref2=_slicedToArray(_ref,2),id=_ref2[0],sublayer=_ref2[1];if(sublayer.getSource()&&sublayer.getSource().getImageLoadFunction){sublayer.getSource().on("imageloadstart",function(){_this.props.setLayerLoading(id,true)});sublayer.getSource().on("imageloadend",function(){_this.props.setLayerLoading(id,false)});sublayer.getSource().on("imageloaderror",function(){_this.props.setLayerLoading(id,false)})}else if(sublayer.getSource()&&sublayer.getSource().getTileLoadFunction){sublayer.getSource().on("tileloadstart",function(){if(_this.tilestoload===0){_this.props.setLayerLoading(id,true)}_this.tilestoload++});sublayer.getSource().on("tileloadend",function(){_this.tilestoload--;if(_this.tilestoload===0){_this.props.setLayerLoading(id,false)}});sublayer.getSource().on("tileloaderror",function(){_this.tilestoload--;if(_this.tilestoload===0){_this.props.setLayerLoading(id,false)}})}else if(sublayer.getSource()&&sublayer.getSource()instanceof ol.source.Vector&&sublayer.getSource().getUrl()){sublayer.getSource().on("featuresloadstart",function(){_this.props.setLayerLoading(id,true)});sublayer.getSource().on("featuresloadend",function(){_this.props.setLayerLoading(id,false)});sublayer.getSource().on("featuresloaderror",function(){_this.props.setLayerLoading(id,false)})}})});_this.layer=null;_this.updateInterval=null;return _this}_inherits(OlLayer,_React$Component);return _createClass(OlLayer,[{key:"componentDidMount",value:function componentDidMount(){this.tilestoload=0;this.createLayer(this.makeOptions(this.props.options))}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){if(!this.layer){return}var newOptions=this.makeOptions(this.props.options);var oldOptions=this.makeOptions(prevProps.options);this.updateLayer(newOptions,oldOptions);// WMS layer handles visibility and opacity internally
11
+ if(newOptions.type!=="wms"){this.layer.setVisible(newOptions.visibility);this.layer.setOpacity(newOptions.opacity/255)}this.layer.setZIndex(this.props.zIndex);if(this.props.swipe!==prevProps.swipe){this.props.map.render()}}},{key:"componentWillUnmount",value:function componentWillUnmount(){if(this.layer&&this.props.map){this.props.map.removeLayer(this.layer)}clearInterval(this.updateInterval)}},{key:"render",value:function render(){var layerCreator=LayerRegistry[this.props.options.type];if(layerCreator&&layerCreator.render){// NOTE: required for Google Maps layer
12
+ return layerCreator.render(this.props.options,this.props.map,this.layer)}return null}}])}(React.Component);_defineProperty(OlLayer,"propTypes",{map:PropTypes.object,options:PropTypes.object,projection:PropTypes.string,refreshLayer:PropTypes.func,setLayerLoading:PropTypes.func,swipe:PropTypes.number,zIndex:PropTypes.number});export default connect(function(){return{}},{setLayerLoading:setLayerLoading,refreshLayer:refreshLayer})(OlLayer);
@@ -4,4 +4,4 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
4
4
  *
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
- */import axios from"axios";import{applyStyle}from"ol-mapbox-style";import ol from"openlayers";export default{create:function create(options){var createLayer=function createLayer(){return new ol.layer.VectorTile(_objectSpread({minResolution:options.minResolution,maxResolution:options.maxResolution,declutter:options.declutter,source:new ol.source.VectorTile(_objectSpread({projection:options.projection,format:new ol.format.MVT({}),url:options.url,tileGrid:options.tileGridConfig?new ol.tilegrid.TileGrid(_objectSpread({},options.tileGridConfig)):undefined},options.sourceConfig||{}))},options.layerConfig||{}))};var group=new ol.layer.Group;if(options.style){axios.get(options.style).then(function(response){var glStyle=response.data;Object.keys(glStyle.sources).forEach(function(styleSource){var layer=createLayer();applyStyle(layer,glStyle,styleSource,options.styleOptions).then(function(){group.getLayers().push(layer)})})})}else{group.getLayers().push(createLayer())}return group}};
7
+ */import axios from"axios";import{applyStyle}from"ol-mapbox-style";import ol from"openlayers";export default{create:function create(options){var createLayer=function createLayer(){return new ol.layer.VectorTile(_objectSpread({minResolution:options.minResolution,maxResolution:options.maxResolution,declutter:options.declutter,source:new ol.source.VectorTile(_objectSpread({projection:options.projection,format:new ol.format.MVT({}),url:options.url,tileGrid:options.tileGridConfig?new ol.tilegrid.TileGrid(_objectSpread({},options.tileGridConfig)):undefined},options.sourceConfig||{}))},options.layerConfig||{}))};var group=new ol.layer.Group;if(options.style){axios.get(options.style).then(function(response){var glStyle=response.data;if(glStyle.sprite.startsWith(".")){glStyle.sprite=new URL(glStyle.sprite,options.style).href}if(glStyle.glyphs.startsWith(".")){glStyle.glyphs=new URL(glStyle.glyphs,options.style).href}Object.keys(glStyle.sources).forEach(function(styleSource){if(glStyle.sources[styleSource].url.startsWith(".")){glStyle.sources[styleSource].url=new URL(glStyle.sources[styleSource].url,options.style).href}var layer=createLayer();applyStyle(layer,glStyle,styleSource,options.styleOptions).then(function(){group.getLayers().push(layer)})})})}else{group.getLayers().push(createLayer())}return group}};
@@ -5,5 +5,5 @@ 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 ol from"openlayers";import ConfigUtils from"../../../utils/ConfigUtils";import CoordinatesUtils from"../../../utils/CoordinatesUtils";function getWMSURLs(urls){return urls.map(function(url){return url.split("?")[0]})}export function createWMTSSource(options){var _options$style,_options$wrapX,_options$requestEncod;var urls=getWMSURLs(Array.isArray(options.url)?options.url:[options.url]).map(function(url){if(options.rev){return url+"?"+options.rev}else{return url}});var projection=ol.proj.get(options.projection);var resolutions=options.resolutions;var matrixIds=new Array(options.resolutions.length);// generate matrixIds arrays for this WMTS
9
- for(var z=0;z<options.resolutions.length;++z){matrixIds[z]=options.tileMatrixPrefix!==""?options.tileMatrixPrefix+":"+z:z}var extent=options.bbox?CoordinatesUtils.reprojectBbox(options.bbox.bounds,options.bbox.crs,options.projection):null;return new ol.source.WMTS(_objectSpread({urls:urls,layer:options.name,format:options.format,projection:projection?projection:null,matrixSet:options.tileMatrixSet,tileGrid:new ol.tilegrid.WMTS({extent:extent,origin:[options.originX,options.originY],resolutions:resolutions,matrixIds:matrixIds,tileSize:options.tileSize||[256,256]}),style:(_options$style=options.style)!==null&&_options$style!==void 0?_options$style:"",wrapX:(_options$wrapX=options.wrapX)!==null&&_options$wrapX!==void 0?_options$wrapX:false,requestEncoding:(_options$requestEncod=options.requestEncoding)!==null&&_options$requestEncod!==void 0?_options$requestEncod:"REST"},options.sourceConfig||{}))}export default{create:function create(options){return new ol.layer.Tile(_objectSpread({minResolution:options.minResolution,maxResolution:options.maxResolution,preload:ConfigUtils.getConfigProp("tilePreloadLevels",null,0),source:createWMTSSource(options)},options.layerConfig||{}))},update:function update(layer,newOptions,oldOptions){if(newOptions.rev!==oldOptions.rev){layer.setSource(createWMTSSource(newOptions))}}};
8
+ */import ol from"openlayers";import ConfigUtils from"../../../utils/ConfigUtils";import CoordinatesUtils from"../../../utils/CoordinatesUtils";function getWMSURLs(urls){return urls.map(function(url){return url.split("?")[0]})}export function createWMTSSource(options){var _options$layerName,_options$matrixIds,_options$style,_options$wrapX,_options$requestEncod;var urls=getWMSURLs(Array.isArray(options.url)?options.url:[options.url]).map(function(url){if(options.rev){return url+"?"+options.rev}else{return url}});var projection=ol.proj.get(options.projection);var resolutions=options.resolutions;var matrixIds=new Array(options.resolutions.length);// generate matrixIds arrays for this WMTS
9
+ for(var z=0;z<options.resolutions.length;++z){matrixIds[z]=options.tileMatrixPrefix!==""?options.tileMatrixPrefix+":"+z:z}var extent=options.bbox?CoordinatesUtils.reprojectBbox(options.bbox.bounds,options.bbox.crs,options.projection):null;return new ol.source.WMTS(_objectSpread({urls:urls,layer:(_options$layerName=options.layerName)!==null&&_options$layerName!==void 0?_options$layerName:options.name,format:options.format,projection:projection?projection:null,matrixSet:options.tileMatrixSet,tileGrid:new ol.tilegrid.WMTS({extent:extent,origin:[options.originX,options.originY],resolutions:resolutions,matrixIds:(_options$matrixIds=options.matrixIds)!==null&&_options$matrixIds!==void 0?_options$matrixIds:matrixIds,tileSize:options.tileSize||[256,256]}),style:(_options$style=options.style)!==null&&_options$style!==void 0?_options$style:"",wrapX:(_options$wrapX=options.wrapX)!==null&&_options$wrapX!==void 0?_options$wrapX:false,requestEncoding:(_options$requestEncod=options.requestEncoding)!==null&&_options$requestEncod!==void 0?_options$requestEncod:"REST"},options.sourceConfig||{}))}export default{create:function create(options){return new ol.layer.Tile(_objectSpread({minResolution:options.minResolution,maxResolution:options.maxResolution,preload:ConfigUtils.getConfigProp("tilePreloadLevels",null,0),source:createWMTSSource(options)},options.layerConfig||{}))},update:function update(layer,newOptions,oldOptions){if(newOptions.rev!==oldOptions.rev){layer.setSource(createWMTSSource(newOptions))}}};
@@ -4,7 +4,7 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
4
4
  *
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
- */import React from"react";import PropTypes from"prop-types";import{Group}from"three";import{v4 as uuidv4}from"uuid";import LocaleUtils from"../../utils/LocaleUtils";import Icon from"../Icon";import TaskBar from"../TaskBar";import ButtonBar from"../widgets/ButtonBar";import CreateTool3D from"./drawtool/CreateTool3D";import EditTool3D from"./drawtool/EditTool3D";import"./style/Draw3D.css";var Draw3D=/*#__PURE__*/function(_React$Component){function Draw3D(){var _this;_classCallCheck(this,Draw3D);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,Draw3D,[].concat(args));_defineProperty(_this,"state",{action:null,baseSize:10,color:[255,105,0,1],geomType:null,drawGroupId:"",selectedObject:null});_defineProperty(_this,"onShow",function(){// Ensure a draw group is present
8
- var drawGroup=Object.entries(_this.props.sceneContext.sceneObjects).find(function(_ref){var _ref2=_slicedToArray(_ref,2),key=_ref2[0],options=_ref2[1];return options.drawGroup===true});if(drawGroup===undefined){_this.addDrawGroup(LocaleUtils.tr("draw3d.drawings"))}else{_this.setState({drawGroupId:drawGroup[0]})}_this.setState({action:"Pick"})});_defineProperty(_this,"onHide",function(){// Remove empty draw groups
9
- Object.entries(_this.props.sceneContext.sceneObjects).filter(function(_ref3){var _ref4=_slicedToArray(_ref3,2),objectId=_ref4[0],options=_ref4[1];return options.drawGroup===true}).forEach(function(_ref5){var _ref6=_slicedToArray(_ref5,2),objectId=_ref6[0],options=_ref6[1];var object=_this.props.sceneContext.getSceneObject(objectId);if(object.children.length===0){_this.props.sceneContext.removeSceneObject(objectId)}});_this.setState({selectedObject:null})});_defineProperty(_this,"createDrawGroup",function(){var message=LocaleUtils.tr("draw3d.newgroupprompt");// eslint-disable-next-line
10
- var name=prompt(message);if(name){_this.addDrawGroup(name)}});_defineProperty(_this,"addDrawGroup",function(name){var objectId=uuidv4();var options={drawGroup:true,layertree:true,title:name};_this.props.sceneContext.addSceneObject(objectId,new Group,options);_this.setState({drawGroupId:objectId})});_defineProperty(_this,"renderBody",function(){var activeButton=_this.state.action==="Create"?_this.state.geomType:_this.state.action;var drawButtons=[{key:"Cuboid",tooltip:LocaleUtils.tr("draw3d.cuboid"),icon:"cuboid",data:{action:"Create",geomType:"Cuboid"}},{key:"Wedge",tooltip:LocaleUtils.tr("draw3d.wedge"),icon:"wedge",data:{action:"Create",geomType:"Wedge"}},{key:"Cylinder",tooltip:LocaleUtils.tr("draw3d.cylinder"),icon:"cylinder",data:{action:"Create",geomType:"Cylinder"}},[{key:"Pyramid",tooltip:LocaleUtils.tr("draw3d.pyramid"),icon:"pyramid",data:{action:"Create",geomType:"Pyramid"}},{key:"Sphere",tooltip:LocaleUtils.tr("draw3d.sphere"),icon:"sphere",data:{action:"Create",geomType:"Sphere"}},{key:"Cone",tooltip:LocaleUtils.tr("draw3d.cone"),icon:"cone",data:{action:"Create",geomType:"Cone"}}]];var editButtons=[{key:"Pick",tooltip:LocaleUtils.tr("draw3d.pick"),icon:"nodetool",data:{action:"Pick",geomType:null}},{key:"Delete",tooltip:LocaleUtils.tr("draw3d.delete"),icon:"trash",data:{action:"Delete",geomType:null},disabled:!_this.state.selectedObject}];var drawGroups=Object.entries(_this.props.sceneContext.sceneObjects).filter(function(_ref7){var _ref8=_slicedToArray(_ref7,2),key=_ref8[0],entry=_ref8[1];return entry.drawGroup===true});return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("div",{className:"redlining-buttongroups"},/*#__PURE__*/React.createElement("div",{className:"redlining-group"},/*#__PURE__*/React.createElement("div",null,LocaleUtils.tr("redlining.layer")),/*#__PURE__*/React.createElement("div",{className:"controlgroup"},/*#__PURE__*/React.createElement("select",{onChange:function onChange(ev){return _this.setState({drawGroupId:ev.target.value})},value:_this.state.drawGroupId},drawGroups.map(function(_ref9){var _ref10=_slicedToArray(_ref9,2),objectId=_ref10[0],options=_ref10[1];return/*#__PURE__*/React.createElement("option",{key:objectId,value:objectId},options.title)})),/*#__PURE__*/React.createElement("button",{className:"button",onClick:_this.createDrawGroup},/*#__PURE__*/React.createElement(Icon,{icon:"plus"})))),/*#__PURE__*/React.createElement("div",{className:"redlining-group"},/*#__PURE__*/React.createElement("div",null,LocaleUtils.tr("redlining.draw")),/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement(ButtonBar,{active:activeButton,buttons:drawButtons,onClick:function onClick(key,data){return _this.actionChanged(data)}}))),/*#__PURE__*/React.createElement("div",{className:"redlining-group"},/*#__PURE__*/React.createElement("div",null,LocaleUtils.tr("redlining.edit")),/*#__PURE__*/React.createElement(ButtonBar,{active:activeButton,buttons:editButtons,onClick:function onClick(key,data){return _this.actionChanged(data)}}))),_this.renderControl())});_defineProperty(_this,"renderControl",function(){if(_this.state.action==="Create"){return/*#__PURE__*/React.createElement(CreateTool3D,{baseSize:_this.state.baseSize,baseSizeChanged:function baseSizeChanged(baseSize){return _this.setState({baseSize:baseSize})},color:_this.state.color,colorChanged:function colorChanged(color){return _this.setState({color:color})},drawGroupId:_this.state.drawGroupId,geomType:_this.state.geomType,objectCreated:_this.objectCreated,sceneContext:_this.props.sceneContext})}else if(_this.state.action==="Pick"){return/*#__PURE__*/React.createElement(EditTool3D,{color:_this.state.color,colorChanged:function colorChanged(color){return _this.setState({color:color})},drawGroupId:_this.state.drawGroupId,objectPicked:_this.objectPicked,sceneContext:_this.props.sceneContext,selectedObject:_this.state.selectedObject})}return null});_defineProperty(_this,"actionChanged",function(data){if(data.action==="Delete"){_this.deleteSelectedObject()}else{_this.setState({action:data.action,geomType:data.geomType,selectedObject:null})}});_defineProperty(_this,"deleteSelectedObject",function(){var group=_this.props.sceneContext.getSceneObject(_this.state.drawGroupId);var parent=null;group.traverse(function(c){if(c===_this.state.selectedObject){parent=c.parent}});if(parent){parent.remove(_this.state.selectedObject);while(parent.parent&&!parent.isMesh&&parent.children.length===0&&parent!==group){var grandparent=parent.parent;grandparent.remove(parent);parent=grandparent}_this.setState({action:"Pick",geomType:null,selectedObject:null});_this.props.sceneContext.scene.notifyChange()}});_defineProperty(_this,"objectCreated",function(object){_this.setState({action:"Pick",geomType:null,selectedObject:object})});_defineProperty(_this,"objectPicked",function(object){_this.setState({selectedObject:object})});return _this}_inherits(Draw3D,_React$Component);return _createClass(Draw3D,[{key:"render",value:function render(){var _this2=this;return/*#__PURE__*/React.createElement(TaskBar,{onHide:this.onHide,onShow:this.onShow,task:"Draw3D"},function(){return{body:_this2.renderBody()}})}}])}(React.Component);_defineProperty(Draw3D,"propTypes",{sceneContext:PropTypes.object});export{Draw3D as default};
7
+ */import React from"react";import PropTypes from"prop-types";import{Group}from"three";import{v4 as uuidv4}from"uuid";import LocaleUtils from"../../utils/LocaleUtils";import Icon from"../Icon";import TaskBar from"../TaskBar";import ButtonBar from"../widgets/ButtonBar";import CreateTool3D from"./drawtool/CreateTool3D";import EditTool3D from"./drawtool/EditTool3D";import"./style/Draw3D.css";var Draw3D=/*#__PURE__*/function(_React$Component){function Draw3D(){var _this;_classCallCheck(this,Draw3D);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,Draw3D,[].concat(args));_defineProperty(_this,"state",{action:null,baseSize:10,color:[255,105,0,1],geomType:null,drawGroupId:"",selectedObject:null});_defineProperty(_this,"onShow",function(){_this.ensureDrawGroup();_this.setState({action:"Pick"})});_defineProperty(_this,"onHide",function(){// Remove empty draw groups
8
+ Object.entries(_this.props.sceneContext.sceneObjects).filter(function(_ref){var _ref2=_slicedToArray(_ref,2),objectId=_ref2[0],options=_ref2[1];return options.drawGroup===true}).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),objectId=_ref4[0],options=_ref4[1];var object=_this.props.sceneContext.getSceneObject(objectId);if(object.children.length===0){_this.props.sceneContext.removeSceneObject(objectId)}});_this.setState({selectedObject:null})});_defineProperty(_this,"ensureDrawGroup",function(){// Ensure a draw group is present
9
+ var drawGroup=Object.entries(_this.props.sceneContext.sceneObjects).find(function(_ref5){var _ref6=_slicedToArray(_ref5,2),key=_ref6[0],options=_ref6[1];return options.drawGroup===true});if(drawGroup===undefined){_this.addDrawGroup(LocaleUtils.tr("draw3d.drawings"))}else{_this.setState({drawGroupId:drawGroup[0]})}});_defineProperty(_this,"createDrawGroup",function(){var message=LocaleUtils.tr("draw3d.newgroupprompt");// eslint-disable-next-line
10
+ var name=prompt(message);if(name){_this.addDrawGroup(name)}});_defineProperty(_this,"addDrawGroup",function(name){var objectId=uuidv4();var options={drawGroup:true,layertree:true,title:name};_this.props.sceneContext.addSceneObject(objectId,new Group,options);_this.setState({drawGroupId:objectId})});_defineProperty(_this,"renderBody",function(){var activeButton=_this.state.action==="Create"?_this.state.geomType:_this.state.action;var drawButtons=[{key:"Cuboid",tooltip:LocaleUtils.tr("draw3d.cuboid"),icon:"cuboid",data:{action:"Create",geomType:"Cuboid"}},{key:"Wedge",tooltip:LocaleUtils.tr("draw3d.wedge"),icon:"wedge",data:{action:"Create",geomType:"Wedge"}},{key:"Cylinder",tooltip:LocaleUtils.tr("draw3d.cylinder"),icon:"cylinder",data:{action:"Create",geomType:"Cylinder"}},[{key:"Pyramid",tooltip:LocaleUtils.tr("draw3d.pyramid"),icon:"pyramid",data:{action:"Create",geomType:"Pyramid"}},{key:"Sphere",tooltip:LocaleUtils.tr("draw3d.sphere"),icon:"sphere",data:{action:"Create",geomType:"Sphere"}},{key:"Cone",tooltip:LocaleUtils.tr("draw3d.cone"),icon:"cone",data:{action:"Create",geomType:"Cone"}}]];var editButtons=[{key:"Pick",tooltip:LocaleUtils.tr("draw3d.pick"),icon:"nodetool",data:{action:"Pick",geomType:null}},{key:"Delete",tooltip:LocaleUtils.tr("draw3d.delete"),icon:"trash",data:{action:"Delete",geomType:null},disabled:!_this.state.selectedObject}];var drawGroups=Object.entries(_this.props.sceneContext.sceneObjects).filter(function(_ref7){var _ref8=_slicedToArray(_ref7,2),key=_ref8[0],entry=_ref8[1];return entry.drawGroup===true});return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("div",{className:"redlining-buttongroups"},/*#__PURE__*/React.createElement("div",{className:"redlining-group"},/*#__PURE__*/React.createElement("div",null,LocaleUtils.tr("redlining.layer")),/*#__PURE__*/React.createElement("div",{className:"controlgroup"},/*#__PURE__*/React.createElement("select",{onChange:function onChange(ev){return _this.setState({drawGroupId:ev.target.value})},value:_this.state.drawGroupId},drawGroups.map(function(_ref9){var _ref10=_slicedToArray(_ref9,2),objectId=_ref10[0],options=_ref10[1];return/*#__PURE__*/React.createElement("option",{key:objectId,value:objectId},options.title)})),/*#__PURE__*/React.createElement("button",{className:"button",onClick:_this.createDrawGroup},/*#__PURE__*/React.createElement(Icon,{icon:"plus"})))),/*#__PURE__*/React.createElement("div",{className:"redlining-group"},/*#__PURE__*/React.createElement("div",null,LocaleUtils.tr("redlining.draw")),/*#__PURE__*/React.createElement("span",null,/*#__PURE__*/React.createElement(ButtonBar,{active:activeButton,buttons:drawButtons,onClick:function onClick(key,data){return _this.actionChanged(data)}}))),/*#__PURE__*/React.createElement("div",{className:"redlining-group"},/*#__PURE__*/React.createElement("div",null,LocaleUtils.tr("redlining.edit")),/*#__PURE__*/React.createElement(ButtonBar,{active:activeButton,buttons:editButtons,onClick:function onClick(key,data){return _this.actionChanged(data)}}))),_this.renderControl())});_defineProperty(_this,"renderControl",function(){if(_this.state.action==="Create"){return/*#__PURE__*/React.createElement(CreateTool3D,{baseSize:_this.state.baseSize,baseSizeChanged:function baseSizeChanged(baseSize){return _this.setState({baseSize:baseSize})},color:_this.state.color,colorChanged:function colorChanged(color){return _this.setState({color:color})},drawGroupId:_this.state.drawGroupId,geomType:_this.state.geomType,objectCreated:_this.objectCreated,sceneContext:_this.props.sceneContext})}else if(_this.state.action==="Pick"){return/*#__PURE__*/React.createElement(EditTool3D,{color:_this.state.color,colorChanged:function colorChanged(color){return _this.setState({color:color})},drawGroupId:_this.state.drawGroupId,objectPicked:_this.objectPicked,sceneContext:_this.props.sceneContext,selectedObject:_this.state.selectedObject})}return null});_defineProperty(_this,"actionChanged",function(data){if(data.action==="Delete"){_this.deleteSelectedObject()}else{_this.setState({action:data.action,geomType:data.geomType,selectedObject:null})}});_defineProperty(_this,"deleteSelectedObject",function(){var group=_this.props.sceneContext.getSceneObject(_this.state.drawGroupId);var parent=null;group.traverse(function(c){if(c===_this.state.selectedObject){parent=c.parent}});if(parent){parent.remove(_this.state.selectedObject);while(parent.parent&&!parent.isMesh&&parent.children.length===0&&parent!==group){var grandparent=parent.parent;grandparent.remove(parent);parent=grandparent}if(group.children.length===0){_this.props.sceneContext.removeSceneObject(_this.state.drawGroupId,function(){_this.ensureDrawGroup()})}_this.setState({action:"Pick",geomType:null,selectedObject:null});_this.props.sceneContext.scene.notifyChange()}});_defineProperty(_this,"objectCreated",function(object){_this.setState({action:"Pick",geomType:null,selectedObject:object})});_defineProperty(_this,"objectPicked",function(object){_this.setState({selectedObject:object})});return _this}_inherits(Draw3D,_React$Component);return _createClass(Draw3D,[{key:"render",value:function render(){var _this2=this;return/*#__PURE__*/React.createElement(TaskBar,{onHide:this.onHide,onShow:this.onShow,task:"Draw3D"},function(){return{body:_this2.renderBody()}})}}])}(React.Component);_defineProperty(Draw3D,"propTypes",{sceneContext:PropTypes.object});export{Draw3D as default};
@@ -7,14 +7,15 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
7
7
  */import React from"react";import{connect}from"react-redux";import ColorLayer from"@giro3d/giro3d/core/layer/ColorLayer";import DrawTool,{conditions}from"@giro3d/giro3d/interactions/DrawTool";import VectorSource from"@giro3d/giro3d/sources/VectorSource";import FileSaver from"file-saver";import ol from"openlayers";import pointInPolygon from"point-in-polygon";import PropTypes from"prop-types";import{Box3,BufferGeometry,Float32BufferAttribute,Group,Matrix4,Mesh,MeshStandardMaterial,Quaternion,Scene,Vector3}from"three";import{GLTFExporter}from"three/addons/exporters/GLTFExporter.js";import{setCurrentTask}from"../../actions/task";import LocaleUtils from"../../utils/LocaleUtils";import VectorLayerUtils from"../../utils/VectorLayerUtils";import SideBar from"../SideBar";import Spinner from"../widgets/Spinner";var ExportObjects3D=/*#__PURE__*/function(_React$Component){function ExportObjects3D(props){var _this;_classCallCheck(this,ExportObjects3D);_this=_callSuper(this,ExportObjects3D,[props]);_defineProperty(_this,"state",{selectedFormat:"model/gltf+json",minimized:false,exporting:false,exportPolygon:null});_defineProperty(_this,"onShow",function(){_this.abortController=new AbortController;_this.measureTool=new DrawTool({instance:_this.props.sceneContext.scene});_this.drawLayer=new ColorLayer({source:new VectorSource({data:[],format:new ol.format.GeoJSON,style:_this.featureStyleFunction})});_this.props.sceneContext.map.addLayer(_this.drawLayer);_this.restart()});_defineProperty(_this,"onHide",function(){_this.abortController.abort();_this.abortController=null;_this.measureTool.dispose();_this.measureTool=null;_this.props.sceneContext.map.removeLayer(_this.drawLayer,{dispose:true});_this.drawLayer=null});_defineProperty(_this,"formatChanged",function(ev){_this.setState({selectedFormat:ev.target.value})});_defineProperty(_this,"renderBody",function(){var exportDisabled=_this.state.exporting||_this.state.exportPolygon===null;var formatMap={"model/gltf+json":"GLTF"};return/*#__PURE__*/React.createElement("div",{className:"mapexport-body"},/*#__PURE__*/React.createElement("form",{onSubmit:_this.exportArea},/*#__PURE__*/React.createElement("table",{className:"options-table"},/*#__PURE__*/React.createElement("tbody",null,/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("mapexport.format")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{name:"FORMAT",onChange:_this.formatChanged,value:_this.state.selectedFormat},Object.entries(formatMap).map(function(_ref){var _ref2=_slicedToArray(_ref,2),format=_ref2[0],label=_ref2[1];return/*#__PURE__*/React.createElement("option",{key:format,value:format},label)})))))),/*#__PURE__*/React.createElement("div",{className:"button-bar"},/*#__PURE__*/React.createElement("button",{className:"button",disabled:exportDisabled,type:"submit"},_this.state.exporting?/*#__PURE__*/React.createElement("span",{className:"mapexport-wait"},/*#__PURE__*/React.createElement(Spinner,null)," ",LocaleUtils.tr("mapexport.wait")):LocaleUtils.tr("mapexport.submit")))))});_defineProperty(_this,"restart",function(){if(_this.abortController){_this.abortController.abort()}_this.abortController=new AbortController;var pick=function pick(e){return _this.props.sceneContext.scene.pickObjectsAt(e,{sortByDistance:true,where:[_this.props.sceneContext.getMap()]})};var options={signal:_this.abortController.signal,endCondition:conditions.doubleClick,pick:pick};_this.measureTool.createPolygon(options).then(_this.selectArea)["catch"](function(){})});_defineProperty(_this,"selectArea",function(polygon){if(polygon===null){_this.restart();return}_this.drawLayer.source.clear();var polyGeoJson=polygon.toGeoJSON();var feature=new ol.format.GeoJSON().readFeature(polyGeoJson,{dataProjection:"EPSG:4326",featureProjection:_this.props.sceneContext.mapCrs});_this.drawLayer.source.addFeature(feature);_this.props.sceneContext.scene.remove(polygon);_this.setState({exportPolygon:feature.getGeometry().getCoordinates()});// Setup for next selection
8
8
  _this.restart()});_defineProperty(_this,"featureStyleFunction",function(){return[new ol.style.Style({fill:new ol.style.Fill({color:[41,120,180,0.5]})}),new ol.style.Style({stroke:new ol.style.Stroke({color:[255,255,255],width:4})}),new ol.style.Style({stroke:new ol.style.Stroke({color:[41,120,180],width:1.5})})]});_defineProperty(_this,"exportArea",function(ev){ev.preventDefault();if(_this.state.selectedFormat==="model/gltf+json"){_this.exportToGltf()}});_defineProperty(_this,"exportToGltf",function(){_this.setState({exporting:true});var bbox=VectorLayerUtils.computeFeatureBBox({type:"Polygon",coordinates:_this.state.exportPolygon});// Create a bounding box in world space
9
9
  var selectionBox=new Box3().setFromPoints([new Vector3(bbox[0],bbox[1],0),new Vector3(bbox[2],bbox[3],8000)]);var exportGroup=new Group;exportGroup.rotation.set(-Math.PI/2,0,0);// GLTF is Y-UP
10
- Object.entries(_this.props.sceneContext.sceneObjects).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),objectId=_ref4[0],options=_ref4[1];if(!options.layertree||!options.visibility){return}var object=_this.props.sceneContext.getSceneObject(objectId);if(object.tiles){_this.addTileToExportGroup(object.tiles,exportGroup,selectionBox)}else{_this.addObjectToExportGroup(object,exportGroup,selectionBox)}});var exportScene=new Scene;exportScene.add(exportGroup);var exporter=new GLTFExporter;exporter.parse(exportScene,function(gltf){var blob=new Blob([JSON.stringify(gltf)],{type:"application/json"});FileSaver.saveAs(blob,"scene.gltf");_this.setState({exporting:false})})});_defineProperty(_this,"addTileToExportGroup",function(tiles,exportGroup,selectionBox){tiles.group.traverse(function(c){if(c.geometry){var bbox=c.geometry.boundingBox.applyMatrix4(c.matrixWorld);if(!selectionBox.intersectsBox(bbox)){return}var batchidAttr=c.geometry.getAttribute("_batchid");var posAttr=c.geometry.getAttribute("position");var norAttr=c.geometry.getAttribute("normal");var colAttr=c.geometry.getAttribute("color");var colStride=c.material.transparent?4:3;var batches={};batchidAttr.array.forEach(function(batchId,idx){var _batches$batchId$posi,_batches$batchId$norm;if(!batches[batchId]){batches[batchId]={position:[],normal:[],color:colAttr?[]:null,colorStride:colStride,bbox:new Box3}}var pos=posAttr.array.slice(3*idx,3*idx+3);(_batches$batchId$posi=batches[batchId].position).push.apply(_batches$batchId$posi,_toConsumableArray(pos));var nor=norAttr.array.slice(3*idx,3*idx+3);(_batches$batchId$norm=batches[batchId].normal).push.apply(_batches$batchId$norm,_toConsumableArray(nor));if(colAttr){var _batches$batchId$colo;var col=colAttr.array.slice(colStride*idx,colStride*idx+colStride);(_batches$batchId$colo=batches[batchId].color).push.apply(_batches$batchId$colo,_toConsumableArray(col))}batches[batchId].bbox.expandByPoint(_construct(Vector3,_toConsumableArray(pos)).applyMatrix4(c.matrixWorld))});Object.entries(batches).forEach(function(_ref5){var _ref6=_slicedToArray(_ref5,2),batchId=_ref6[0],batch=_ref6[1];if(selectionBox.intersectsBox(batch.bbox)&&_this.bboxInExportPolygon(batch.bbox)){// Get batch table object
10
+ Object.entries(_this.props.sceneContext.sceneObjects).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),objectId=_ref4[0],options=_ref4[1];if(!options.layertree||!options.visibility){return}var object=_this.props.sceneContext.getSceneObject(objectId);if(object.tiles){_this.addTileToExportGroup(object.tiles,exportGroup,selectionBox)}else{_this.addObjectToExportGroup(object,exportGroup,selectionBox)}});var exportScene=new Scene;exportScene.add(exportGroup);var exporter=new GLTFExporter;exporter.parse(exportScene,function(gltf){var blob=new Blob([JSON.stringify(gltf)],{type:"application/json"});FileSaver.saveAs(blob,"scene.gltf");_this.setState({exporting:false})})});_defineProperty(_this,"addTileToExportGroup",function(tiles,exportGroup,selectionBox){tiles.group.traverse(function(c){if(c.geometry){var bbox=c.geometry.boundingBox.applyMatrix4(c.matrixWorld);if(!selectionBox.intersectsBox(bbox)){return}var batchidAttr=c.geometry.getAttribute("_batchid");var posAttr=c.geometry.getAttribute("position");var norAttr=c.geometry.getAttribute("normal");var colAttr=c.geometry.getAttribute("color");var colStride=c.material.transparent?4:3;var batches={};batchidAttr.array.forEach(function(batchId,idx){var _batches$batchId$posi,_batches$batchId$norm;if(!batches[batchId]){batches[batchId]={position:[],normal:[],color:colAttr?[]:null,colorStride:colStride,bbox:new Box3}}var pos=posAttr.array.slice(3*idx,3*idx+3);(_batches$batchId$posi=batches[batchId].position).push.apply(_batches$batchId$posi,_toConsumableArray(pos));var nor=norAttr.array.slice(3*idx,3*idx+3);(_batches$batchId$norm=batches[batchId].normal).push.apply(_batches$batchId$norm,_toConsumableArray(nor));if(colAttr){var _batches$batchId$colo;var col=colAttr.array.slice(colStride*idx,colStride*idx+colStride);(_batches$batchId$colo=batches[batchId].color).push.apply(_batches$batchId$colo,_toConsumableArray(col))}batches[batchId].bbox.expandByPoint(_construct(Vector3,_toConsumableArray(pos)).applyMatrix4(c.matrixWorld))});Object.entries(batches).forEach(function(_ref5){var _ref6=_slicedToArray(_ref5,2),batchId=_ref6[0],batch=_ref6[1];if(selectionBox.intersectsBox(batch.bbox)&&_this.bboxInExportPolygon(batch.bbox)){var _batchTableObject$use;// Get batch table object
11
11
  var batchTableObject=c;while(!batchTableObject.batchTable){batchTableObject=batchTableObject.parent}// Express coordinates wrt center of batch object bbox
12
12
  var prevPosition=new Vector3;c.matrixWorld.decompose(prevPosition,new Quaternion,new Vector3);var newPosition=new Vector3;batch.bbox.getCenter(newPosition);var offset=new Vector3().subVectors(newPosition,prevPosition);for(var i=0;i<batch.position.length/3;++i){batch.position[3*i+0]-=offset.x;batch.position[3*i+1]-=offset.y;batch.position[3*i+2]-=offset.z}// Construct mesh
13
13
  var material=new MeshStandardMaterial({color:16777215});var geometry=new BufferGeometry;geometry.setAttribute("position",new Float32BufferAttribute(batch.position,3));geometry.setAttribute("normal",new Float32BufferAttribute(batch.normal,3));if(batch.color){var _material$color;// geometry.setAttribute('color', new Float32BufferAttribute(batch.color, batch.colorStride));
14
14
  // material.vertexColors = batch.color !== null;
15
15
  // material.transparent = batch.colorStride === 4;
16
16
  (_material$color=material.color).set.apply(_material$color,_toConsumableArray(batch.color.slice(0,3)))}var mesh=new Mesh(geometry,material);mesh.applyMatrix4(c.matrixWorld.clone().multiply(new Matrix4().makeTranslation(offset)));// Include attribute from batch table
17
- Object.assign(mesh.userData,batchTableObject.batchTable.getDataFromId(batchId));exportGroup.add(mesh)}})}})});_defineProperty(_this,"addObjectToExportGroup",function(object,exportGroup,selectionBox){object.children.forEach(function(child){var objBox=new Box3().setFromObject(child);if(selectionBox.intersectsBox(objBox)&&_this.bboxInExportPolygon(objBox)){exportGroup.add(child.clone())}})});_defineProperty(_this,"bboxInExportPolygon",function(box3){var polygon=_this.state.exportPolygon[0];var _ref7=[box3.min.x,box3.min.y,box3.max.x,box3.max.y],xmin=_ref7[0],ymin=_ref7[1],xmax=_ref7[2],ymax=_ref7[3];function doLinesIntersect(p1,p2,p3,p4){// Helper function to check if two line segments (p1-p2 and p3-p4) intersect
17
+ var batchAttrs=batchTableObject.batchTable.getDataFromId(batchId);Object.assign(mesh.userData,batchAttrs);// Add label
18
+ var label=(_batchTableObject$use=batchTableObject.userData.tileLabels)===null||_batchTableObject$use===void 0?void 0:_batchTableObject$use[batchId];if(label){mesh.userData.label=label}exportGroup.add(mesh)}})}})});_defineProperty(_this,"addObjectToExportGroup",function(object,exportGroup,selectionBox){object.children.forEach(function(child){var objBox=new Box3().setFromObject(child);if(selectionBox.intersectsBox(objBox)&&_this.bboxInExportPolygon(objBox)){exportGroup.add(child.clone())}})});_defineProperty(_this,"bboxInExportPolygon",function(box3){var polygon=_this.state.exportPolygon[0];var _ref7=[box3.min.x,box3.min.y,box3.max.x,box3.max.y],xmin=_ref7[0],ymin=_ref7[1],xmax=_ref7[2],ymax=_ref7[3];function doLinesIntersect(p1,p2,p3,p4){// Helper function to check if two line segments (p1-p2 and p3-p4) intersect
18
19
  function ccw(A,B,C){return(C[1]-A[1])*(B[0]-A[0])>(B[1]-A[1])*(C[0]-A[0])}return ccw(p1,p3,p4)!==ccw(p2,p3,p4)&&ccw(p1,p2,p3)!==ccw(p1,p2,p4)}// Check if any bbox vertex is inside the polygon
19
20
  if(pointInPolygon([xmin,ymin],polygon)||pointInPolygon([xmax,ymin],polygon)||pointInPolygon([xmax,ymax],polygon)||pointInPolygon([xmax,ymin],polygon)){return true}// Check if any edge of the polygon intersects the bbox
20
21
  for(var i=0;i<polygon.length-1;i++){var _polygon$i=_slicedToArray(polygon[i],2),x1=_polygon$i[0],y1=_polygon$i[1];var _polygon=_slicedToArray(polygon[i+1],2),x2=_polygon[0],y2=_polygon[1];if(doLinesIntersect([x1,y1],[x2,y2],[xmin,ymin],[xmin,ymax])||doLinesIntersect([x1,y1],[x2,y2],[xmin,ymax],[xmax,ymax])||doLinesIntersect([x1,y1],[x2,y2],[xmax,ymax],[xmax,ymin])||doLinesIntersect([x1,y1],[x2,y2],[xmax,ymin],[xmin,ymin])){return true}}return false});_this.measureTool=null;_this.drawLayer=null;return _this}_inherits(ExportObjects3D,_React$Component);return _createClass(ExportObjects3D,[{key:"render",value:function render(){var _this2=this;return/*#__PURE__*/React.createElement(SideBar,{extraClasses:"MapExport",icon:"export",id:"ExportObjects3D",onHide:this.onHide,onShow:this.onShow,title:LocaleUtils.tr("appmenu.items.ExportObjects3D"),width:"20em"},function(){return{body:_this2.renderBody()}})}}])}(React.Component);_defineProperty(ExportObjects3D,"propTypes",{sceneContext:PropTypes.object,setCurrentTask:PropTypes.func});export default connect(function(state){return{theme:state.theme.current}},{setCurrentTask:setCurrentTask})(ExportObjects3D);
@@ -4,5 +4,5 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
4
4
  *
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
- */import React from"react";import classNames from"classnames";import PropTypes from"prop-types";import{Box3,Group}from"three";import{GLTFLoader}from"three/addons/loaders/GLTFLoader";import{v4 as uuidv4}from"uuid";import ConfigUtils from"../../utils/ConfigUtils";import LocaleUtils from"../../utils/LocaleUtils";import Icon from"../Icon";import SideBar from"../SideBar";import FileSelector from"../widgets/FileSelector";import NumberInput from"../widgets/NumberInput";import Spinner from"../widgets/Spinner";import"./style/LayerTree3D.css";var LayerTree3D=/*#__PURE__*/function(_React$Component){function LayerTree3D(){var _this;_classCallCheck(this,LayerTree3D);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,LayerTree3D,[].concat(args));_defineProperty(_this,"state",{activemenu:null,importvisible:false,selectedfile:null,importing:false});_defineProperty(_this,"renderBody",function(){var sceneContext=_this.props.sceneContext;return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("div",{className:"layertree3d-section"},LocaleUtils.tr("layertree3d.objects")),Object.entries(sceneContext.sceneObjects).map(function(_ref){var _ref2=_slicedToArray(_ref,2),objectId=_ref2[0],entry=_ref2[1];return _this.renderLayerEntry(objectId,entry,sceneContext.updateSceneObject,true)}),/*#__PURE__*/React.createElement("div",{className:"layertree3d-section"},LocaleUtils.tr("layertree3d.layers")),Object.entries(sceneContext.colorLayers).map(function(_ref3){var _ref4=_slicedToArray(_ref3,2),layerId=_ref4[0],entry=_ref4[1];return _this.renderLayerEntry(layerId,entry,sceneContext.updateColorLayer,false)}),/*#__PURE__*/React.createElement("div",{className:"layertree3d-option",onClick:function onClick(){return _this.setState(function(state){return{importvisible:!state.importvisible}})}},/*#__PURE__*/React.createElement(Icon,{icon:_this.state.importvisible?"collapse":"expand"})," ",LocaleUtils.tr("layertree3d.importobjects")),_this.state.importvisible?_this.renderImportForm():null)});_defineProperty(_this,"renderLayerEntry",function(entryId,entry,updateCallback,isObject){var _entry$title,_entry$title2;if(entry.layertree===false){return null}var classes=classNames({"layertree3d-item":true,"layertree3d-item-disabled":!entry.visibility});var optMenuClasses=classNames({"layertree3d-item-menubutton":true,"layertree3d-item-menubutton-active":_this.state.activemenu===entryId});return/*#__PURE__*/React.createElement("div",{className:"layertree3d-item-container",key:entryId},/*#__PURE__*/React.createElement("div",{className:classes},/*#__PURE__*/React.createElement(Icon,{className:"layertree3d-item-checkbox",icon:entry.visibility?"checked":"unchecked",onClick:function onClick(){return updateCallback(entryId,{visibility:!entry.visibility})}}),/*#__PURE__*/React.createElement("span",{className:"layertree3d-item-title",title:(_entry$title=entry.title)!==null&&_entry$title!==void 0?_entry$title:entryId},(_entry$title2=entry.title)!==null&&_entry$title2!==void 0?_entry$title2:entryId),entry.drawGroup?/*#__PURE__*/React.createElement(Icon,{className:"layertree3d-item-remove",icon:"trash",onClick:function onClick(){return _this.props.sceneContext.removeSceneObject(entryId)}}):null,/*#__PURE__*/React.createElement(Icon,{className:optMenuClasses,icon:"cog",onClick:function onClick(){return _this.layerMenuToggled(entryId)}})),_this.state.activemenu===entryId?/*#__PURE__*/React.createElement("div",{className:"layertree3d-item-optionsmenu"},/*#__PURE__*/React.createElement("div",{className:"layertree3d-item-optionsmenu-row"},isObject?/*#__PURE__*/React.createElement(Icon,{icon:"zoom",onClick:function onClick(){return _this.zoomToObject(entryId)},title:LocaleUtils.tr("layertree3d.zoomtoobject")}):null,/*#__PURE__*/React.createElement(Icon,{icon:"transparency"}),/*#__PURE__*/React.createElement("input",{className:"layertree3d-item-transparency-slider",max:"255",min:"0",onChange:function onChange(ev){return updateCallback(entryId,{opacity:parseInt(ev.target.value,10)})},step:"1",type:"range",value:entry.opacity})),entry.extrusionHeight!==undefined?/*#__PURE__*/React.createElement("div",{className:"layertree3d-item-optionsmenu-row"},/*#__PURE__*/React.createElement("span",null,"Extrude: "),/*#__PURE__*/React.createElement(NumberInput,{max:500,min:0,onChange:function onChange(h){return updateCallback(entryId,{extrusionHeight:h})},value:entry.extrusionHeight})):null):null)});_defineProperty(_this,"renderImportForm",function(){return/*#__PURE__*/React.createElement("div",{className:"layertree3d-import-widget"},/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement(FileSelector,{accept:".gltf",file:_this.state.selectedfile,onFileSelected:function onFileSelected(file){return _this.setState({selectedfile:file})},title:LocaleUtils.tr("layertree3d.supportedformats")})),/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("button",{className:"button importlayer-addbutton",disabled:_this.state.selectedfile===null||_this.state.importing,onClick:_this.importFile,type:"button"},_this.state.importing?/*#__PURE__*/React.createElement(Spinner,null):null,LocaleUtils.tr("layertree3d.import"))))});_defineProperty(_this,"layerMenuToggled",function(entryId){_this.setState(function(state){return{activemenu:state.activemenu===entryId?null:entryId}})});_defineProperty(_this,"zoomToObject",function(objectId){var _obj$tiles;var obj=_this.props.sceneContext.getSceneObject(objectId);var bbox=new Box3;if(obj!==null&&obj!==void 0&&(_obj$tiles=obj.tiles)!==null&&_obj$tiles!==void 0&&_obj$tiles.root){obj.tiles.root.cached.boundingVolume.getAABB(bbox)}else{bbox.setFromObject(obj)}if(!bbox.isEmpty()){var bounds=[bbox.min.x,bbox.min.y,bbox.max.x,bbox.max.y];_this.props.sceneContext.setViewToExtent(bounds,0)}});_defineProperty(_this,"importFile",function(){if(!_this.state.selectedfile){return}_this.setState({importing:true});var file=_this.state.selectedfile;var reader=new FileReader;reader.onload=function(ev){var loader=new GLTFLoader;loader.parse(ev.target.result,ConfigUtils.getAssetsPath(),function(gltf){// GLTF is Y-UP, we need Z-UP
8
- gltf.scene.rotation.x=Math.PI/2;gltf.scene.updateMatrixWorld();var objectId=uuidv4();var options={drawGroup:true,layertree:true,title:file.name};var group=new Group;group.add(gltf.scene);gltf.scene.traverse(function(c){if(c.geometry){c.castShadow=true;c.receiveShadow=true}});_this.props.sceneContext.addSceneObject(objectId,group,options)},function(err){/* eslint-disable-next-line */console.warn(err)});_this.setState({selectedfile:null,importing:false})};reader.readAsArrayBuffer(_this.state.selectedfile)});return _this}_inherits(LayerTree3D,_React$Component);return _createClass(LayerTree3D,[{key:"render",value:function render(){var _this2=this;return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement(SideBar,{icon:"layers",id:"LayerTree3D",title:LocaleUtils.tr("appmenu.items.LayerTree3D"),width:"20em"},function(){return{body:_this2.renderBody()}}))}}])}(React.Component);_defineProperty(LayerTree3D,"propTypes",{sceneContext:PropTypes.object});export{LayerTree3D as default};
7
+ */import React from"react";import classNames from"classnames";import PropTypes from"prop-types";import{Box3,Group}from"three";import{GLTFLoader}from"three/addons/loaders/GLTFLoader";import{v4 as uuidv4}from"uuid";import ConfigUtils from"../../utils/ConfigUtils";import LocaleUtils from"../../utils/LocaleUtils";import Icon from"../Icon";import SideBar from"../SideBar";import FileSelector from"../widgets/FileSelector";import NumberInput from"../widgets/NumberInput";import Spinner from"../widgets/Spinner";import"./style/LayerTree3D.css";var LayerTree3D=/*#__PURE__*/function(_React$Component){function LayerTree3D(){var _this;_classCallCheck(this,LayerTree3D);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,LayerTree3D,[].concat(args));_defineProperty(_this,"state",{activemenu:null,importvisible:false,selectedfile:null,importing:false});_defineProperty(_this,"renderBody",function(){var sceneContext=_this.props.sceneContext;return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("div",{className:"layertree3d-section"},LocaleUtils.tr("layertree3d.objects")),Object.entries(sceneContext.sceneObjects).map(function(_ref){var _ref2=_slicedToArray(_ref,2),objectId=_ref2[0],entry=_ref2[1];return _this.renderLayerEntry(objectId,entry,sceneContext.updateSceneObject,true)}),/*#__PURE__*/React.createElement("div",{className:"layertree3d-section"},LocaleUtils.tr("layertree3d.layers")),Object.entries(sceneContext.colorLayers).map(function(_ref3){var _ref4=_slicedToArray(_ref3,2),layerId=_ref4[0],entry=_ref4[1];return _this.renderLayerEntry(layerId,entry,sceneContext.updateColorLayer,false)}),/*#__PURE__*/React.createElement("div",{className:"layertree3d-option",onClick:function onClick(){return _this.setState(function(state){return{importvisible:!state.importvisible}})}},/*#__PURE__*/React.createElement(Icon,{icon:_this.state.importvisible?"collapse":"expand"})," ",LocaleUtils.tr("layertree3d.importobjects")),_this.state.importvisible?_this.renderImportForm():null)});_defineProperty(_this,"renderLayerEntry",function(entryId,entry,updateCallback,isObject){var _entry$title,_entry$title2;if(entry.layertree===false){return null}var classes=classNames({"layertree3d-item":true,"layertree3d-item-disabled":!entry.visibility});var optMenuClasses=classNames({"layertree3d-item-menubutton":true,"layertree3d-item-menubutton-active":_this.state.activemenu===entryId});return/*#__PURE__*/React.createElement("div",{className:"layertree3d-item-container",key:entryId},/*#__PURE__*/React.createElement("div",{className:classes},/*#__PURE__*/React.createElement(Icon,{className:"layertree3d-item-checkbox",icon:entry.visibility?"checked":"unchecked",onClick:function onClick(){return updateCallback(entryId,{visibility:!entry.visibility})}}),/*#__PURE__*/React.createElement("span",{className:"layertree3d-item-title",title:(_entry$title=entry.title)!==null&&_entry$title!==void 0?_entry$title:entryId},(_entry$title2=entry.title)!==null&&_entry$title2!==void 0?_entry$title2:entryId),entry.drawGroup?/*#__PURE__*/React.createElement(Icon,{className:"layertree3d-item-remove",icon:"trash",onClick:function onClick(){return _this.props.sceneContext.removeSceneObject(entryId)}}):null,/*#__PURE__*/React.createElement(Icon,{className:optMenuClasses,icon:"cog",onClick:function onClick(){return _this.layerMenuToggled(entryId)}})),_this.state.activemenu===entryId?/*#__PURE__*/React.createElement("div",{className:"layertree3d-item-optionsmenu"},/*#__PURE__*/React.createElement("div",{className:"layertree3d-item-optionsmenu-row"},isObject?/*#__PURE__*/React.createElement(Icon,{icon:"zoom",onClick:function onClick(){return _this.zoomToObject(entryId)},title:LocaleUtils.tr("layertree3d.zoomtoobject")}):null,/*#__PURE__*/React.createElement(Icon,{icon:"transparency"}),/*#__PURE__*/React.createElement("input",{className:"layertree3d-item-transparency-slider",max:"255",min:"0",onChange:function onChange(ev){return updateCallback(entryId,{opacity:parseInt(ev.target.value,10)})},step:"1",type:"range",value:entry.opacity})),entry.extrusionHeight!==undefined?/*#__PURE__*/React.createElement("div",{className:"layertree3d-item-optionsmenu-row"},/*#__PURE__*/React.createElement("span",null,"Extrude:"),/*#__PURE__*/React.createElement(React.Fragment,null,"\xA0"),/*#__PURE__*/React.createElement("select",{onChange:function onChange(ev){return updateCallback(entryId,{extrusionHeight:ev.target.value==="__value"?0:ev.target.value})},value:typeof entry.extrusionHeight==="string"?entry.extrusionHeight:"__value"},/*#__PURE__*/React.createElement("option",{value:"__value"},LocaleUtils.tr("layertree3d.customheight")),(entry.fields||[]).map(function(field){return/*#__PURE__*/React.createElement("option",{key:field,value:field},field)})),typeof entry.extrusionHeight!=="string"?/*#__PURE__*/React.createElement(NumberInput,{max:500,min:0,onChange:function onChange(h){return updateCallback(entryId,{extrusionHeight:h})},value:entry.extrusionHeight}):null):null):null)});_defineProperty(_this,"renderImportForm",function(){return/*#__PURE__*/React.createElement("div",{className:"layertree3d-import-widget"},/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement(FileSelector,{accept:".gltf",file:_this.state.selectedfile,onFileSelected:function onFileSelected(file){return _this.setState({selectedfile:file})},title:LocaleUtils.tr("layertree3d.supportedformats")})),/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("button",{className:"button importlayer-addbutton",disabled:_this.state.selectedfile===null||_this.state.importing,onClick:_this.importFile,type:"button"},_this.state.importing?/*#__PURE__*/React.createElement(Spinner,null):null,LocaleUtils.tr("layertree3d.import"))))});_defineProperty(_this,"layerMenuToggled",function(entryId){_this.setState(function(state){return{activemenu:state.activemenu===entryId?null:entryId}})});_defineProperty(_this,"zoomToObject",function(objectId){var _obj$tiles;var obj=_this.props.sceneContext.getSceneObject(objectId);var bbox=new Box3;if(obj!==null&&obj!==void 0&&(_obj$tiles=obj.tiles)!==null&&_obj$tiles!==void 0&&_obj$tiles.root){obj.tiles.root.cached.boundingVolume.getAABB(bbox)}else{bbox.setFromObject(obj)}if(!bbox.isEmpty()){var bounds=[bbox.min.x,bbox.min.y,bbox.max.x,bbox.max.y];_this.props.sceneContext.setViewToExtent(bounds,0)}});_defineProperty(_this,"importFile",function(){if(!_this.state.selectedfile){return}_this.setState({importing:true});var file=_this.state.selectedfile;var reader=new FileReader;reader.onload=function(ev){var loader=new GLTFLoader;loader.parse(ev.target.result,ConfigUtils.getAssetsPath(),function(gltf){// GLTF is Y-UP, we need Z-UP
8
+ gltf.scene.rotation.x=Math.PI/2;gltf.scene.updateMatrixWorld();var objectId=uuidv4();var options={drawGroup:true,layertree:true,title:file.name};var group=new Group;group.add(gltf.scene);gltf.scene.traverse(function(c){if(c.geometry){c.castShadow=true;c.receiveShadow=true}if(c.userData.label){_this.props.sceneContext.updateObjectLabel(c)}});_this.props.sceneContext.addSceneObject(objectId,group,options)},function(err){/* eslint-disable-next-line */console.warn(err)});_this.setState({selectedfile:null,importing:false})};reader.readAsArrayBuffer(_this.state.selectedfile)});return _this}_inherits(LayerTree3D,_React$Component);return _createClass(LayerTree3D,[{key:"render",value:function render(){var _this2=this;return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement(SideBar,{icon:"layers",id:"LayerTree3D",title:LocaleUtils.tr("appmenu.items.LayerTree3D"),width:"20em"},function(){return{body:_this2.renderBody()}}))}}])}(React.Component);_defineProperty(LayerTree3D,"propTypes",{sceneContext:PropTypes.object});export{LayerTree3D as default};
@@ -4,9 +4,10 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
4
4
  *
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
- */import React from"react";import{connect}from"react-redux";import Instance from"@giro3d/giro3d/core/Instance.js";import Coordinates from"@giro3d/giro3d/core/geographic/Coordinates";import Extent from"@giro3d/giro3d/core/geographic/Extent.js";import ElevationLayer from"@giro3d/giro3d/core/layer/ElevationLayer.js";import FeatureCollection from"@giro3d/giro3d/entities/FeatureCollection.js";import Map from"@giro3d/giro3d/entities/Map.js";import Tiles3D from"@giro3d/giro3d/entities/Tiles3D.js";import Inspector from"@giro3d/giro3d/gui/Inspector.js";import GeoTIFFSource from"@giro3d/giro3d/sources/GeoTIFFSource.js";import axios from"axios";import{fromUrl}from"geotiff";import isEmpty from"lodash.isempty";import PropTypes from"prop-types";import{Vector2,CubeTextureLoader,Group,Raycaster,Mesh}from"three";import{GLTFExporter}from"three/addons/exporters/GLTFExporter.js";import{GLTFLoader}from"three/addons/loaders/GLTFLoader";import{v4 as uuidv4}from"uuid";import{LayerRole}from"../../actions/layers";import{setCurrentTask}from"../../actions/task";import{BackgroundSwitcher}from"../../plugins/BackgroundSwitcher";import ConfigUtils from"../../utils/ConfigUtils";import CoordinatesUtils from"../../utils/CoordinatesUtils";import MiscUtils from"../../utils/MiscUtils";import{registerPermalinkDataStoreHook,unregisterPermalinkDataStoreHook,UrlParams}from"../../utils/PermaLinkUtils";import BottomBar3D from"./BottomBar3D";import Compare3D from"./Compare3D";import Draw3D from"./Draw3D";import ExportObjects3D from"./ExportObjects3D";import HideObjects3D from"./HideObjects3D";import Identify3D from"./Identify3D";import LayerTree3D from"./LayerTree3D";import Map3DLight from"./Map3DLight";import MapControls3D from"./MapControls3D";import MapExport3D from"./MapExport3D";import Measure3D from"./Measure3D";import OverviewMap3D from"./OverviewMap3D";import TopBar3D from"./TopBar3D";import View3DSwitcher from"./View3DSwitcher";import LayerRegistry from"./layers/index";import Tiles3DStyle from"./utils/Tiles3DStyle";import"./style/Map3D.css";var UnloadWrapper=/*#__PURE__*/function(_React$Component){function UnloadWrapper(){var _this;_classCallCheck(this,UnloadWrapper);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,UnloadWrapper,[].concat(args));_defineProperty(_this,"onUnload",function(el){if(!el){_this.props.onUnload(_this.props.sceneId)}});return _this}_inherits(UnloadWrapper,_React$Component);return _createClass(UnloadWrapper,[{key:"render",value:function render(){return/*#__PURE__*/React.createElement("div",null,this.props.children,/*#__PURE__*/React.createElement("span",{ref:this.onUnload}))}}])}(React.Component);_defineProperty(UnloadWrapper,"propTypes",{children:PropTypes.oneOfType([PropTypes.node,PropTypes.func]),onUnload:PropTypes.func,sceneId:PropTypes.string});var Map3D=/*#__PURE__*/function(_React$Component2){function Map3D(props){var _this2;_classCallCheck(this,Map3D);_this2=_callSuper(this,Map3D,[props]);_defineProperty(_this2,"state",{sceneContext:_objectSpread(_objectSpread({},Map3D.defaultSceneState),{},{addLayer:function addLayer(layer){},getLayer:function getLayer(layerId){},removeLayer:function removeLayer(layerId){},updateColorLayer:function updateColorLayer(layerId,options){},addSceneObject:function addSceneObject(objectId,object){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{}},getSceneObject:function getSceneObject(objectId){},removeSceneObject:function removeSceneObject(objectId){},updateSceneObject:function updateSceneObject(objectId,options){},getMap:function getMap(){},setViewToExtent:function setViewToExtent(bounds,angle){},getTerrainHeightFromDTM:function getTerrainHeightFromDTM(scenePos){},getTerrainHeightFromMap:function getTerrainHeightFromMap(scenePos){},getSceneIntersection:function getSceneIntersection(x,y){}}),sceneId:null});_defineProperty(_this2,"applyBaseLayer",function(){var baseLayer=_this2.state.sceneContext.baseLayers.find(function(e){return e.visibility===true});_this2.removeLayer("__baselayer");if(!baseLayer){return}var layerCreator=LayerRegistry[baseLayer.type];if(layerCreator!==null&&layerCreator!==void 0&&layerCreator.create3d){var layer3d=layerCreator.create3d(baseLayer,_this2.state.sceneContext.mapCrs);_this2.addLayer("__baselayer",layer3d);_this2.map.insertLayerAfter(layer3d,null)}});_defineProperty(_this2,"setBaseLayer",function(layer,visibility){_this2.setState(function(state){return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{baseLayers:state.sceneContext.baseLayers.map(function(entry){return _objectSpread(_objectSpread({},entry),{},{visibility:entry.name===layer.name?visibility:false})})})}})});_defineProperty(_this2,"collectColorLayers",function(prevColorLayers){return _this2.props.layers.reduce(function(colorLayers,layer){var _prevOptions$visibili,_prevOptions$opacity,_prevOptions$extrusio;if(layer.role!==LayerRole.THEME&&layer.role!==LayerRole.USERLAYER){return colorLayers}var layerCreator=LayerRegistry[layer.type];if(!layerCreator||!layerCreator.create3d){return colorLayers}var prevOptions=prevColorLayers[layer.uuid];colorLayers[layer.uuid]=_objectSpread(_objectSpread({},layer),{},{visibility:(_prevOptions$visibili=prevOptions===null||prevOptions===void 0?void 0:prevOptions.visibility)!==null&&_prevOptions$visibili!==void 0?_prevOptions$visibili:false,opacity:(_prevOptions$opacity=prevOptions===null||prevOptions===void 0?void 0:prevOptions.opacity)!==null&&_prevOptions$opacity!==void 0?_prevOptions$opacity:255,extrusionHeight:(_prevOptions$extrusio=prevOptions===null||prevOptions===void 0?void 0:prevOptions.extrusionHeight)!==null&&_prevOptions$extrusio!==void 0?_prevOptions$extrusio:["vector","wfs"].includes(layer.type)?0:undefined});return colorLayers},{})});_defineProperty(_this2,"applyColorLayerUpdates",function(colorLayers,prevColorLayers){// Add-update new layers
8
- var layerBelow=_this2.getLayer("__baselayer");Object.entries(colorLayers).reverse().forEach(function(_ref){var _ref2=_slicedToArray(_ref,2),layerId=_ref2[0],options=_ref2[1];var prevOptions=prevColorLayers[layerId];var layerCreator=LayerRegistry[options.type];var mapLayer=_this2.getLayer(layerId);if(mapLayer){layerCreator.update3d(mapLayer.source,options,prevOptions,_this2.state.sceneContext.mapCrs)}else{mapLayer=layerCreator.create3d(options,_this2.state.sceneContext.mapCrs);_this2.addLayer(layerId,mapLayer)}_this2.map.insertLayerAfter(mapLayer,layerBelow);mapLayer.visible=options.visibility;mapLayer.opacity=options.opacity/255;layerBelow=mapLayer;if(options.extrusionHeight>0){_this2.createUpdateExtrudedLayer(mapLayer,options,options.features!==(prevOptions===null||prevOptions===void 0?void 0:prevOptions.features))}else if((prevOptions===null||prevOptions===void 0?void 0:prevOptions.extrusionHeight)>0){_this2.removeExtrudedLayer(options.uuid)}});// Remove old layers
9
- Object.entries(prevColorLayers).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),layerId=_ref4[0],options=_ref4[1];if(!(layerId in colorLayers)){if(options.extrusionHeight){_this2.removeExtrudedLayer(options.uuid)}_this2.removeLayer(layerId)}});_this2.instance.notifyChange(_this2.map)});_defineProperty(_this2,"createUpdateExtrudedLayer",function(mapLayer,options){var _options$features,_options$features$red;var forceCreate=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var bounds=options.bbox.bounds;var extent=new Extent(options.bbox.crs,bounds[0],bounds[2],bounds[1],bounds[3]);var objId=options.uuid+":extruded";var makeColor=function makeColor(c){if(Array.isArray(c)){return c[0]<<16|c[1]<<8|c[2]}else if(typeof c==="string"){return parseInt(c.replace("#",""),16)}else{return c}};var obj=_this2.objectMap[objId];if(!obj||forceCreate){var _options$color;if(obj){_this2.instance.remove(obj)}var layercolor=makeColor((_options$color=options.color)!==null&&_options$color!==void 0?_options$color:"#FF0000");obj=new FeatureCollection({source:mapLayer.source.source,extent:extent,elevation:function elevation(feature){var coordinates=feature.getGeometry().getCoordinates();while(Array.isArray(coordinates[0])){coordinates=coordinates[0]}return coordinates[2]||_this2.getTerrainHeightFromMap(coordinates)||0},extrusionOffset:function extrusionOffset(){return obj.userData.extrusionHeight},style:function style(feature){var _obj$userData$feature,_obj$userData$feature2;return(_obj$userData$feature=(_obj$userData$feature2=obj.userData.featureStyles)===null||_obj$userData$feature2===void 0?void 0:_obj$userData$feature2[feature.getId()])!==null&&_obj$userData$feature!==void 0?_obj$userData$feature:{fill:{color:layercolor,shading:true}}}});obj.castShadow=true;obj.receiveShadow=true;_this2.instance.add(obj);_this2.objectMap[objId]=obj}obj.userData.extrusionHeight=options.extrusionHeight;obj.userData.featureStyles=(_options$features=options.features)===null||_options$features===void 0||(_options$features$red=_options$features.reduce)===null||_options$features$red===void 0?void 0:_options$features$red.call(_options$features,function(res,feature){return _objectSpread(_objectSpread({},res),{},_defineProperty({},feature.id,{fill:{color:makeColor(feature.styleOptions.fillColor),shading:true}}))},{});obj.traverse(function(mesh){mesh.castShadow=true;mesh.receiveShadow=true});obj.opacity=mapLayer.opacity;obj.visible=mapLayer.visible;obj.updateStyles()});_defineProperty(_this2,"removeExtrudedLayer",function(layerId){var objId=layerId+":extruded";if(_this2.objectMap[objId]){_this2.instance.remove(_this2.objectMap[objId]);delete _this2.objectMap[objId]}_this2.instance.notifyChange()});_defineProperty(_this2,"applySceneObjectUpdates",function(sceneObjects){Object.entries(sceneObjects).forEach(function(_ref5){var _ref6=_slicedToArray(_ref5,2),objectId=_ref6[0],options=_ref6[1];var object=_this2.objectMap[objectId];object.visible=options.visibility&&options.opacity>0;if(object.opacity!==undefined){object.opacity=options.opacity/255}else{object.traverse(function(child){if(child instanceof Mesh){child.material.transparent=options.opacity<255;child.material.opacity=options.opacity/255;child.material.needsUpdate=true}})}_this2.instance.notifyChange(object)})});_defineProperty(_this2,"addLayer",function(layerId,layer){layer.userData.layerId=layerId;_this2.map.addLayer(layer)});_defineProperty(_this2,"getLayer",function(layerId){var _this2$map$getLayers$;return(_this2$map$getLayers$=_this2.map.getLayers(function(l){return l.userData.layerId===layerId})[0])!==null&&_this2$map$getLayers$!==void 0?_this2$map$getLayers$:null});_defineProperty(_this2,"removeLayer",function(layerId){_this2.map.getLayers(function(l){return l.userData.layerId===layerId}).forEach(function(layer){_this2.map.removeLayer(layer,{dispose:true})})});_defineProperty(_this2,"updateColorLayer",function(layerId,options){_this2.setState(function(state){return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{colorLayers:_objectSpread(_objectSpread({},state.sceneContext.colorLayers),{},_defineProperty({},layerId,_objectSpread(_objectSpread({},state.sceneContext.colorLayers[layerId]),options)))})}})});_defineProperty(_this2,"addSceneObject",function(objectId,object){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};_this2.sceneObjectGroup.add(object);_this2.objectMap[objectId]=object;_this2.setState(function(state){var objectState=_objectSpread({visibility:true,opacity:255,layertree:false},options);return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{sceneObjects:_objectSpread(_objectSpread({},state.sceneContext.sceneObjects),{},_defineProperty({},objectId,objectState))})}})});_defineProperty(_this2,"getSceneObject",function(objectId){return _this2.objectMap[objectId]});_defineProperty(_this2,"removeSceneObject",function(objectId){if(!_this2.objectMap[objectId]){return}_this2.sceneObjectGroup.remove(_this2.objectMap[objectId]);delete _this2.objectMap[objectId];_this2.setState(function(state){var newSceneObjects=_objectSpread({},state.sceneContext.sceneObjects);delete newSceneObjects[objectId];return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{sceneObjects:newSceneObjects})}})});_defineProperty(_this2,"updateSceneObject",function(objectId,options){_this2.setState(function(state){return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{sceneObjects:_objectSpread(_objectSpread({},state.sceneContext.sceneObjects),{},_defineProperty({},objectId,_objectSpread(_objectSpread({},state.sceneContext.sceneObjects[objectId]),options)))})}})});_defineProperty(_this2,"getMap",function(){return _this2.map});_defineProperty(_this2,"setupContainer",function(el){if(el){_this2.container=el;_this2.setupInstance()}});_defineProperty(_this2,"setupInstance",function(){var _this2$props$theme$ma,_this2$props$theme$ma2,_this2$props$theme$ma3,_this2$props$theme$ma6,_this2$props$theme$ma7;if(_this2.instance){_this2.disposeInstance()}var projection=_this2.props.theme.mapCrs;// Setup instance
7
+ */import React from"react";import{connect}from"react-redux";import Instance from"@giro3d/giro3d/core/Instance.js";import Coordinates from"@giro3d/giro3d/core/geographic/Coordinates";import Extent from"@giro3d/giro3d/core/geographic/Extent.js";import ElevationLayer from"@giro3d/giro3d/core/layer/ElevationLayer.js";import FeatureCollection from"@giro3d/giro3d/entities/FeatureCollection.js";import Map from"@giro3d/giro3d/entities/Map.js";import Tiles3D from"@giro3d/giro3d/entities/Tiles3D.js";import Inspector from"@giro3d/giro3d/gui/Inspector.js";import GeoTIFFSource from"@giro3d/giro3d/sources/GeoTIFFSource.js";import axios from"axios";import{fromUrl}from"geotiff";import isEmpty from"lodash.isempty";import PropTypes from"prop-types";import{Vector2,CubeTextureLoader,Group,Raycaster,Mesh}from"three";import{GLTFExporter}from"three/addons/exporters/GLTFExporter.js";import{GLTFLoader}from"three/addons/loaders/GLTFLoader";import{CSS2DObject}from"three/addons/renderers/CSS2DRenderer";import{v4 as uuidv4}from"uuid";import{LayerRole}from"../../actions/layers";import{setCurrentTask}from"../../actions/task";import{BackgroundSwitcher}from"../../plugins/BackgroundSwitcher";import ConfigUtils from"../../utils/ConfigUtils";import CoordinatesUtils from"../../utils/CoordinatesUtils";import MiscUtils from"../../utils/MiscUtils";import{registerPermalinkDataStoreHook,unregisterPermalinkDataStoreHook,UrlParams}from"../../utils/PermaLinkUtils";import BottomBar3D from"./BottomBar3D";import Compare3D from"./Compare3D";import Draw3D from"./Draw3D";import ExportObjects3D from"./ExportObjects3D";import HideObjects3D from"./HideObjects3D";import Identify3D from"./Identify3D";import LayerTree3D from"./LayerTree3D";import Map3DLight from"./Map3DLight";import MapControls3D from"./MapControls3D";import MapExport3D from"./MapExport3D";import Measure3D from"./Measure3D";import OverviewMap3D from"./OverviewMap3D";import TopBar3D from"./TopBar3D";import View3DSwitcher from"./View3DSwitcher";import LayerRegistry from"./layers/index";import Tiles3DStyle from"./utils/Tiles3DStyle";import"./style/Map3D.css";var UnloadWrapper=/*#__PURE__*/function(_React$Component){function UnloadWrapper(){var _this;_classCallCheck(this,UnloadWrapper);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,UnloadWrapper,[].concat(args));_defineProperty(_this,"onUnload",function(el){if(!el){_this.props.onUnload(_this.props.sceneId)}});return _this}_inherits(UnloadWrapper,_React$Component);return _createClass(UnloadWrapper,[{key:"render",value:function render(){return/*#__PURE__*/React.createElement("div",null,this.props.children,/*#__PURE__*/React.createElement("span",{ref:this.onUnload}))}}])}(React.Component);_defineProperty(UnloadWrapper,"propTypes",{children:PropTypes.oneOfType([PropTypes.node,PropTypes.func]),onUnload:PropTypes.func,sceneId:PropTypes.string});var Map3D=/*#__PURE__*/function(_React$Component2){function Map3D(props){var _this2;_classCallCheck(this,Map3D);_this2=_callSuper(this,Map3D,[props]);_defineProperty(_this2,"state",{sceneContext:_objectSpread(_objectSpread({},Map3D.defaultSceneState),{},{addLayer:function addLayer(layer){},getLayer:function getLayer(layerId){},removeLayer:function removeLayer(layerId){},updateColorLayer:function updateColorLayer(layerId,options){},addSceneObject:function addSceneObject(objectId,object){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{}},getSceneObject:function getSceneObject(objectId){},removeSceneObject:function removeSceneObject(objectId){},updateSceneObject:function updateSceneObject(objectId,options){},updateObjectLabel:function updateObjectLabel(object){},getMap:function getMap(){},setViewToExtent:function setViewToExtent(bounds,angle){},getTerrainHeightFromDTM:function getTerrainHeightFromDTM(scenePos){},getTerrainHeightFromMap:function getTerrainHeightFromMap(scenePos){},getSceneIntersection:function getSceneIntersection(x,y){}}),sceneId:null});_defineProperty(_this2,"applyBaseLayer",function(){var baseLayer=_this2.state.sceneContext.baseLayers.find(function(e){return e.visibility===true});_this2.removeLayer("__baselayer");if(!baseLayer){return}var layerCreator=LayerRegistry[baseLayer.type];if(layerCreator!==null&&layerCreator!==void 0&&layerCreator.create3d){var layer3d=layerCreator.create3d(baseLayer,_this2.state.sceneContext.mapCrs);_this2.addLayer("__baselayer",layer3d);_this2.map.insertLayerAfter(layer3d,null)}});_defineProperty(_this2,"setBaseLayer",function(layer,visibility){_this2.setState(function(state){return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{baseLayers:state.sceneContext.baseLayers.map(function(entry){return _objectSpread(_objectSpread({},entry),{},{visibility:entry.name===layer.name?visibility:false})})})}})});_defineProperty(_this2,"collectColorLayers",function(prevColorLayers){return _this2.props.layers.reduce(function(colorLayers,layer){var _prevOptions$visibili,_prevOptions$opacity,_prevOptions$extrusio,_prevOptions$fields;if(layer.role!==LayerRole.THEME&&layer.role!==LayerRole.USERLAYER){return colorLayers}var layerCreator=LayerRegistry[layer.type];if(!layerCreator||!layerCreator.create3d){return colorLayers}var prevOptions=prevColorLayers[layer.uuid];colorLayers[layer.uuid]=_objectSpread(_objectSpread({},layer),{},{visibility:(_prevOptions$visibili=prevOptions===null||prevOptions===void 0?void 0:prevOptions.visibility)!==null&&_prevOptions$visibili!==void 0?_prevOptions$visibili:false,opacity:(_prevOptions$opacity=prevOptions===null||prevOptions===void 0?void 0:prevOptions.opacity)!==null&&_prevOptions$opacity!==void 0?_prevOptions$opacity:255,extrusionHeight:(_prevOptions$extrusio=prevOptions===null||prevOptions===void 0?void 0:prevOptions.extrusionHeight)!==null&&_prevOptions$extrusio!==void 0?_prevOptions$extrusio:["vector","wfs"].includes(layer.type)?0:undefined,fields:(_prevOptions$fields=prevOptions===null||prevOptions===void 0?void 0:prevOptions.fields)!==null&&_prevOptions$fields!==void 0?_prevOptions$fields:undefined});if(colorLayers[layer.uuid].fields===undefined&&layerCreator.getFields){layerCreator.getFields(layer).then(function(fields){_this2.updateColorLayer(layer.uuid,{fields:fields})})}return colorLayers},{})});_defineProperty(_this2,"applyColorLayerUpdates",function(colorLayers,prevColorLayers){// Add-update new layers
8
+ var layerBelow=_this2.getLayer("__baselayer");Object.entries(colorLayers).reverse().forEach(function(_ref){var _ref2=_slicedToArray(_ref,2),layerId=_ref2[0],options=_ref2[1];var prevOptions=prevColorLayers[layerId];var layerCreator=LayerRegistry[options.type];var mapLayer=_this2.getLayer(layerId);if(mapLayer){layerCreator.update3d(mapLayer.source,options,prevOptions,_this2.state.sceneContext.mapCrs)}else{mapLayer=layerCreator.create3d(options,_this2.state.sceneContext.mapCrs);_this2.addLayer(layerId,mapLayer)}_this2.map.insertLayerAfter(mapLayer,layerBelow);mapLayer.visible=options.visibility;mapLayer.opacity=options.opacity/255;layerBelow=mapLayer;if(options.extrusionHeight!==0){_this2.createUpdateExtrudedLayer(mapLayer,options,options.features!==(prevOptions===null||prevOptions===void 0?void 0:prevOptions.features))}else if((prevOptions===null||prevOptions===void 0?void 0:prevOptions.extrusionHeight)!==0){_this2.removeExtrudedLayer(options.uuid)}});// Remove old layers
9
+ Object.entries(prevColorLayers).forEach(function(_ref3){var _ref4=_slicedToArray(_ref3,2),layerId=_ref4[0],options=_ref4[1];if(!(layerId in colorLayers)){if(options.extrusionHeight!==0){_this2.removeExtrudedLayer(options.uuid)}_this2.removeLayer(layerId)}});_this2.instance.notifyChange(_this2.map)});_defineProperty(_this2,"createUpdateExtrudedLayer",function(mapLayer,options){var _options$features,_options$features$red;var forceCreate=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var bounds=options.bbox.bounds;var extent=new Extent(options.bbox.crs,bounds[0],bounds[2],bounds[1],bounds[3]);var objId=options.uuid+":extruded";var makeColor=function makeColor(c){if(Array.isArray(c)){return c[0]<<16|c[1]<<8|c[2]}else if(typeof c==="string"){return parseInt(c.replace("#",""),16)}else{return c}};var obj=_this2.objectMap[objId];if(!obj||forceCreate){var _options$color;if(obj){_this2.instance.remove(obj)}var layercolor=makeColor((_options$color=options.color)!==null&&_options$color!==void 0?_options$color:"#FF0000");obj=new FeatureCollection({source:mapLayer.source.source,extent:extent,minLevel:1,maxLevel:1,ignoreZ:true,elevation:function elevation(feature){var _this2$getTerrainHeig;var coordinates=feature.getGeometry().getCoordinates();while(Array.isArray(coordinates[0])){coordinates=coordinates[0]}return(_this2$getTerrainHeig=_this2.getTerrainHeightFromMap(coordinates))!==null&&_this2$getTerrainHeig!==void 0?_this2$getTerrainHeig:0},extrusionOffset:function extrusionOffset(feature){if(typeof obj.userData.extrusionHeight==="string"){return parseFloat(feature.getProperties()[obj.userData.extrusionHeight])||0}else{return obj.userData.extrusionHeight}},style:function style(feature){var _obj$userData$feature,_obj$userData$feature2;return(_obj$userData$feature=(_obj$userData$feature2=obj.userData.featureStyles)===null||_obj$userData$feature2===void 0?void 0:_obj$userData$feature2[feature.getId()])!==null&&_obj$userData$feature!==void 0?_obj$userData$feature:{fill:{color:layercolor,shading:true}}}});obj.castShadow=true;obj.receiveShadow=true;_this2.instance.add(obj);_this2.objectMap[objId]=obj}obj.userData.extrusionHeight=options.extrusionHeight;obj.userData.featureStyles=(_options$features=options.features)===null||_options$features===void 0||(_options$features$red=_options$features.reduce)===null||_options$features$red===void 0?void 0:_options$features$red.call(_options$features,function(res,feature){return _objectSpread(_objectSpread({},res),{},_defineProperty({},feature.id,{fill:{color:makeColor(feature.styleOptions.fillColor),shading:true}}))},{});obj.opacity=mapLayer.opacity;obj.visible=mapLayer.visible;obj.updateStyles()});_defineProperty(_this2,"removeExtrudedLayer",function(layerId){var objId=layerId+":extruded";if(_this2.objectMap[objId]){_this2.instance.remove(_this2.objectMap[objId]);delete _this2.objectMap[objId]}_this2.instance.notifyChange()});_defineProperty(_this2,"applySceneObjectUpdates",function(sceneObjects){Object.entries(sceneObjects).forEach(function(_ref5){var _ref6=_slicedToArray(_ref5,2),objectId=_ref6[0],options=_ref6[1];var object=_this2.objectMap[objectId];object.visible=options.visibility&&options.opacity>0;if(object.opacity!==undefined){object.opacity=options.opacity/255}else{object.traverse(function(child){if(child instanceof Mesh){child.material.transparent=options.opacity<255;child.material.opacity=options.opacity/255;child.material.needsUpdate=true}})}_this2.instance.notifyChange(object)})});_defineProperty(_this2,"updateObjectLabel",function(sceneObject){var labelObject=sceneObject.children.find(function(child){return child.isCSS2DObject});if(sceneObject.userData.label){if(!labelObject){var labelEl=document.createElement("span");labelEl.className="map3d-object-label";labelObject=new CSS2DObject(labelEl);labelObject.updateMatrixWorld();sceneObject.add(labelObject);labelObject.userData.removeCallback=function(){// Explicitly remove label DOM element
10
+ labelEl.parentNode.removeChild(labelEl)};sceneObject.addEventListener("removed",labelObject.userData.removeCallback);sceneObject.updateMatrixWorld()}labelObject.element.textContent=sceneObject.userData.label}else if(labelObject){sceneObject.removeEventListener("removed",labelObject.userData.removeCallback);sceneObject.remove(labelObject)}_this2.instance.notifyChange(sceneObject)});_defineProperty(_this2,"addLayer",function(layerId,layer){layer.userData.layerId=layerId;_this2.map.addLayer(layer)});_defineProperty(_this2,"getLayer",function(layerId){var _this2$map$getLayers$;return(_this2$map$getLayers$=_this2.map.getLayers(function(l){return l.userData.layerId===layerId})[0])!==null&&_this2$map$getLayers$!==void 0?_this2$map$getLayers$:null});_defineProperty(_this2,"removeLayer",function(layerId){_this2.map.getLayers(function(l){return l.userData.layerId===layerId}).forEach(function(layer){_this2.map.removeLayer(layer,{dispose:true})})});_defineProperty(_this2,"updateColorLayer",function(layerId,options){_this2.setState(function(state){return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{colorLayers:_objectSpread(_objectSpread({},state.sceneContext.colorLayers),{},_defineProperty({},layerId,_objectSpread(_objectSpread({},state.sceneContext.colorLayers[layerId]),options)))})}})});_defineProperty(_this2,"addSceneObject",function(objectId,object){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};_this2.sceneObjectGroup.add(object);_this2.objectMap[objectId]=object;_this2.setState(function(state){var objectState=_objectSpread({visibility:true,opacity:255,layertree:false},options);return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{sceneObjects:_objectSpread(_objectSpread({},state.sceneContext.sceneObjects),{},_defineProperty({},objectId,objectState))})}})});_defineProperty(_this2,"getSceneObject",function(objectId){return _this2.objectMap[objectId]});_defineProperty(_this2,"removeSceneObject",function(objectId){var callback=arguments.length>1&&arguments[1]!==undefined?arguments[1]:undefined;if(!_this2.objectMap[objectId]){return}_this2.objectMap[objectId].traverse(function(child){child.dispatchEvent({type:"removed"})});_this2.sceneObjectGroup.remove(_this2.objectMap[objectId]);delete _this2.objectMap[objectId];_this2.setState(function(state){var newSceneObjects=_objectSpread({},state.sceneContext.sceneObjects);delete newSceneObjects[objectId];return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{sceneObjects:newSceneObjects})}},callback)});_defineProperty(_this2,"updateSceneObject",function(objectId,options){_this2.setState(function(state){return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{sceneObjects:_objectSpread(_objectSpread({},state.sceneContext.sceneObjects),{},_defineProperty({},objectId,_objectSpread(_objectSpread({},state.sceneContext.sceneObjects[objectId]),options)))})}})});_defineProperty(_this2,"getMap",function(){return _this2.map});_defineProperty(_this2,"setupContainer",function(el){if(el){_this2.container=el;_this2.setupInstance()}});_defineProperty(_this2,"setupInstance",function(){var _this2$props$theme$ma,_this2$props$theme$ma2,_this2$props$theme$ma3,_this2$props$theme$ma6,_this2$props$theme$ma7;if(_this2.instance){_this2.disposeInstance()}var projection=_this2.props.theme.mapCrs;// Setup instance
10
11
  _this2.instance=new Instance({target:_this2.container,crs:projection,renderer:{clearColor:0,preserveDrawingBuffer:true}});_this2.sceneObjectGroup=new Group;_this2.instance.add(_this2.sceneObjectGroup);// Setup map
11
12
  var bounds=CoordinatesUtils.reprojectBbox(_this2.props.theme.initialBbox.bounds,_this2.props.theme.initialBbox.crs,projection);var extent=new Extent(projection,bounds[0],bounds[2],bounds[1],bounds[3]);_this2.map=new Map({extent:extent,backgroundColor:"white"});_this2.instance.add(_this2.map);// Setup camera
12
13
  var center=extent.center();_this2.instance.view.camera.position.set(center.x,center.y,0.5*(extent.east-extent.west));// Skybox
@@ -25,6 +26,6 @@ var maxPixelY=Math.round((tiepointY-dtmExt[1])/scaleY)+1;// Inverted Y-axis in i
25
26
  var maxPixelX=Math.round((dtmExt[2]-tiepointX)/scaleX)+1;var width=maxPixelX-minPixelX;var height=maxPixelY-minPixelY;image.readRasters({window:[minPixelX,minPixelY,maxPixelX,maxPixelY]}).then(function(raster){if(!returnArray){resolve(raster[0][0])}else{var h=dtmPos.map(function(p){var x=Math.round((p[0]-dtmExt[0])/(dtmExt[2]-dtmExt[0])*(width-1));var y=Math.round((1-(p[1]-dtmExt[1])/(dtmExt[3]-dtmExt[1]))*(height-1));return raster[0][x+y*width]});resolve(h)}})})})})});_defineProperty(_this2,"getTerrainHeightFromMap",function(scenePos){var _elevationResult$samp;var coordinates=new Coordinates(_this2.state.sceneContext.mapCrs,scenePos[0],scenePos[1],0);var elevationResult=_this2.state.sceneContext.map.getElevation({coordinates:coordinates});elevationResult.samples.sort(function(a,b){return b.resolution-a.resolution});return(_elevationResult$samp=elevationResult.samples[0])===null||_elevationResult$samp===void 0?void 0:_elevationResult$samp.elevation});_defineProperty(_this2,"getSceneIntersection",function(x,y){var objects=arguments.length>2&&arguments[2]!==undefined?arguments[2]:true;var raycaster=new Raycaster;var camera=_this2.instance.view.camera;raycaster.setFromCamera(new Vector2(x,y),camera);// Query object intersection
26
27
  var intersectionObjects=objects?Object.entries(_this2.state.sceneContext.sceneObjects).map(function(_ref11){var _ref12=_slicedToArray(_ref11,2),objId=_ref12[0],options=_ref12[1];if(options.layertree&&options.visibility){var _obj$tiles$group,_obj$tiles;var obj=_this2.objectMap[objId];return(_obj$tiles$group=(_obj$tiles=obj.tiles)===null||_obj$tiles===void 0?void 0:_obj$tiles.group)!==null&&_obj$tiles$group!==void 0?_obj$tiles$group:obj}return null}).filter(Boolean):null;var objInter=objects?raycaster.intersectObjects(intersectionObjects,true)[0]:undefined;// Query highest resolution terrain tile (i.e. tile with no children)
27
28
  var terrInter=raycaster.intersectObjects([_this2.map.object3d]).filter(function(result){return result.object.children.length===0})[0];// Return closest result
28
- if(objInter&&terrInter){return objInter.distance<terrInter.distance?objInter:terrInter}return objInter!==null&&objInter!==void 0?objInter:terrInter});_defineProperty(_this2,"redrawScene",function(ev){var width=ev.target.innerWidth;var height=ev.target.innerHeight;_this2.instance.renderer.setSize(width,height);_this2.instance.view.camera.aspect=width/height;_this2.instance.view.camera.updateProjectionMatrix();_this2.instance.renderer.render(_this2.instance.scene,_this2.instance.view.camera)});_defineProperty(_this2,"setViewToExtent",function(bounds,rotation){_this2.state.sceneContext.setViewToExtent(bounds,rotation)});_defineProperty(_this2,"store3dState",function(){var promises=Object.entries(_this2.state.sceneContext.sceneObjects).map(function(_ref13){var _ref14=_slicedToArray(_ref13,2),objectId=_ref14[0],entry=_ref14[1];if(!entry.layertree){return null}return new Promise(function(resolve){if(entry.drawGroup){var exporter=new GLTFExporter;exporter.parse(_this2.state.sceneContext.getSceneObject(objectId),function(result){resolve({id:objectId,options:entry,data:result})})}else{resolve({id:objectId,options:entry})}})}).filter(Boolean);return new Promise(function(resolve){Promise.all(promises).then(function(objects){var cameraPos=_this2.state.sceneContext.scene.view.camera.position;var target=_this2.state.sceneContext.scene.view.controls.target;var layers=Object.entries(_this2.state.sceneContext.colorLayers).map(function(_ref15){var _ref16=_slicedToArray(_ref15,2),layerId=_ref16[0],options=_ref16[1];return{id:layerId,options:{visibility:options.visibility,opacity:options.opacity,extrusionHeight:options.extrusionHeight}}});resolve({objects:objects,colorLayers:layers,cameraPos:[cameraPos.x,cameraPos.y,cameraPos.z],center:[target.x,target.y,target.z]})})})});_defineProperty(_this2,"restore3dState",function(data){if(isEmpty(data)){return}(data.objects||[]).forEach(function(item){if(item.data){var loader=new GLTFLoader;loader.parse(item.data,ConfigUtils.getAssetsPath(),function(gltf){gltf.scene.traverse(function(obj){if(obj.isMesh){obj.castShadow=true;obj.receiveShadow=true}});_this2.state.sceneContext.addSceneObject(item.id,gltf.scene,item.options)})}else if(item.id in _this2.state.sceneContext.sceneObjects){_this2.state.sceneContext.updateSceneObject(item.id,item.options)}});(data.colorLayers||[]).forEach(function(item){if(item.id in _this2.state.sceneContext.colorLayers){_this2.state.sceneContext.updateColorLayer(item.id,item.options)}});if(data.cameraPos&&data.center){var cameraPos=_this2.state.sceneContext.scene.view.camera.position;cameraPos.x=data.cameraPos[0];cameraPos.y=data.cameraPos[1];cameraPos.z=data.cameraPos[2];var controlsTarget=_this2.state.sceneContext.scene.view.controls.target;controlsTarget.x=data.center[0];controlsTarget.y=data.center[1];controlsTarget.z=data.center[2]}_this2.state.sceneContext.scene.notifyChange()});_this2.container=null;_this2.inspector=null;_this2.instance=null;_this2.map=null;_this2.sceneObjectGroup=null;_this2.objectMap={};_this2.state.sceneContext.addLayer=_this2.addLayer;_this2.state.sceneContext.getLayer=_this2.getLayer;_this2.state.sceneContext.removeLayer=_this2.removeLayer;_this2.state.sceneContext.updateColorLayer=_this2.updateColorLayer;_this2.state.sceneContext.addSceneObject=_this2.addSceneObject;_this2.state.sceneContext.getSceneObject=_this2.getSceneObject;_this2.state.sceneContext.removeSceneObject=_this2.removeSceneObject;_this2.state.sceneContext.updateSceneObject=_this2.updateSceneObject;_this2.state.sceneContext.getMap=_this2.getMap;_this2.state.sceneContext.getTerrainHeightFromDTM=_this2.getTerrainHeightFromDTM;_this2.state.sceneContext.getTerrainHeightFromMap=_this2.getTerrainHeightFromMap;_this2.state.sceneContext.getSceneIntersection=_this2.getSceneIntersection;registerPermalinkDataStoreHook("map3d",_this2.store3dState);return _this2}_inherits(Map3D,_React$Component2);return _createClass(Map3D,[{key:"componentDidMount",value:function componentDidMount(){this.props.innerRef(this)}},{key:"componentWillUnmount",value:function componentWillUnmount(){unregisterPermalinkDataStoreHook("map3d")}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps,prevState){var _this3=this;if(this.props.theme!==prevProps.theme){this.setupInstance()}else if(this.props.layers!==prevProps.layers){this.setState(function(state){return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{colorLayers:_this3.collectColorLayers(state.sceneContext.colorLayers)})}})}// Update map layers
29
+ if(objInter&&terrInter){return objInter.distance<terrInter.distance?objInter:terrInter}return objInter!==null&&objInter!==void 0?objInter:terrInter});_defineProperty(_this2,"redrawScene",function(ev){var width=ev.target.innerWidth;var height=ev.target.innerHeight;_this2.instance.renderer.setSize(width,height);_this2.instance.view.camera.aspect=width/height;_this2.instance.view.camera.updateProjectionMatrix();_this2.instance.renderer.render(_this2.instance.scene,_this2.instance.view.camera)});_defineProperty(_this2,"setViewToExtent",function(bounds,rotation){_this2.state.sceneContext.setViewToExtent(bounds,rotation)});_defineProperty(_this2,"store3dState",function(){var promises=Object.entries(_this2.state.sceneContext.sceneObjects).map(function(_ref13){var _ref14=_slicedToArray(_ref13,2),objectId=_ref14[0],entry=_ref14[1];if(!entry.layertree){return null}return new Promise(function(resolve){if(entry.drawGroup){var exporter=new GLTFExporter;exporter.parse(_this2.state.sceneContext.getSceneObject(objectId),function(result){resolve({id:objectId,options:entry,data:result})})}else{resolve({id:objectId,options:entry})}})}).filter(Boolean);return new Promise(function(resolve){Promise.all(promises).then(function(objects){var cameraPos=_this2.state.sceneContext.scene.view.camera.position;var target=_this2.state.sceneContext.scene.view.controls.target;var layers=Object.entries(_this2.state.sceneContext.colorLayers).map(function(_ref15){var _ref16=_slicedToArray(_ref15,2),layerId=_ref16[0],options=_ref16[1];return{id:layerId,options:{visibility:options.visibility,opacity:options.opacity,extrusionHeight:options.extrusionHeight}}});resolve({objects:objects,colorLayers:layers,cameraPos:[cameraPos.x,cameraPos.y,cameraPos.z],center:[target.x,target.y,target.z]})})})});_defineProperty(_this2,"restore3dState",function(data){if(isEmpty(data)){return}(data.objects||[]).forEach(function(item){if(item.data){var loader=new GLTFLoader;loader.parse(item.data,ConfigUtils.getAssetsPath(),function(gltf){gltf.scene.traverse(function(obj){if(obj.isMesh){obj.castShadow=true;obj.receiveShadow=true}});_this2.state.sceneContext.addSceneObject(item.id,gltf.scene,item.options)})}else if(item.id in _this2.state.sceneContext.sceneObjects){_this2.state.sceneContext.updateSceneObject(item.id,item.options)}});(data.colorLayers||[]).forEach(function(item){if(item.id in _this2.state.sceneContext.colorLayers){_this2.state.sceneContext.updateColorLayer(item.id,item.options)}});if(data.cameraPos&&data.center){var cameraPos=_this2.state.sceneContext.scene.view.camera.position;cameraPos.x=data.cameraPos[0];cameraPos.y=data.cameraPos[1];cameraPos.z=data.cameraPos[2];var controlsTarget=_this2.state.sceneContext.scene.view.controls.target;controlsTarget.x=data.center[0];controlsTarget.y=data.center[1];controlsTarget.z=data.center[2]}_this2.state.sceneContext.scene.notifyChange()});_this2.container=null;_this2.inspector=null;_this2.instance=null;_this2.map=null;_this2.sceneObjectGroup=null;_this2.objectMap={};_this2.state.sceneContext.addLayer=_this2.addLayer;_this2.state.sceneContext.getLayer=_this2.getLayer;_this2.state.sceneContext.removeLayer=_this2.removeLayer;_this2.state.sceneContext.updateColorLayer=_this2.updateColorLayer;_this2.state.sceneContext.addSceneObject=_this2.addSceneObject;_this2.state.sceneContext.getSceneObject=_this2.getSceneObject;_this2.state.sceneContext.removeSceneObject=_this2.removeSceneObject;_this2.state.sceneContext.updateSceneObject=_this2.updateSceneObject;_this2.state.sceneContext.updateObjectLabel=_this2.updateObjectLabel;_this2.state.sceneContext.getMap=_this2.getMap;_this2.state.sceneContext.getTerrainHeightFromDTM=_this2.getTerrainHeightFromDTM;_this2.state.sceneContext.getTerrainHeightFromMap=_this2.getTerrainHeightFromMap;_this2.state.sceneContext.getSceneIntersection=_this2.getSceneIntersection;registerPermalinkDataStoreHook("map3d",_this2.store3dState);return _this2}_inherits(Map3D,_React$Component2);return _createClass(Map3D,[{key:"componentDidMount",value:function componentDidMount(){this.props.innerRef(this)}},{key:"componentWillUnmount",value:function componentWillUnmount(){unregisterPermalinkDataStoreHook("map3d")}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps,prevState){var _this3=this;if(this.props.theme!==prevProps.theme){this.setupInstance()}else if(this.props.layers!==prevProps.layers){this.setState(function(state){return{sceneContext:_objectSpread(_objectSpread({},state.sceneContext),{},{colorLayers:_this3.collectColorLayers(state.sceneContext.colorLayers)})}})}// Update map layers
29
30
  if(this.state.sceneContext.baseLayers!==prevState.sceneContext.baseLayers){this.applyBaseLayer()}if(this.state.sceneContext.colorLayers!==prevState.sceneContext.colorLayers){this.applyColorLayerUpdates(this.state.sceneContext.colorLayers,prevState.sceneContext.colorLayers)}// Update scene objects
30
31
  if(this.state.sceneContext.sceneObjects!==prevState.sceneContext.sceneObjects){this.applySceneObjectUpdates(this.state.sceneContext.sceneObjects)}}},{key:"render",value:function render(){var baseLayer=this.state.sceneContext.baseLayers.find(function(l){return l.visibility===true});var style={marginTop:this.props.mapMargins.top,marginRight:this.props.mapMargins.right,marginBottom:this.props.mapMargins.bottom,marginLeft:this.props.mapMargins.left};return/*#__PURE__*/React.createElement("div",{className:"map3d-body"},/*#__PURE__*/React.createElement("div",{className:"map3d-inspector"}),/*#__PURE__*/React.createElement("div",{className:"map3d-map",onMouseDown:this.stopAnimations,ref:this.setupContainer,style:style}),/*#__PURE__*/React.createElement(View3DSwitcher,{position:2}),this.state.sceneContext.scene?/*#__PURE__*/React.createElement(UnloadWrapper,{key:this.state.sceneId,onUnload:this.onUnload,sceneId:this.state.sceneId},/*#__PURE__*/React.createElement(MapControls3D,{onControlsSet:this.setupControls,sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(BackgroundSwitcher,{changeLayerVisibility:this.setBaseLayer,layers:this.state.sceneContext.baseLayers,mapMargins:this.props.mapMargins}),/*#__PURE__*/React.createElement(TopBar3D,{options:this.props.options,sceneContext:this.state.sceneContext,searchProviders:this.props.searchProviders}),/*#__PURE__*/React.createElement(LayerTree3D,{sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(BottomBar3D,{sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(OverviewMap3D,{baseLayer:baseLayer,sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(Map3DLight,{sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(Measure3D,{sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(Identify3D,{sceneContext:this.state.sceneContext,tileInfoServiceUrl:this.props.options.tileInfoServiceUrl}),/*#__PURE__*/React.createElement(Compare3D,{sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(Draw3D,{sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(MapExport3D,{sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(ExportObjects3D,{sceneContext:this.state.sceneContext}),/*#__PURE__*/React.createElement(HideObjects3D,{sceneContext:this.state.sceneContext})):null)}}])}(React.Component);_defineProperty(Map3D,"propTypes",{innerRef:PropTypes.func,layers:PropTypes.array,mapMargins:PropTypes.object,onMapInitialized:PropTypes.func,options:PropTypes.object,searchProviders:PropTypes.object,setCurrentTask:PropTypes.func,theme:PropTypes.object});_defineProperty(Map3D,"defaultProps",{geometry:{initialWidth:600,initialHeight:800,initialX:0,initialY:0,initiallyDocked:true},options:{searchMinScaleDenom:1000}});_defineProperty(Map3D,"defaultSceneState",{scene:null,map:null,mapCrs:null,dtmUrl:null,dtmCrs:null,baseLayers:[],colorLayers:{},sceneObjects:{}});export default connect(function(state){return{mapMargins:state.windows.mapMargins,theme:state.theme.current,layers:state.layers.flat}},{setCurrentTask:setCurrentTask})(Map3D);
@@ -4,7 +4,7 @@ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof
4
4
  *
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
- */import React from"react";import Sun from"@giro3d/giro3d/core/geographic/Sun.js";import{MapLightingMode}from"@giro3d/giro3d/entities/MapLightingOptions";import PropTypes from"prop-types";import suncalc from"suncalc";import{AmbientLight,BasicShadowMap,CameraHelper,DirectionalLight,DirectionalLightHelper,PCFShadowMap,PCFSoftShadowMap,VSMShadowMap}from"three";import CoordinatesUtils from"../../utils/CoordinatesUtils";import LocaleUtils from"../../utils/LocaleUtils";import Icon from"../Icon";import SideBar from"../SideBar";import NumberInput from"../widgets/NumberInput";import ToggleSwitch from"../widgets/ToggleSwitch";import"./style/Map3DLight.css";var Map3DLight=/*#__PURE__*/function(_React$Component){function Map3DLight(){var _this;_classCallCheck(this,Map3DLight);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,Map3DLight,[].concat(args));_defineProperty(_this,"state",{showAdvanced:false,lightParams:{day:182,time:720,helpersVisible:false,ambientLightIntensity:2.1,directionalLightIntensity:1.8,zFactor:1,lightElevationLayersOnly:false,shadowsEnabled:true,shadowType:PCFShadowMap,shadowMapSize:4096,shadowBias:-0.0001,sunDistance:80000,normalBias:0,shadowIntensity:0.9,shadowVolumeNear:60000,shadowVolumeFar:100000},dayAnimation:false,dayAnimationSettings:false,dayStep:30,timeAnimation:false,timeAnimationSettings:false,timeStep:30});_defineProperty(_this,"onHide",function(){clearInterval(_this.animationInterval);_this.setState({dayAnimation:false,timeAnimation:false})});_defineProperty(_this,"renderBody",function(){var lightParams=_this.state.lightParams;var dateFormatter=function dateFormatter(day){var date=new Date(new Date().getFullYear(),0,day);return"".concat(String(date.getDate()).padStart(2,"0"),".").concat(String(date.getMonth()+1).padStart(2,"0"))};var timeFormatter=function timeFormatter(time){return"".concat(String(Math.trunc(time/60)).padStart(2,"0"),":").concat(String(time%60).padStart(2,"0"))};return/*#__PURE__*/React.createElement("div",{className:"maplight3d-body"},/*#__PURE__*/React.createElement("table",null,/*#__PURE__*/React.createElement("tbody",null,/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.date")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("div",{className:"map3d-animation-slider"},/*#__PURE__*/React.createElement(Icon,{icon:_this.state.dayAnimation?"square":"triangle-right",onClick:_this.toggleDayAnimation}),_this.renderSlider("day",1,365,1,dateFormatter),/*#__PURE__*/React.createElement(Icon,{className:_this.state.dayAnimationSettings?"map3d-animation-settings-active":"",icon:"cog",onClick:function onClick(){return _this.setState(function(state){return{dayAnimationSettings:!state.dayAnimationSettings}})}})))),_this.state.dayAnimationSettings?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",{colSpan:"2"},/*#__PURE__*/React.createElement("div",{className:"maplight3d-animation-settings"},/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("maplight3d.animationstep"),":"),/*#__PURE__*/React.createElement(NumberInput,{max:60,min:1,onChange:function onChange(dayStep){return _this.setState({dayStep:dayStep})},suffix:" "+LocaleUtils.tr("maplight3d.dayspersec"),value:_this.state.dayStep})))):null,/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.time")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("div",{className:"map3d-animation-slider"},/*#__PURE__*/React.createElement(Icon,{icon:_this.state.timeAnimation?"square":"triangle-right",onClick:_this.toggleTimeAnimation}),_this.renderSlider("time",0,1439,1,timeFormatter),/*#__PURE__*/React.createElement(Icon,{className:_this.state.timeAnimationSettings?"map3d-animation-settings-active":"",icon:"cog",onClick:function onClick(){return _this.setState(function(state){return{timeAnimationSettings:!state.timeAnimationSettings}})}})))),_this.state.timeAnimationSettings?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",{colSpan:"2"},/*#__PURE__*/React.createElement("div",{className:"maplight3d-animation-settings"},/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("maplight3d.animationstep"),":"),/*#__PURE__*/React.createElement(NumberInput,{max:60,min:1,onChange:function onChange(timeStep){return _this.setState({timeStep:timeStep})},suffix:" "+LocaleUtils.tr("maplight3d.minspersec"),value:_this.state.timeStep})))):null,/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.ambientLightIntensity")),/*#__PURE__*/React.createElement("td",null,_this.renderSlider("ambientLightIntensity",0,5,0.1))),/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.directionalLightIntensity")),/*#__PURE__*/React.createElement("td",null,_this.renderSlider("directionalLightIntensity",0,10,0.1))),/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadows")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(ToggleSwitch,{active:lightParams.shadowsEnabled,onChange:function onChange(value){return _this.updateLightParams("shadowsEnabled",value)}}))),/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowintensity")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:1,disabled:!lightParams.shadowsEnabled,max:2,min:0,onChange:function onChange(value){return _this.updateLightParams("shadowIntensity",value)},value:lightParams.shadowIntensity}))),/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",{className:"maplight3d-advanced",colSpan:"2"},/*#__PURE__*/React.createElement("label",null,/*#__PURE__*/React.createElement("input",{checked:_this.state.showAdvanced,onChange:function onChange(ev){return _this.setState(function(state){return{showAdvanced:!state.showAdvanced}})},type:"checkbox"})," ",LocaleUtils.tr("maplight3d.showadvanced")))),_this.state.showAdvanced?[/*#__PURE__*/React.createElement("tr",{key:"helpersVisible"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.helpersVisible")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(ToggleSwitch,{active:lightParams.helpersVisible,onChange:function onChange(value){return _this.updateLightParams("helpersVisible",value)}}))),/*#__PURE__*/React.createElement("tr",{key:"zFactor"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.zFactor")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("input",{max:10,min:0,onChange:function onChange(ev){return _this.updateLightParams("zFactor",ev.target.value)},step:0.1,type:"range",value:lightParams.zFactor}))),/*#__PURE__*/React.createElement("tr",{key:"shadowType"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowType")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{onChange:function onChange(ev){return _this.updateLightParams("shadowType",parseInt(ev.target.value,10))},value:lightParams.shadowType},/*#__PURE__*/React.createElement("option",{value:BasicShadowMap},"BasicShadowMap"),/*#__PURE__*/React.createElement("option",{value:PCFShadowMap},"PCFShadowMap"),/*#__PURE__*/React.createElement("option",{value:PCFSoftShadowMap},"PCFSoftShadowMap"),/*#__PURE__*/React.createElement("option",{value:VSMShadowMap},"VSMShadowMap")))),/*#__PURE__*/React.createElement("tr",{key:"shadowMapSize"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowMapSize")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:0,max:8192,min:64,onChange:function onChange(value){return _this.updateLightParams("shadowMapSize",value)},value:lightParams.shadowMapSize}))),/*#__PURE__*/React.createElement("tr",{key:"shadowBias"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowBias")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:5,max:0.01,min:-0.01,onChange:function onChange(value){return _this.updateLightParams("shadowBias",value)},value:lightParams.shadowBias}))),/*#__PURE__*/React.createElement("tr",{key:"normalBias"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.normalBias")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:1,max:10,min:-10,onChange:function onChange(value){return _this.updateLightParams("normalBias",value)},value:lightParams.normalBias}))),/*#__PURE__*/React.createElement("tr",{key:"shadowVolumeNear"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowVolumeNear")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:0,max:100000,min:100,onChange:function onChange(value){return _this.updateLightParams("shadowVolumeNear",value)},value:lightParams.shadowVolumeNear}))),/*#__PURE__*/React.createElement("tr",{key:"shadowVolumeFar"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowVolumeFar")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:0,max:100000,min:100,onChange:function onChange(value){return _this.updateLightParams("shadowVolumeFar",value)},value:lightParams.shadowVolumeFar})))]:null)))});_defineProperty(_this,"toggleDayAnimation",function(){_this.setState(function(state){return{dayAnimation:!state.dayAnimation,timeAnimation:false}},function(){clearInterval(_this.animationInterval);if(_this.state.dayAnimation){_this.animationInterval=setInterval(function(){_this.updateLightParams("day",(_this.state.lightParams.day+_this.state.dayStep/10)%365)},100)}})});_defineProperty(_this,"toggleTimeAnimation",function(){_this.setState(function(state){return{timeAnimation:!state.timeAnimation,dayAnimation:false}},function(){clearInterval(_this.animationInterval);if(_this.state.timeAnimation){_this.animationInterval=setInterval(function(){_this.updateLightParams("time",(_this.state.lightParams.time+_this.state.timeStep/10)%1440)},100)}})});_defineProperty(_this,"renderSlider",function(key,min,max,step){var labelFormatter=arguments.length>4&&arguments[4]!==undefined?arguments[4]:undefined;var value=_this.state.lightParams[key];var parseValue=function parseValue(x){return Number.isInteger(step)?parseInt(x,10):parseFloat(x)};labelFormatter=labelFormatter!==null&&labelFormatter!==void 0?labelFormatter:function(x){return x.toFixed(-Math.log10(step))};return/*#__PURE__*/React.createElement("div",{className:"maplight3d-slider"},/*#__PURE__*/React.createElement("input",{max:max,min:min,onChange:function onChange(ev){return _this.updateLightParams(key,parseValue(ev.target.value))},step:step,type:"range",value:value}),/*#__PURE__*/React.createElement("div",{className:"maplight3d-slider-label"},/*#__PURE__*/React.createElement("span",{style:{left:(value-min)*100/(max-min)+"%"}},labelFormatter(value))))});_defineProperty(_this,"updateLightParams",function(key,value){_this.setState(function(state){return{lightParams:_objectSpread(_objectSpread({},state.lightParams),{},_defineProperty({},key,value))}})});_defineProperty(_this,"computeShadowVolume",function(directionalLight,lightParams){if(!lightParams.shadowsEnabled){_this.props.sceneContext.scene.renderer.shadowMap.enabled=false;return}var cameraHeight=_this.props.sceneContext.scene.view.camera.position.z;var targetHeight=_this.props.sceneContext.scene.view.controls.target.z;var volumeSize=Math.min(20000,Math.max(1000,cameraHeight-targetHeight));directionalLight.shadow.camera.top=volumeSize;directionalLight.shadow.camera.bottom=-volumeSize;directionalLight.shadow.camera.left=-volumeSize;directionalLight.shadow.camera.right=volumeSize;directionalLight.shadow.camera.near=lightParams.shadowVolumeNear;directionalLight.shadow.camera.far=lightParams.shadowVolumeFar;_this.props.sceneContext.scene.renderer.shadowMap.enabled=true});_defineProperty(_this,"setLighting",function(){var sceneContext=_this.props.sceneContext;var lightParams=_this.state.lightParams;var ambientLight=sceneContext.getSceneObject("__ambientLight");var directionalLight=sceneContext.getSceneObject("__directionalLight");var directionalLightHelper=sceneContext.getSceneObject("__directionalLightHelper");var shadowCameraHelper=sceneContext.getSceneObject("__shadowCameraHelper");var lightTarget=sceneContext.scene.view.controls.target.clone();lightTarget.z=0;// Compute azimuth / zenith and sun position
7
+ */import React from"react";import Sun from"@giro3d/giro3d/core/geographic/Sun.js";import{MapLightingMode}from"@giro3d/giro3d/entities/MapLightingOptions";import PropTypes from"prop-types";import suncalc from"suncalc";import{AmbientLight,BasicShadowMap,CameraHelper,DirectionalLight,DirectionalLightHelper,PCFShadowMap,PCFSoftShadowMap,VSMShadowMap}from"three";import CoordinatesUtils from"../../utils/CoordinatesUtils";import LocaleUtils from"../../utils/LocaleUtils";import Icon from"../Icon";import SideBar from"../SideBar";import NumberInput from"../widgets/NumberInput";import ToggleSwitch from"../widgets/ToggleSwitch";import"./style/Map3DLight.css";var Map3DLight=/*#__PURE__*/function(_React$Component){function Map3DLight(){var _this;_classCallCheck(this,Map3DLight);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}_this=_callSuper(this,Map3DLight,[].concat(args));_defineProperty(_this,"state",{showAdvanced:false,lightParams:{day:182,time:720,helpersVisible:false,ambientLightIntensity:2.1,directionalLightIntensity:1.8,zFactor:1,lightElevationLayersOnly:false,shadowsEnabled:true,shadowType:PCFShadowMap,shadowMapSize:4096,shadowBias:-0.0001,sunDistance:80000,normalBias:0,shadowIntensity:0.9,shadowVolumeNear:60000,shadowVolumeFar:100000},dayAnimation:false,dayAnimationSettings:false,dayStep:30,timeAnimation:false,timeAnimationSettings:false,timeStep:30});_defineProperty(_this,"onHide",function(){clearInterval(_this.animationInterval);_this.setState({dayAnimation:false,timeAnimation:false})});_defineProperty(_this,"renderBody",function(){var lightParams=_this.state.lightParams;var dateFormatter=function dateFormatter(day){var date=new Date(new Date().getFullYear(),0,day);return"".concat(String(date.getDate()).padStart(2,"0"),".").concat(String(date.getMonth()+1).padStart(2,"0"))};var timeFormatter=function timeFormatter(time){return"".concat(String(Math.trunc(time/60)).padStart(2,"0"),":").concat(String(time%60).padStart(2,"0"))};return/*#__PURE__*/React.createElement("div",{className:"maplight3d-body"},/*#__PURE__*/React.createElement("table",null,/*#__PURE__*/React.createElement("tbody",null,/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.date")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("div",{className:"map3d-animation-slider"},/*#__PURE__*/React.createElement(Icon,{icon:_this.state.dayAnimation?"square":"triangle-right",onClick:_this.toggleDayAnimation}),_this.renderSlider("day",1,365,1,dateFormatter),/*#__PURE__*/React.createElement(Icon,{className:_this.state.dayAnimationSettings?"map3d-animation-settings-active":"",icon:"cog",onClick:function onClick(){return _this.setState(function(state){return{dayAnimationSettings:!state.dayAnimationSettings}})}})))),_this.state.dayAnimationSettings?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",{colSpan:"2"},/*#__PURE__*/React.createElement("div",{className:"maplight3d-animation-settings"},/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("maplight3d.animationstep"),":"),/*#__PURE__*/React.createElement(NumberInput,{max:60,min:1,onChange:function onChange(dayStep){return _this.setState({dayStep:dayStep})},suffix:" "+LocaleUtils.tr("maplight3d.dayspersec"),value:_this.state.dayStep})))):null,/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.time")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("div",{className:"map3d-animation-slider"},/*#__PURE__*/React.createElement(Icon,{icon:_this.state.timeAnimation?"square":"triangle-right",onClick:_this.toggleTimeAnimation}),_this.renderSlider("time",0,1439,1,timeFormatter),/*#__PURE__*/React.createElement(Icon,{className:_this.state.timeAnimationSettings?"map3d-animation-settings-active":"",icon:"cog",onClick:function onClick(){return _this.setState(function(state){return{timeAnimationSettings:!state.timeAnimationSettings}})}})))),_this.state.timeAnimationSettings?/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",{colSpan:"2"},/*#__PURE__*/React.createElement("div",{className:"maplight3d-animation-settings"},/*#__PURE__*/React.createElement("span",null,LocaleUtils.tr("maplight3d.animationstep"),":"),/*#__PURE__*/React.createElement(NumberInput,{max:60,min:1,onChange:function onChange(timeStep){return _this.setState({timeStep:timeStep})},suffix:" "+LocaleUtils.tr("maplight3d.minspersec"),value:_this.state.timeStep})))):null,/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.ambientLightIntensity")),/*#__PURE__*/React.createElement("td",null,_this.renderSlider("ambientLightIntensity",0,5,0.1))),/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.directionalLightIntensity")),/*#__PURE__*/React.createElement("td",null,_this.renderSlider("directionalLightIntensity",0,10,0.1))),/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadows")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(ToggleSwitch,{active:lightParams.shadowsEnabled,onChange:function onChange(value){return _this.updateLightParams("shadowsEnabled",value)}}))),/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowintensity")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:1,disabled:!lightParams.shadowsEnabled,max:2,min:0,onChange:function onChange(value){return _this.updateLightParams("shadowIntensity",value)},value:lightParams.shadowIntensity}))),/*#__PURE__*/React.createElement("tr",null,/*#__PURE__*/React.createElement("td",{className:"maplight3d-advanced",colSpan:"2"},/*#__PURE__*/React.createElement("label",null,/*#__PURE__*/React.createElement("input",{checked:_this.state.showAdvanced,onChange:function onChange(ev){return _this.setState(function(state){return{showAdvanced:!state.showAdvanced}})},type:"checkbox"})," ",LocaleUtils.tr("maplight3d.showadvanced")))),_this.state.showAdvanced?[/*#__PURE__*/React.createElement("tr",{key:"helpersVisible"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.helpersVisible")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(ToggleSwitch,{active:lightParams.helpersVisible,onChange:function onChange(value){return _this.updateLightParams("helpersVisible",value)}}))),/*#__PURE__*/React.createElement("tr",{key:"zFactor"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.zFactor")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("input",{max:10,min:0,onChange:function onChange(ev){return _this.updateLightParams("zFactor",ev.target.value)},step:0.1,type:"range",value:lightParams.zFactor}))),/*#__PURE__*/React.createElement("tr",{key:"shadowType"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowType")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement("select",{onChange:function onChange(ev){return _this.updateLightParams("shadowType",parseInt(ev.target.value,10))},value:lightParams.shadowType},/*#__PURE__*/React.createElement("option",{value:BasicShadowMap},"BasicShadowMap"),/*#__PURE__*/React.createElement("option",{value:PCFShadowMap},"PCFShadowMap"),/*#__PURE__*/React.createElement("option",{value:PCFSoftShadowMap},"PCFSoftShadowMap"),/*#__PURE__*/React.createElement("option",{value:VSMShadowMap},"VSMShadowMap")))),/*#__PURE__*/React.createElement("tr",{key:"shadowMapSize"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowMapSize")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:0,max:8192,min:64,onChange:function onChange(value){return _this.updateLightParams("shadowMapSize",value)},value:lightParams.shadowMapSize}))),/*#__PURE__*/React.createElement("tr",{key:"shadowBias"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowBias")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:5,max:0.01,min:-0.01,onChange:function onChange(value){return _this.updateLightParams("shadowBias",value)},value:lightParams.shadowBias}))),/*#__PURE__*/React.createElement("tr",{key:"normalBias"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.normalBias")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:1,max:10,min:-10,onChange:function onChange(value){return _this.updateLightParams("normalBias",value)},value:lightParams.normalBias}))),/*#__PURE__*/React.createElement("tr",{key:"shadowVolumeNear"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowVolumeNear")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:0,max:100000,min:100,onChange:function onChange(value){return _this.updateLightParams("shadowVolumeNear",value)},value:lightParams.shadowVolumeNear}))),/*#__PURE__*/React.createElement("tr",{key:"shadowVolumeFar"},/*#__PURE__*/React.createElement("td",null,LocaleUtils.tr("maplight3d.shadowVolumeFar")),/*#__PURE__*/React.createElement("td",null,/*#__PURE__*/React.createElement(NumberInput,{decimals:0,max:100000,min:100,onChange:function onChange(value){return _this.updateLightParams("shadowVolumeFar",value)},value:lightParams.shadowVolumeFar})))]:null)))});_defineProperty(_this,"toggleDayAnimation",function(){_this.setState(function(state){return{dayAnimation:!state.dayAnimation,timeAnimation:false}},function(){clearInterval(_this.animationInterval);if(_this.state.dayAnimation){_this.animationInterval=setInterval(function(){_this.updateLightParams("day",(_this.state.lightParams.day+_this.state.dayStep/10)%365)},100)}})});_defineProperty(_this,"toggleTimeAnimation",function(){_this.setState(function(state){return{timeAnimation:!state.timeAnimation,dayAnimation:false}},function(){clearInterval(_this.animationInterval);if(_this.state.timeAnimation){_this.animationInterval=setInterval(function(){_this.updateLightParams("time",(_this.state.lightParams.time+_this.state.timeStep/10)%1440)},100)}})});_defineProperty(_this,"renderSlider",function(key,min,max,step){var labelFormatter=arguments.length>4&&arguments[4]!==undefined?arguments[4]:undefined;var value=_this.state.lightParams[key];var parseValue=function parseValue(x){return Number.isInteger(step)?parseInt(x,10):parseFloat(x)};labelFormatter=labelFormatter!==null&&labelFormatter!==void 0?labelFormatter:function(x){return x.toFixed(-Math.log10(step))};return/*#__PURE__*/React.createElement("div",{className:"maplight3d-slider"},/*#__PURE__*/React.createElement("input",{max:max,min:min,onChange:function onChange(ev){return _this.updateLightParams(key,parseValue(ev.target.value))},step:step,type:"range",value:value}),/*#__PURE__*/React.createElement("div",{className:"maplight3d-slider-label"},/*#__PURE__*/React.createElement("span",{style:{left:(value-min)*100/(max-min)+"%"}},labelFormatter(value))))});_defineProperty(_this,"updateLightParams",function(key,value){_this.setState(function(state){return{lightParams:_objectSpread(_objectSpread({},state.lightParams),{},_defineProperty({},key,value))}})});_defineProperty(_this,"computeShadowVolume",function(directionalLight,lightParams){if(!lightParams.shadowsEnabled){_this.props.sceneContext.scene.renderer.shadowMap.enabled=false;return}var cameraHeight=_this.props.sceneContext.scene.view.camera.position.z;var targetHeight=_this.props.sceneContext.scene.view.controls.target.z;var volumeSize=Math.min(20000,Math.max(1000,cameraHeight-targetHeight));directionalLight.shadow.camera.top=volumeSize;directionalLight.shadow.camera.bottom=-volumeSize;directionalLight.shadow.camera.left=-volumeSize;directionalLight.shadow.camera.right=volumeSize;directionalLight.shadow.camera.near=lightParams.shadowVolumeNear;directionalLight.shadow.camera.far=lightParams.shadowVolumeFar;_this.props.sceneContext.scene.renderer.shadowMap.enabled=true});_defineProperty(_this,"setLighting",function(){var sceneContext=_this.props.sceneContext;var lightParams=_this.state.lightParams;var ambientLight=sceneContext.getSceneObject("__ambientLight");var directionalLight=sceneContext.getSceneObject("__directionalLight");var lightTarget=sceneContext.scene.view.controls.target.clone();lightTarget.z=0;// Compute azimuth / zenith and sun position
8
8
  var date=new Date(new Date().getFullYear(),0,lightParams.day,Math.trunc(lightParams.time/60),lightParams.time%60);var latlon=CoordinatesUtils.reproject([lightTarget.x,lightTarget.y],sceneContext.mapCrs,"EPSG:4326");var sunPos=suncalc.getPosition(date,latlon[1],latlon[0]);var zenith=90-sunPos.altitude/Math.PI*180;var azimuth=180+sunPos.azimuth/Math.PI*180;var sunLocalPos=Sun.getLocalPosition({point:lightTarget,zenith:zenith,azimuth:azimuth,distance:lightParams.sunDistance});directionalLight.position.copy(sunLocalPos);// Set lighting params
9
9
  sceneContext.map.lighting.enabled=true;sceneContext.map.lighting.mode=lightParams.shadowsEnabled?MapLightingMode.LightBased:MapLightingMode.Hillshade;sceneContext.map.lighting.elevationLayersOnly=lightParams.lightElevationLayersOnly;sceneContext.map.lighting.hillshadeAzimuth=azimuth;sceneContext.map.lighting.hillshadeZenith=zenith;sceneContext.map.lighting.zFactor=lightParams.zFactor;sceneContext.scene.notifyChange(sceneContext.map);sceneContext.scene.renderer.shadowMap.type=lightParams.shadowType;var zenithAttenuation=Math.pow(zenith/90,4);ambientLight.intensity=lightParams.ambientLightIntensity-3*zenithAttenuation;directionalLight.intensity=lightParams.directionalLightIntensity-0.5*zenithAttenuation;directionalLight.shadow.mapSize.set(lightParams.shadowMapSize,lightParams.shadowMapSize);directionalLight.shadow.bias=lightParams.shadowBias;directionalLight.shadow.normalBias=lightParams.normalBias;directionalLight.shadow.intensity=lightParams.shadowIntensity;directionalLight.target.position.copy(lightTarget);_this.computeShadowVolume(directionalLight,lightParams);// Update scene
10
- directionalLight.updateMatrixWorld(true);directionalLight.target.updateMatrixWorld(true);directionalLight.shadow.updateMatrices(directionalLight);directionalLight.shadow.camera.updateProjectionMatrix();directionalLight.shadow.camera.updateMatrix();directionalLightHelper.visible=lightParams.helpersVisible;directionalLightHelper.update();directionalLightHelper.updateMatrixWorld(true);shadowCameraHelper.visible=lightParams.helpersVisible;shadowCameraHelper.update();shadowCameraHelper.updateMatrixWorld(true);sceneContext.scene.notifyChange()});return _this}_inherits(Map3DLight,_React$Component);return _createClass(Map3DLight,[{key:"componentDidMount",value:function componentDidMount(){this.animationInterval=null;this.componentDidUpdate({})}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps,prevState){var _prevProps$sceneConte;if(this.props.sceneContext.scene!==((_prevProps$sceneConte=prevProps.sceneContext)===null||_prevProps$sceneConte===void 0?void 0:_prevProps$sceneConte.scene)){var ambientLight=new AmbientLight(16777215,this.state.ambientLightIntensity);this.props.sceneContext.addSceneObject("__ambientLight",ambientLight);var directionalLight=new DirectionalLight(16777215,this.state.directionalLightIntensity);directionalLight.castShadow=true;this.props.sceneContext.addSceneObject("__directionalLight",directionalLight);var directionalLightHelper=new DirectionalLightHelper(directionalLight,200,"white");this.props.sceneContext.addSceneObject("__directionalLightHelper",directionalLightHelper);directionalLightHelper.visible=this.state.lightParams.helpersVisible;var shadowCameraHelper=new CameraHelper(directionalLight.shadow.camera);this.props.sceneContext.addSceneObject("__shadowCameraHelper",shadowCameraHelper);shadowCameraHelper.visible=this.state.lightParams.helpersVisible;this.props.sceneContext.scene.view.controls.addEventListener("change",this.setLighting);this.setLighting()}else if(this.state.lightParams!==prevState.lightParams){this.setLighting()}}},{key:"componentWillUnmount",value:function componentWillUnmount(){clearInterval(this.lightPositionInterval)}},{key:"render",value:function render(){var _this2=this;return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement(SideBar,{icon:"light",id:"MapLight3D",onHide:this.onHide,title:LocaleUtils.tr("appmenu.items.MapLight3D"),width:"25em"},function(){return{body:_this2.renderBody()}}))}}])}(React.Component);_defineProperty(Map3DLight,"propTypes",{sceneContext:PropTypes.object});export{Map3DLight as default};
10
+ directionalLight.updateMatrixWorld(true);directionalLight.target.updateMatrixWorld(true);directionalLight.shadow.updateMatrices(directionalLight);directionalLight.shadow.camera.updateProjectionMatrix();directionalLight.shadow.camera.updateMatrix();if(lightParams.helpersVisible){var directionalLightHelper=sceneContext.getSceneObject("__directionalLightHelper");directionalLightHelper.update();directionalLightHelper.updateMatrixWorld(true);var shadowCameraHelper=sceneContext.getSceneObject("__shadowCameraHelper");shadowCameraHelper.update();shadowCameraHelper.updateMatrixWorld(true)}sceneContext.scene.notifyChange()});return _this}_inherits(Map3DLight,_React$Component);return _createClass(Map3DLight,[{key:"componentDidMount",value:function componentDidMount(){this.animationInterval=null;this.componentDidUpdate({})}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps,prevState){var _prevProps$sceneConte;if(this.props.sceneContext.scene!==((_prevProps$sceneConte=prevProps.sceneContext)===null||_prevProps$sceneConte===void 0?void 0:_prevProps$sceneConte.scene)){var ambientLight=new AmbientLight(16777215,this.state.ambientLightIntensity);this.props.sceneContext.addSceneObject("__ambientLight",ambientLight);var directionalLight=new DirectionalLight(16777215,this.state.directionalLightIntensity);directionalLight.castShadow=true;this.props.sceneContext.addSceneObject("__directionalLight",directionalLight);if(this.state.lightParams.helpersVisible){var directionalLightHelper=new DirectionalLightHelper(directionalLight,200,"white");this.props.sceneContext.addSceneObject("__directionalLightHelper",directionalLightHelper);var shadowCameraHelper=new CameraHelper(directionalLight.shadow.camera);this.props.sceneContext.addSceneObject("__shadowCameraHelper",shadowCameraHelper)}this.props.sceneContext.scene.view.controls.addEventListener("change",this.setLighting);this.setLighting()}else if(this.state.lightParams!==prevState.lightParams){if(this.state.lightParams.helpersVisible&&!prevState.lightParams.helpersVisible){var _directionalLight=this.props.sceneContext.getSceneObject("__directionalLight");var _directionalLightHelper=new DirectionalLightHelper(_directionalLight,200,"white");this.props.sceneContext.addSceneObject("__directionalLightHelper",_directionalLightHelper);var _shadowCameraHelper=new CameraHelper(_directionalLight.shadow.camera);this.props.sceneContext.addSceneObject("__shadowCameraHelper",_shadowCameraHelper)}else if(prevState.lightParams.helpersVisible&&!this.state.lightParams.helpersVisible){this.props.sceneContext.removeSceneObject("__directionalLightHelper");this.props.sceneContext.removeSceneObject("__shadowCameraHelper")}this.setLighting()}}},{key:"componentWillUnmount",value:function componentWillUnmount(){clearInterval(this.lightPositionInterval)}},{key:"render",value:function render(){var _this2=this;return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement(SideBar,{icon:"light",id:"MapLight3D",onHide:this.onHide,title:LocaleUtils.tr("appmenu.items.MapLight3D"),width:"25em"},function(){return{body:_this2.renderBody()}}))}}])}(React.Component);_defineProperty(Map3DLight,"propTypes",{sceneContext:PropTypes.object});export{Map3DLight as default};