Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/charts/map/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WebMercatorViewport } from "@deck.gl/core";
import { MapboxOverlay, MapboxOverlayProps } from "@deck.gl/mapbox";
import bbox from "@turf/bbox";
import { extent } from "d3-array";
import { geoBounds } from "d3-geo";
import { useEffect, useMemo, useState } from "react";
import { useControl, ViewState } from "react-map-gl";
import { feature } from "topojson-client";
Expand Down Expand Up @@ -137,9 +137,12 @@ export const getBBox = (
let symbolsBbox: BBox | undefined;

if (shapes) {
const _shapesBbox = geoBounds(shapes);
if (!_shapesBbox.flat().some(isNaN)) {
shapesBbox = _shapesBbox;
const [minLng, minLat, maxLng, maxLat] = bbox(shapes);
if (![minLng, minLat, maxLng, maxLat].some(isNaN)) {
shapesBbox = [
[minLng, minLat],
[maxLng, maxLat],
] as BBox;
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/charts/map/map-state-props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { geoCentroid } from "d3-geo";
import centroid from "@turf/centroid";
import keyBy from "lodash/keyBy";
import { useMemo } from "react";

Expand Down Expand Up @@ -158,7 +158,7 @@

const points = features.map((d) => ({
...d,
coordinates: geoCentroid(d),
coordinates: centroid(d).geometry.coordinates,
}));

return {
Expand All @@ -179,7 +179,7 @@
...data,
features: {
areaLayer,
symbolLayer,

Check failure on line 182 in app/charts/map/map-state-props.ts

View workflow job for this annotation

GitHub Actions / base-checks (typecheck)

Type '{ points: GeoPoint[]; } | { points: { coordinates: Position; type: "Feature"; geometry: MultiPolygon | Polygon; id?: string | number | undefined; properties: GeoProperties; bbox?: BBox | undefined; }[]; } | undefined' is not assignable to type 'SymbolLayer | undefined'.
},
};
};
4 changes: 2 additions & 2 deletions app/charts/map/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { supported } from "@mapbox/mapbox-gl-supported";
import { Button, Theme } from "@mui/material";
import { makeStyles } from "@mui/styles";
import { geoArea } from "d3-geo";
import area from "@turf/area";
import debounce from "lodash/debounce";
import orderBy from "lodash/orderBy";
import uniq from "lodash/uniq";
Expand Down Expand Up @@ -302,7 +302,7 @@ export const MapComponent = ({
// Sort for smaller shapes to be over larger ones, to be able to use tooltip
const sortedFeatures = orderBy(
features.areaLayer?.shapes?.features,
geoArea,
area,
"desc"
) satisfies GeoFeature[];

Expand Down
15 changes: 13 additions & 2 deletions app/graphql/resolvers/rdf.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { rewindGeometry } from "@placemarkio/geojson-rewind";
import { ascending, descending } from "d3-array";
import DataLoader from "dataloader";
import groupBy from "lodash/groupBy";
import ParsingClient from "sparql-http-client/ParsingClient";
import { topology } from "topojson-server";
import { LRUCache } from "typescript-lru-cache";
import { parse as parseWKT } from "wellknown";
import { GeoJSONGeometry, parse as parseWKT } from "wellknown";

import { Filters } from "@/config-types";
import {
Expand Down Expand Up @@ -127,6 +128,16 @@ export const searchCubes: NonNullable<QueryResolvers["searchCubes"]> = async (
});
};

/**
* Normalize the geometry's winding order to follow GeoJSON standards. It is
* converted to CCW (a.k.a. "right hand rule") if it has a non-standard CW
* winding order.
*/
const rewind = (geometry: GeoJSONGeometry): GeoJSONGeometry => {
if (!geometry) return null;
return rewindGeometry(geometry) as GeoJSONGeometry;
};

export const dataCubeDimensionGeoShapes: NonNullable<
QueryResolvers["dataCubeDimensionGeoShapes"]
> = async (_, { locale, cubeFilter }, { setup }, info) => {
Expand Down Expand Up @@ -178,7 +189,7 @@ export const dataCubeDimensionGeoShapes: NonNullable<
iri: value,
label: dimensionValuesByValue.get(value),
},
geometry: parseWKT(shape.wktString),
geometry: rewind(parseWKT(shape.wktString)),
};
});

Expand Down
6 changes: 4 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@opentelemetry/sdk-node": "^0.211.0",
"@opentelemetry/sdk-trace-node": "^2.5.0",
"@opentelemetry/semantic-conventions": "^1.39.0",
"@placemarkio/geojson-rewind": "^1.0.3",
"@preconstruct/next": "^3.0.1",
"@prisma/client": "^4.10.1",
"@rdfjs/data-model": "^2.0.2",
Expand All @@ -62,6 +63,9 @@
"@testing-library/react-hooks": "^8.0.1",
"@tpluscode/rdf-ns-builders": "2.0.1",
"@tpluscode/sparql-builder": "^0.3.31",
"@turf/area": "7.3.4",
"@turf/bbox": "7.3.4",
"@turf/centroid": "7.3.4",
"@types/react-grid-layout": "^1.3.5",
"@uiw/react-color": "^2.3.2",
"@urql/devtools": "^2.0.3",
Expand All @@ -83,7 +87,6 @@
"d3-delaunay": "^6.0.4",
"d3-dsv": "^3.0.1",
"d3-format": "^3.1.0",
"d3-geo": "^3.1.1",
"d3-interpolate": "^3.0.1",
"d3-interpolate-path": "^2.3.0",
"d3-scale": "^4.0.2",
Expand Down Expand Up @@ -204,7 +207,6 @@
"@types/d3-delaunay": "^6.0.4",
"@types/d3-dsv": "^3.0.7",
"@types/d3-format": "^3.0.4",
"@types/d3-geo": "^3.1.0",
"@types/d3-interpolate": "^3.0.4",
"@types/d3-interpolate-path": "^2.0.0",
"@types/d3-scale": "^4.0.8",
Expand Down
Loading
Loading