diff --git a/app/charts/map/chart-map.tsx b/app/charts/map/chart-map.tsx index 9416ee99f..d2e21115c 100644 --- a/app/charts/map/chart-map.tsx +++ b/app/charts/map/chart-map.tsx @@ -21,9 +21,9 @@ import { import { DimensionMetaDataFragment, useDataCubeObservationsQuery, + useGeoCoordinatesByDimensionIriQuery, } from "../../graphql/query-hooks"; import { useLocale } from "../../locales/use-locale"; -import { GeoCoordinates } from "../../rdf/query-geo-coordinates"; import { QueryFilters } from "../shared/chart-helpers"; import { ChartContainer } from "../shared/containers"; import { MapComponent } from "./map"; @@ -69,6 +69,21 @@ export const ChartMapVisualization = ({ | Observation[] | undefined; + const [{ data: fetchedGeoCoordinates }] = + useGeoCoordinatesByDimensionIriQuery({ + variables: { + dataCubeIri: dataSetIri, + locale, + dimensionIri: symbolDimensionIri, + }, + }); + + const geoCoordinates = + fetchedGeoCoordinates?.dataCubeByIri?.dimensionByIri?.__typename === + "GeoCoordinatesDimension" + ? fetchedGeoCoordinates.dataCubeByIri.dimensionByIri.geoCoordinates + : null; + const areaLayer: AreaLayer | undefined = useMemo(() => { const dimension = dimensions?.find((d) => d.iri === areaDimensionIri); @@ -99,8 +114,8 @@ export const ChartMapVisualization = ({ const symbolLayer: SymbolLayer | undefined = useMemo(() => { const dimension = dimensions?.find((d) => d.iri === symbolDimensionIri); - if (isGeoCoordinatesDimension(dimension)) { - const points = (dimension.geoCoordinates as GeoCoordinates[]).map( + if (isGeoCoordinatesDimension(dimension) && geoCoordinates) { + const points = geoCoordinates.map( (d) => ({ coordinates: [d.longitude, d.latitude], @@ -125,7 +140,7 @@ export const ChartMapVisualization = ({ return { points }; } } - }, [areaLayer, dimensions, observations, symbolDimensionIri]); + }, [areaLayer, dimensions, observations, symbolDimensionIri, geoCoordinates]); useEffect(() => { const loadLakes = async () => { diff --git a/app/graphql/queries/data-cubes.graphql b/app/graphql/queries/data-cubes.graphql index 63e305cb2..73346f569 100644 --- a/app/graphql/queries/data-cubes.graphql +++ b/app/graphql/queries/data-cubes.graphql @@ -38,9 +38,6 @@ fragment dimensionMetaData on Dimension { isKeyDimension values(filters: $filters) unit - ... on GeoCoordinatesDimension { - geoCoordinates - } ... on GeoShapesDimension { geoShapes } @@ -141,6 +138,26 @@ query DimensionValues( } } +query GeoCoordinatesByDimensionIri( + $dataCubeIri: String! + $dimensionIri: String! + $latest: Boolean + $locale: String! +) { + dataCubeByIri(iri: $dataCubeIri, locale: $locale, latest: $latest) { + dimensionByIri(iri: $dimensionIri) { + ... on GeoCoordinatesDimension { + geoCoordinates { + iri + label + latitude + longitude + } + } + } + } +} + query TemporalDimensionValues( $dataCubeIri: String! $dimensionIri: String! diff --git a/app/graphql/query-hooks.ts b/app/graphql/query-hooks.ts index 8f8ee682a..2b425d9c8 100644 --- a/app/graphql/query-hooks.ts +++ b/app/graphql/query-hooks.ts @@ -14,7 +14,6 @@ export type Scalars = { Float: number; DimensionValue: any; Filters: any; - GeoCoordinates: any; GeoShapes: any; Observation: any; RawObservation: any; @@ -111,6 +110,13 @@ export type DimensionValuesArgs = { +export type GeoCoordinates = { + __typename: 'GeoCoordinates'; + iri: Scalars['String']; + label: Scalars['String']; + latitude: Scalars['Float']; + longitude: Scalars['Float']; +}; export type GeoCoordinatesDimension = Dimension & { __typename: 'GeoCoordinatesDimension'; @@ -120,7 +126,7 @@ export type GeoCoordinatesDimension = Dimension & { scaleType?: Maybe; isKeyDimension: Scalars['Boolean']; values: Array; - geoCoordinates: Scalars['GeoCoordinates']; + geoCoordinates?: Maybe>; }; @@ -292,7 +298,7 @@ export type DataCubesQueryVariables = Exact<{ export type DataCubesQuery = { __typename: 'Query', dataCubes: Array<{ __typename: 'DataCubeResult', highlightedTitle?: Maybe, highlightedDescription?: Maybe, dataCube: { __typename: 'DataCube', iri: string, title: string, description?: Maybe, publicationStatus: DataCubePublicationStatus, datePublished?: Maybe, creator?: Maybe<{ __typename: 'DataCubeOrganization', iri: string, label?: Maybe }>, themes: Array<{ __typename: 'DataCubeTheme', iri: string, label?: Maybe }> } }> }; -type DimensionMetaData_GeoCoordinatesDimension_Fragment = { __typename: 'GeoCoordinatesDimension', geoCoordinates: any, iri: string, label: string, isKeyDimension: boolean, values: Array, unit?: Maybe }; +type DimensionMetaData_GeoCoordinatesDimension_Fragment = { __typename: 'GeoCoordinatesDimension', iri: string, label: string, isKeyDimension: boolean, values: Array, unit?: Maybe }; type DimensionMetaData_GeoShapesDimension_Fragment = { __typename: 'GeoShapesDimension', geoShapes: any, iri: string, label: string, isKeyDimension: boolean, values: Array, unit?: Maybe }; @@ -416,6 +422,16 @@ export type DimensionValuesQuery = { __typename: 'Query', dataCubeByIri?: Maybe< & DimensionMetaData_TemporalDimension_Fragment )> }> }; +export type GeoCoordinatesByDimensionIriQueryVariables = Exact<{ + dataCubeIri: Scalars['String']; + dimensionIri: Scalars['String']; + latest?: Maybe; + locale: Scalars['String']; +}>; + + +export type GeoCoordinatesByDimensionIriQuery = { __typename: 'Query', dataCubeByIri?: Maybe<{ __typename: 'DataCube', dimensionByIri?: Maybe<{ __typename: 'GeoCoordinatesDimension', geoCoordinates?: Maybe> } | { __typename: 'GeoShapesDimension' } | { __typename: 'Measure' } | { __typename: 'NominalDimension' } | { __typename: 'OrdinalDimension' } | { __typename: 'TemporalDimension' }> }> }; + export type TemporalDimensionValuesQueryVariables = Exact<{ dataCubeIri: Scalars['String']; dimensionIri: Scalars['String']; @@ -500,9 +516,6 @@ export const DimensionMetaDataFragmentDoc = gql` isKeyDimension values(filters: $filters) unit - ... on GeoCoordinatesDimension { - geoCoordinates - } ... on GeoShapesDimension { geoShapes } @@ -640,6 +653,26 @@ export const DimensionValuesDocument = gql` export function useDimensionValuesQuery(options: Omit, 'query'> = {}) { return Urql.useQuery({ query: DimensionValuesDocument, ...options }); }; +export const GeoCoordinatesByDimensionIriDocument = gql` + query GeoCoordinatesByDimensionIri($dataCubeIri: String!, $dimensionIri: String!, $latest: Boolean, $locale: String!) { + dataCubeByIri(iri: $dataCubeIri, locale: $locale, latest: $latest) { + dimensionByIri(iri: $dimensionIri) { + ... on GeoCoordinatesDimension { + geoCoordinates { + iri + label + latitude + longitude + } + } + } + } +} + `; + +export function useGeoCoordinatesByDimensionIriQuery(options: Omit, 'query'> = {}) { + return Urql.useQuery({ query: GeoCoordinatesByDimensionIriDocument, ...options }); +}; export const TemporalDimensionValuesDocument = gql` query TemporalDimensionValues($dataCubeIri: String!, $dimensionIri: String!, $locale: String!, $latest: Boolean, $filters: Filters) { dataCubeByIri(iri: $dataCubeIri, locale: $locale, latest: $latest) { diff --git a/app/graphql/resolver-types.ts b/app/graphql/resolver-types.ts index 7dc259493..6458ef5de 100644 --- a/app/graphql/resolver-types.ts +++ b/app/graphql/resolver-types.ts @@ -19,7 +19,6 @@ export type Scalars = { Float: number; DimensionValue: DimensionValue; Filters: Filters; - GeoCoordinates: any; GeoShapes: any; Observation: Observation; RawObservation: RawObservation; @@ -116,6 +115,13 @@ export type DimensionValuesArgs = { +export type GeoCoordinates = { + __typename?: 'GeoCoordinates'; + iri: Scalars['String']; + label: Scalars['String']; + latitude: Scalars['Float']; + longitude: Scalars['Float']; +}; export type GeoCoordinatesDimension = Dimension & { __typename?: 'GeoCoordinatesDimension'; @@ -125,7 +131,7 @@ export type GeoCoordinatesDimension = Dimension & { scaleType?: Maybe; isKeyDimension: Scalars['Boolean']; values: Array; - geoCoordinates: Scalars['GeoCoordinates']; + geoCoordinates?: Maybe>; }; @@ -367,7 +373,7 @@ export type ResolversTypes = ResolversObject<{ Boolean: ResolverTypeWrapper; DimensionValue: ResolverTypeWrapper; Filters: ResolverTypeWrapper; - GeoCoordinates: ResolverTypeWrapper; + GeoCoordinates: ResolverTypeWrapper; GeoCoordinatesDimension: ResolverTypeWrapper; GeoShapes: ResolverTypeWrapper; GeoShapesDimension: ResolverTypeWrapper; @@ -397,7 +403,7 @@ export type ResolversParentTypes = ResolversObject<{ Boolean: Scalars['Boolean']; DimensionValue: Scalars['DimensionValue']; Filters: Scalars['Filters']; - GeoCoordinates: Scalars['GeoCoordinates']; + GeoCoordinates: GeoCoordinates; GeoCoordinatesDimension: ResolvedDimension; GeoShapes: Scalars['GeoShapes']; GeoShapesDimension: ResolvedDimension; @@ -476,9 +482,13 @@ export interface FiltersScalarConfig extends GraphQLScalarTypeConfig { - name: 'GeoCoordinates'; -} +export type GeoCoordinatesResolvers = ResolversObject<{ + iri?: Resolver; + label?: Resolver; + latitude?: Resolver; + longitude?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}>; export type GeoCoordinatesDimensionResolvers = ResolversObject<{ iri?: Resolver; @@ -487,7 +497,7 @@ export type GeoCoordinatesDimensionResolvers, ParentType, ContextType>; isKeyDimension?: Resolver; values?: Resolver, ParentType, ContextType, RequireFields>; - geoCoordinates?: Resolver; + geoCoordinates?: Resolver>, ParentType, ContextType>; __isTypeOf?: IsTypeOfResolverFn; }>; @@ -582,7 +592,7 @@ export type Resolvers = ResolversObject<{ Dimension?: DimensionResolvers; DimensionValue?: GraphQLScalarType; Filters?: GraphQLScalarType; - GeoCoordinates?: GraphQLScalarType; + GeoCoordinates?: GeoCoordinatesResolvers; GeoCoordinatesDimension?: GeoCoordinatesDimensionResolvers; GeoShapes?: GraphQLScalarType; GeoShapesDimension?: GeoShapesDimensionResolvers; diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index ee0fcb2b2..40ba94af3 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -2,7 +2,6 @@ scalar Observation scalar DimensionValue scalar RawObservation scalar Filters -scalar GeoCoordinates scalar GeoShapes type ObservationsQuery { @@ -54,6 +53,13 @@ interface Dimension { values(filters: Filters): [DimensionValue!]! } +type GeoCoordinates { + iri: String! + label: String! + latitude: Float! + longitude: Float! +} + type GeoCoordinatesDimension implements Dimension { iri: String! label: String! @@ -61,7 +67,7 @@ type GeoCoordinatesDimension implements Dimension { scaleType: String isKeyDimension: Boolean! values(filters: Filters): [DimensionValue!]! - geoCoordinates: GeoCoordinates! + geoCoordinates: [GeoCoordinates!] } type GeoShapesDimension implements Dimension {