diff --git a/src/mapboxgl/tdt/map-switcher/TdtMapSwitcherViewModel.js b/src/mapboxgl/tdt/map-switcher/TdtMapSwitcherViewModel.js index 4382792c..2184394a 100644 --- a/src/mapboxgl/tdt/map-switcher/TdtMapSwitcherViewModel.js +++ b/src/mapboxgl/tdt/map-switcher/TdtMapSwitcherViewModel.js @@ -50,8 +50,9 @@ export default class TdtMapSwitcherViewModel extends mapboxgl.Evented { } togglerLabelLayer(isChecked) { - const labelLayer = this.map && this.map.getLayer(geti18n().tc(`tdtMapSwitcher.Tianditu${this.tdtLabelType}`)); - labelLayer && this.webmap.changeItemVisible(geti18n().tc(`tdtMapSwitcher.Tianditu${this.tdtLabelType}`), isChecked); + const appreciableLayers = this.webmap && this.webmap.getAppreciableLayers(); + const labelLayer = appreciableLayers.find(layer => layer.id === geti18n().tc(`tdtMapSwitcher.Tianditu${this.tdtLabelType}`)); + labelLayer && this.webmap.changeItemVisible(labelLayer, isChecked); } addLayer(sources, layers, fromTdt = true) { diff --git a/src/mapboxgl/tdt/map-switcher/__tests__/TdtMapSwitcher.spec.js b/src/mapboxgl/tdt/map-switcher/__tests__/TdtMapSwitcher.spec.js index d9f2b3e3..a7d89ea2 100644 --- a/src/mapboxgl/tdt/map-switcher/__tests__/TdtMapSwitcher.spec.js +++ b/src/mapboxgl/tdt/map-switcher/__tests__/TdtMapSwitcher.spec.js @@ -89,6 +89,25 @@ describe('TdtMapSwitcher.vue', () => { let mockOnOptions; const webmap = { getLayerList: () => layerCatalogs, + getAppreciableLayers: () => { + return [ + { + "dataSource": {}, + "id": "tdtMapSwitcher.TiandituCia", + "title": "tdtMapSwitcher.TiandituCia", + "renderSource": { + "id": "tdtMapSwitcher.TiandituCia", + "type": "raster" + }, + "renderLayers": [ + "tdtMapSwitcher.TiandituCia" + ], + "type": "raster", + "themeSetting": {}, + "visible": true + } + ] + }, changeItemVisible: () => { mockOnOptions.layersupdated(); },