Skip to content

Commit

Permalink
🐛 Invalid dependency Api (iframe + editing) (#729)
Browse files Browse the repository at this point in the history
* 🐛 Fix method call to retrieve API from plugin service in BaseIframeService

* use `PluginsRegistry.getPlugin('editing')` as api

---------

Co-authored-by: Raruto <[email protected]>
(cherry picked from commit c3ef609)
  • Loading branch information
volterra79 authored and github-actions[bot] committed Feb 11, 2025
1 parent 49d1cba commit bdc9ae9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/components/MapControlGeocoding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 13 additions & 26 deletions src/services/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/[email protected]
*
* @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/[email protected]
*
Expand Down

0 comments on commit bdc9ae9

Please sign in to comment.