Skip to content

Commit

Permalink
Updates COG rendering (#319)
Browse files Browse the repository at this point in the history
* Fix COG onreview by refresh not rendering

* Bump commit version
  • Loading branch information
meomancer authored Nov 13, 2024
1 parent 6c2073b commit ed66fc9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 33 deletions.
2 changes: 1 addition & 1 deletion django_project/_commit_hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0b044429cb4fda6ef2939f5e8ea987f83ae429fc
24aac4bc3175037479ab01decf2b01e9f0e5e42e
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@

import React, { useEffect, useState } from 'react';
import { SelectWithList } from "../SelectWithList";
import { fetchingData } from "../../../Requests";
import Grid from "@mui/material/Grid";
import Checkbox from "@mui/material/Checkbox";

import './style.scss';
import { dictDeepCopy } from "../../../utils/main";
import { updateColorPaletteData } from "../../../utils/Style";

import './style.scss';

/**
* Color Palette Selector
* @param colorPalette Color palette value
Expand All @@ -38,23 +37,16 @@ export default function ColorPaletteSelector(
) {
const [colorPalettes, setColorPalettes] = useState([]);


// On init
useEffect(() => {
(
async () => {
await fetchingData(
`/api/color/palette/list`,
{}, {}, (response, error) => {
if (response) {
updateColorPaletteData(response)
setColorPalettes(response);
if (!colorPalette) {
onChange(preferences.default_color_palette ? preferences.default_color_palette : response[0]?.id)
}
}
await updateColorPaletteData().then(response => {
setColorPalettes(response);
if (!colorPalette) {
onChange(preferences.default_color_palette ? preferences.default_color_palette : response[0]?.id)
}
)
})
}
)()
}, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import 'maplibre-gl/dist/maplibre-gl.css';
// Initialize cog
import { cogProtocol } from "@geomatico/maplibre-cog-protocol";
import { Variables } from "../../../../utils/Variables";
import { updateColorPaletteData } from "../../../../utils/Style";

maplibregl.addProtocol('cog', cogProtocol);

Expand Down Expand Up @@ -94,10 +95,18 @@ export default function MapConfig({ data, layerInput }) {
useEffect(() => {
if (map) {
const id = data.id ? `context-layer-${data.id}` : 'context-layer'
if ([Variables.LAYER.TYPE.RASTER_COG].includes(data.layer_type)) {
removeLayer(map, id)
if (Variables.LAYER.LIST.LAYERS_NEED_PALETTE.includes(data.layer_type)) {
removeLayer(map, id);
// Await color palette
(
async () => {
await updateColorPaletteData()
contextLayerRendering(id, data, layerInput, map)
}
)()
} else {
contextLayerRendering(id, data, layerInput, map)
}
contextLayerRendering(id, data, layerInput, map)
}
}, [map, layerInput]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,12 @@ function receive(data, error = null) {
*/
export function fetch(dispatch) {
fetchingData(
urls.dashboardData, {}, {}, function (response, error) {
fetchingData(
// Fetch palette color first
`/api/color/palette/list`,
{}, {}, (palettes, paletteError) => {
updateColorPaletteData(palettes)
const recError = !error && paletteError ? paletteError : error
dispatch(receive(response, recError))
}
)
urls.dashboardData, {}, {}, async function (response, error) {
await updateColorPaletteData().then(palettes => {
dispatch(receive(response, null))
}).catch(error => {
dispatch(receive(response, error))
})
}
)
return request();
Expand Down
22 changes: 19 additions & 3 deletions django_project/frontend/src/utils/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { isArray } from "chart.js/helpers";
import { dictDeepCopy } from "./main";
import { NO_DATA_RULE } from "../pages/Admin/Style/Form/StyleRules";
import { getLayerDataCleaned, SingleIndicatorTypes } from "./indicatorLayer";
import { fetchingData } from "../Requests";


export const STYLE_FORM_LIBRARY = 'Style from library.'
Expand All @@ -38,10 +39,25 @@ export let COLOR_PALETTE_DATA = null

/**
* Update color data
* @param data
*/
export function updateColorPaletteData(data) {
COLOR_PALETTE_DATA = data
export async function updateColorPaletteData() {
return new Promise((resolve, reject) => {
if (!COLOR_PALETTE_DATA) {
fetchingData(
`/api/color/palette/list`,
{}, {}, (response, error) => {
if (response) {
COLOR_PALETTE_DATA = response
resolve(response)
} else {
reject(error)
}
}
)
} else {
resolve(COLOR_PALETTE_DATA)
}
});
}

/** Return layer style config */
Expand Down
3 changes: 2 additions & 1 deletion django_project/frontend/src/utils/Variables.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const Variables = {
LIST: {
VECTOR_TILE_TYPES: [RELATED_TABLE, VECTOR_TILE, CLOUD_NATIVE_GIS],
RASTER_TYPES: [RASTER_COG, RASTER_TILE],
OVERRIDE_STYLES: [ARCGIS]
OVERRIDE_STYLES: [ARCGIS],
LAYERS_NEED_PALETTE: [RASTER_COG],
}
}
}

0 comments on commit ed66fc9

Please sign in to comment.