diff --git a/components/IdentifyViewer.jsx b/components/IdentifyViewer.jsx index 5438ad67a..1e898856f 100644 --- a/components/IdentifyViewer.jsx +++ b/components/IdentifyViewer.jsx @@ -314,7 +314,7 @@ class IdentifyViewer extends React.Component { this.export({[layer]: [result]}); }; export = (json, clipboard = false) => { - const exporter = [...BuiltinExporters, ...this.props.customExporters].find(entry => entry.id === this.state.exportFormat); + const exporter = this.getExporters().find(entry => entry.id === this.state.exportFormat); if (exporter) { if (!this.props.exportGeometry) { json = Object.entries(json).reduce((res, [layerId, features]) => ( @@ -422,9 +422,7 @@ class IdentifyViewer extends React.Component { ); }); } - if (this.props.attributeCalculator) { - rows = rows.concat(this.props.attributeCalculator(layer, result)); - } + rows.push(...this.computeExtraAttributes(layer, result)); if (featureReportTemplate) { rows = rows.concat( @@ -450,7 +448,7 @@ class IdentifyViewer extends React.Component { extraattribs = (
- {this.props.attributeCalculator ? this.props.attributeCalculator(layer, result) : null} + {this.computeExtraAttributes(layer, result)} {featureReportTemplate ? ( + + + + )); + } else if (row.length === 1) { + rows.push(( + + + + )); + } + }); + if (this.props.attributeCalculator) { + rows.push(...this.props.attributeCalculator(layer, result)); + } + return rows; + }; + getExporters = () => { + return [ + ...BuiltinExporters, + ...this.props.customExporters, + ...Object.values(window.qwc2.__identifyExportes || []) + ]; + }; setIframeContent = (iframe, html) => { if (iframe.getAttribute("identify-content-set")) { return; diff --git a/components/PluginsContainer.jsx b/components/PluginsContainer.jsx index 62eac5265..0d9dcab14 100644 --- a/components/PluginsContainer.jsx +++ b/components/PluginsContainer.jsx @@ -27,7 +27,7 @@ class PluginsContainer extends React.Component { renderPlugins = (pluginsConfig) => { const allPlugins = { ...this.props.plugins, - ...(window.qwc2?.customPlugins ?? {}) + ...(window.qwc2?.__customPlugins ?? {}) }; return pluginsConfig.map((pluginConf, idx) => { const Plugin = allPlugins[pluginConf.name + "Plugin"]; diff --git a/package.json b/package.json index 4843aa25f..42a58c28b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "qwc2", - "version": "2024.04.16-master", + "version": "2024.04.18-master", "description": "QGIS Web Client 2 core", "author": "Sourcepole AG", "license": "BSD-2-Clause", diff --git a/plugins/API.jsx b/plugins/API.jsx index af4e3e98e..ea6786f4d 100644 --- a/plugins/API.jsx +++ b/plugins/API.jsx @@ -145,8 +145,11 @@ import VectorLayerUtils from '../utils/VectorLayerUtils'; */ class API extends React.Component { componentDidMount() { - window.qwc2 = {}; - window.qwc2.customPlugins = {}; + window.qwc2 = { + __customPlugins: {}, + __attributeCalculators: {}, + __identifyExportes: {} + }; // Auto-binded functions for (const prop of Object.keys(this.props)) { window.qwc2[prop] = this.props[prop]; @@ -155,6 +158,10 @@ class API extends React.Component { window.qwc2.LayerRole = LayerRole; window.qwc2.addPlugin = this.addPlugin; window.qwc2.removePlugin = this.removePlugin; + window.qwc2.addIdentifyAttributeCalculator = this.addIdentifyAttributeCalculator; + window.qwc2.removeIdentifyAttributeCalculator = this.removeIdentifyAttributeCalculator; + window.qwc2.addIdentifyExporter = this.addIdentifyExporter; + window.qwc2.removeIdentifyExporter = this.removeIdentifyExporter; window.qwc2.addExternalLayer = this.addExternalLayer; window.qwc2.drawScratch = this.drawScratch; window.qwc2.drawGeometry = this.drawGeometry; @@ -251,7 +258,19 @@ class API extends React.Component { }; removePlugin = (name) => { this.props.unregisterCustomPlugin(name); - delete window.qwc2.customPlugins[name]; + delete window.qwc2.__customPlugins[name]; + }; + addIdentifyAttributeCalculator = (name, calcFunc) => { + window.qwc2.__attributeCalculators[name] = calcFunc; + }; + removeIdentifyAttributeCalculator = (name) => { + delete window.qwc2.__attributeCalculators[name]; + }; + addIdentifyExporter = (name, exporterConfig) => { + window.qwc2.__identifyExportes[name] = exporterConfig; + }; + removeIdentifyExporter = (name) => { + delete window.qwc2.__identifyExportes[name]; }; addExternalLayer = (resource, beforeLayerName = null, sublayers = true) => { const params = LayerUtils.splitLayerUrlParam(resource);
@@ -528,7 +526,8 @@ class IdentifyViewer extends React.Component { ); } // "el.style.background='inherit'": HACK to trigger an additional repaint, since Safari/Chrome on iOS render the element cut off the first time - const clipboardExportDisabled = ([...BuiltinExporters, ...this.props.customExporters].find(entry => entry.id === this.state.exportFormat) || {}).allowClipboard !== true; + const exporters = this.getExporters(); + const clipboardExportDisabled = exporters.find(entry => entry.id === this.state.exportFormat)?.allowClipboard !== true; return (
{ if (el) el.style.background = 'inherit'; } }> {body} @@ -537,12 +536,7 @@ class IdentifyViewer extends React.Component { {LocaleUtils.tr("identify.exportformat")} 
{row[0]}{row[1]}
{row[0]}