Skip to content

Commit

Permalink
Ensure switching layer legend styles change after changing map theme (#…
Browse files Browse the repository at this point in the history
…552) (#559)

* Pass syle options attribute

* Pass right style layer of current map theme

* Comment

* refactor function `changeMapTheme`

* debug `stylesfeaturecount` is undefined

* 🐛 skip if a layer hasn't feature count option set on QGIS project

* jsdoc

* Style categories is not related to legend position but on map_theme

---------

Co-authored-by: Raruto <[email protected]>
(cherry picked from commit c84e2be)

Co-authored-by: Francesco Boccacci <[email protected]>
  • Loading branch information
github-actions[bot] and volterra79 authored Jan 31, 2024
1 parent 349c602 commit 3e7a475
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
8 changes: 6 additions & 2 deletions src/app/core/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1238,12 +1238,16 @@ proto.getFeatureCount = function() {
/**
* @param style
*
* @returns {Promise<Object>}
* @returns { Promise<Object | void>}
*
* @since 3.8.0
*/
proto.getStyleFeatureCount = async function(style) {
if ("undefined" === typeof this.state.stylesfeaturecount[style]) {
// skip when layer hasn't feature count option set on QGIS project
if (undefined === this.state.stylesfeaturecount) {
return;
}
if (undefined === this.state.stylesfeaturecount[style]) {
try {
const { result, data } = await XHR.post({
url: `${this.config.urls.featurecount}${this.getId()}/`,
Expand Down
34 changes: 18 additions & 16 deletions src/components/Catalog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,27 +194,29 @@ export default {

/**
* Change view
*
* @fires CatalogEventBus~layer-change-style
*/
async changeMapTheme(map_theme) {
GUI.closeContent();
const changes = await this.$options.service.changeMapTheme(map_theme);
const changeStyleLayersId = Object.keys(changes.layers).filter(layerId => {
if (changes.layers[layerId].style) {
if (!changes.layers[layerId].visible) {
const layer = CatalogLayersStoresRegistry.getLayerById(layerId);
// clear categories
layer.clearCategories();
layer.change();
}
return true;

// get all layers with styles
const changes = (await this.$options.service.changeMapTheme(map_theme)).layers;
const layers = Object.keys(changes).filter(id => changes[id].style);
const styles = (await this.project.getMapThemeFromThemeName(map_theme)).styles;

// clear categories
layers.forEach(id => {
if (!changes[id].visible) {
const layer = CatalogLayersStoresRegistry.getLayerById(id);
layer.clearCategories();
layer.change();
}
});
if ('tab' === this.legend.place) {
VM.$emit('layer-change-style');
} else {
// get all layer tha changes style
changeStyleLayersId.forEach(layerId => { VM.$emit('layer-change-style', { layerId }); });
}

// apply styles on each layer
layers.forEach(id => VM.$emit('layer-change-style', { layerId: id, style: styles[id] }));

},

delegationClickEventTab(evt) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/CatalogLayerLegend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@
await this.setLayerCategories(false); // toggle categories.
}
}
} catch(err) {
console.warn('Error while changing layer style')
} catch(e) {
console.warn('Error while changing layer style', e)
}

this.loading = false;
Expand Down

0 comments on commit 3e7a475

Please sign in to comment.