From bdc9ae94a45d43455aa00fb793feb5265d43ca20 Mon Sep 17 00:00:00 2001 From: Francesco Boccacci Date: Tue, 11 Feb 2025 16:38:18 +0100 Subject: [PATCH] :bug: Invalid dependency Api (iframe + editing) (#729) * :bug: Fix method call to retrieve API from plugin service in BaseIframeService * use `PluginsRegistry.getPlugin('editing')` as api --------- Co-authored-by: Raruto (cherry picked from commit c3ef609d57360f2bb5e2009c854fb83a4fba3b2a) --- src/components/MapControlGeocoding.vue | 2 +- src/services/iframe.js | 39 +++++++++----------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/components/MapControlGeocoding.vue b/src/components/MapControlGeocoding.vue index e06e2def8..f46724b95 100644 --- a/src/components/MapControlGeocoding.vue +++ b/src/components/MapControlGeocoding.vue @@ -682,7 +682,7 @@ export default { }); // start editing session - await editing.getApi().addLayerFeature({ layerId: layerId, feature: _feature }); + await editing.addLayerFeature({ layerId: layerId, feature: _feature }); } catch(e) { console.warn(e); diff --git a/src/services/iframe.js b/src/services/iframe.js index de6599aca..58bd64b2a 100644 --- a/src/services/iframe.js +++ b/src/services/iframe.js @@ -12,6 +12,7 @@ import Projections from 'store/projections'; import { normalizeEpsg } from 'utils/normalizeEpsg'; import { createSingleFieldParameter } from 'utils/createSingleFieldParameter'; import { getUniqueDomId } from 'utils/getUniqueDomId'; +import { waitFor } from 'utils/waitFor'; /** * @param epsg: Number Code of epsg Ex.4326 @@ -266,37 +267,23 @@ class BaseIframeService extends G3WObject { layers = {} } = {}) { this.layers = layers; + // skip when plugin is not in configuration (ie. added to the application) - if (!ApplicationState.configurationPlugins.includes(this.pluginName)) { + if ('editing' !== this.pluginName || !ApplicationState.configurationPlugins.includes('editing')) { return; } - const plugin = PluginsRegistry.getPlugin(this.pluginName); - if (plugin) { - this.setDependencyApi(plugin.getApi()); - this.setReady(true); - } else { - PluginsRegistry - .onafter('registerPlugin', async plugin => { - await plugin.isReady(); - if (plugin.getName() === this.pluginName) { - this.setDependencyApi(plugin.getApi()); - this.setReady(true); - } - }) - } - } - /** - * ORIGINAL SOURCE: src/app/core/iframe/services/plugins/service.js@3.9.0 - * - * @virtual method need to be implemented by subclasses - * - * @since 3.9.1 - */ - setDependencyApi(api = {}) { - this.dependencyApi = api; - } + // wait until "editing" plugin is loaded + await waitFor(() => PluginsRegistry.getPlugin('editing')); + + // BACKOMP v3.x + this.dependencyApi = PluginsRegistry.getPlugin('editing'); + this.dependencyApi.getEditableLayersId = this.dependencyApi.getEditableLayersId || (() => Object.keys(this.dependencyApi.getEditableLayers())); + this.dependencyApi.hidePanel = this.dependencyApi.hidePanel || this.dependencyApi.hideEditingPanel; + this.dependencyApi.resetDefault = this.dependencyApi.resetDefault || this.dependencyApi.resetAPIDefault; + this.setReady(true); + } /** * ORIGINAL SOURCE: src/app/core/iframe/services/plugins/service.js@3.9.0 *