Skip to content

Commit

Permalink
BugFix: using altinnrowid instead of index and label as key to make s…
Browse files Browse the repository at this point in the history
…ure the geometries update when changed (#2729)
  • Loading branch information
MartinRoberg authored Nov 20, 2024
1 parent a0413c3 commit 37eaaa9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/layout/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ export function Map({
subdomains={layer.subdomains ? layer.subdomains : []}
/>
))}
{geometries?.map(({ data, label }, i) => (
{geometries?.map(({ altinnRowId, data, label }) => (
<GeoJSON
key={`${i}-${label}`}
key={altinnRowId}
data={data}
interactive={false}
>
Expand Down
2 changes: 2 additions & 0 deletions src/layout/Map/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { GeoJSON } from 'geojson';

export type RawGeometry = {
altinnRowId: string;
data: string;
label?: string;
};

export type Geometry = {
altinnRowId: string;
data: GeoJSON;
label?: string;
};
4 changes: 3 additions & 1 deletion src/layout/Map/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,18 @@ export function parseGeometries(

const out: Geometry[] = [];

for (const { data: rawData, label } of geometries) {
for (const { altinnRowId, data: rawData, label } of geometries) {
if (geometryType === 'WKT') {
const data = WKT.parse(rawData);
out.push({
altinnRowId,
data,
label,
});
} else {
const data = JSON.parse(rawData) as GeoJSON;
out.push({
altinnRowId,
data,
label,
});
Expand Down

0 comments on commit 37eaaa9

Please sign in to comment.