diff --git a/uvdat/core/models/styles.py b/uvdat/core/models/styles.py index 1c573524..6a239f6f 100644 --- a/uvdat/core/models/styles.py +++ b/uvdat/core/models/styles.py @@ -61,13 +61,13 @@ def save_style_configs(self, style_spec): color_config.visible = color_spec.get("visible", True) color_config.use_feature_props = color_spec.get("use_feature_props", True) single_color = color_spec.get("single_color") + colormap_spec = color_spec.get("colormap") if single_color is not None: color_config.single_color = single_color with contextlib.suppress(ColorConfig.colormap.RelatedObjectDoesNotExist): color_config.colormap.delete() - else: + elif colormap_spec is not None: color_config.single_color = "" - colormap_spec = color_spec.get("colormap") colormap = Colormap.objects.get(id=colormap_spec.get("id")) map_range = colormap_spec.get("range") or [None, None] colormap_config_args = { diff --git a/web/src/components/sidebars/LayerStyle.vue b/web/src/components/sidebars/LayerStyle.vue index f67adda6..daa782ae 100644 --- a/web/src/components/sidebars/LayerStyle.vue +++ b/web/src/components/sidebars/LayerStyle.vue @@ -160,7 +160,7 @@ function selectStyle(style: LayerStyle) { function fetchRasterBands() { if (!currentStyleSpec.value) return if (showRasterOptions.value) { - setGroupColorMode('all', 'colormap') + setGroupColorMode('all', 'none') if (frames.value.length) { if (currentFrame.value?.raster) { rasterBands.value = currentFrame.value.raster.metadata.bands; @@ -209,7 +209,7 @@ function setCurrentColorGroups(different: boolean | null) { currentStyleSpec.value.colors = availableGroups.value.map((name) => { return { ...all, visible: true, use_feature_props: true, name } }) - availableGroups.value.forEach((name) => setGroupColorMode(name, 'colormap')) + availableGroups.value.forEach((name) => setGroupColorMode(name, 'none')) } else if (showVectorOptions.value) { currentStyleSpec.value.colors = availableGroups.value.map((name) => { return { ...JSON.parse(JSON.stringify(all)), visible: true, name } @@ -228,7 +228,7 @@ function setCurrentColorGroups(different: boolean | null) { } else { currentStyleSpec.value.colors = [...defaultStyle.colors] } - if (showRasterOptions.value) setGroupColorMode('all', 'colormap') + if (showRasterOptions.value) setGroupColorMode('all', 'none') currentGroups.value['color'] = 'all' } } @@ -250,8 +250,10 @@ function setGroupColorMode(groupName: string, colorMode: string) { }, single_color: undefined, } - } else if (!c.single_color) { + } else if (colorMode === 'single_color' && !c.single_color) { return {...c, colormap: undefined, single_color: styleStore.getDefaultColor(props.layer.id)} + } else if (colorMode === 'none') { + return {...c, colormap: undefined, single_color: undefined} } } return c @@ -523,7 +525,7 @@ onMounted(resetCurrentStyle) /> -
+
Edit Style (Layer: {{ layer.name }}) @@ -659,6 +661,47 @@ onMounted(resetCurrentStyle) + Color scheme + +
+ + None + 1 Color + Colormap + + + + + + + +
+ + + Colormap - + Colormap class - + No. of colors - + Range - + Clamping marker.color ) } + } else if (colorSpec.single_color) { + colorQuery.palette = colorSpec.single_color } if (colorSpec.name === 'all') { - if (colorSpec.colormap && colorSpec.visible) query = colorQuery + if (colorSpec.visible) query = colorQuery } else { if (!query.bands) query.bands = [] colorQuery.band = colorSpec.name.replace('Band ', '') - if (colorSpec.colormap && colorSpec.visible) query.bands.push(colorQuery) + if (colorSpec.visible) query.bands.push(colorQuery) } }) styleSpec.filters.forEach((f) => { @@ -129,7 +131,6 @@ function getRasterTilesQuery(styleSpec: StyleSpec, colormaps: Colormap[]) { query[f.filter_by] = f.list[0] } }) - if (!Object.keys(query).length) return undefined return query; } @@ -336,17 +337,6 @@ export const useStyleStore = defineStore('style', () => { } function getDefaultStyleSpec(raster: RasterData | null | undefined, layerId: number): StyleSpec { - let range: [number, number] | undefined; - let absMin: number | undefined, absMax: number | undefined; - if (raster) { - Object.values(raster.metadata.bands).forEach(({ min, max }) => { - if (!absMin || min < absMin) absMin = min; - if (!absMax || max < absMax) absMax = max; - }) - } - if (absMin !== undefined && absMax !== undefined) { - range = [Math.floor(absMin), Math.ceil(absMax)] as [number, number]; - } return { opacity: 1, default_frame: 0, @@ -356,13 +346,7 @@ export const useStyleStore = defineStore('style', () => { visible: true, use_feature_props: true, single_color: raster ? undefined : getDefaultColor(layerId), - colormap: raster ? { - range, - color_by: 'value', - discrete: false, - n_colors: 5, - null_color: 'transparent' - } : undefined, + colormap: undefined, } ], sizes: [ @@ -476,14 +460,11 @@ export const useStyleStore = defineStore('style', () => { const source = map.getSource(mapLayer.source) as RasterTileSource; const sourceURL = mapStore.rasterSourceTileURLs[mapLayer.source]; if (source && sourceURL) { - const oldQuery = new URLSearchParams(sourceURL.split('?')[1]); const newQueryParams: { projection: string, style?: string } = { projection: 'epsg:3857' }; - if (rasterTilesQuery) newQueryParams.style = JSON.stringify(rasterTilesQuery); + newQueryParams.style = JSON.stringify(rasterTilesQuery); const newQuery = new URLSearchParams(newQueryParams); - if (newQuery.toString() !== oldQuery.toString()) { - tileURL = sourceURL.split('?')[0] + '?' + newQuery.toString(); - return { paint, tileURL } - } + tileURL = sourceURL.split('?')[0] + '?' + newQuery.toString(); + return { paint, tileURL } } } return { paint };