diff --git a/src/lib/bahiaGeometriesTypes.ts b/src/lib/bahiaGeometriesTypes.ts index 6e601405..379d32ec 100644 --- a/src/lib/bahiaGeometriesTypes.ts +++ b/src/lib/bahiaGeometriesTypes.ts @@ -2,7 +2,10 @@ import type { Feature, MultiPolygon, Polygon } from 'geojson' import type { GeometryCollection, Topology } from 'topojson-specification' /** Every committed mesh is polygonal; only the properties differ. */ -type BahiaFeature = Feature +export type BahiaFeature> = Feature< + Polygon | MultiPolygon, + Properties +> type BahiaMunicipalityProperties = { codarea: string diff --git a/src/lib/bahiaGeometryModuleFactory.ts b/src/lib/bahiaGeometryModuleFactory.ts index 1a36558a..8b4f7627 100644 --- a/src/lib/bahiaGeometryModuleFactory.ts +++ b/src/lib/bahiaGeometryModuleFactory.ts @@ -1,19 +1,14 @@ import { feature } from 'topojson-client' -import type { Feature, MultiPolygon, Polygon } from 'geojson' +import type { BahiaFeature } from '@/lib/bahiaGeometriesTypes' import type { GeometryCollection, Topology } from 'topojson-specification' -type PolygonalFeature> = Feature< - Polygon | MultiPolygon, - Properties -> - type GeometryModuleBase< Properties extends Record, TObjectName extends string, > = { topology: Topology<{ [key in TObjectName]: GeometryCollection }> - features: readonly PolygonalFeature[] + features: readonly BahiaFeature[] } type IndexedGeometryModule< @@ -21,7 +16,7 @@ type IndexedGeometryModule< TObjectName extends string, KeyProperty extends keyof Properties & string, > = GeometryModuleBase & { - getFeatureByKey: (key: Properties[KeyProperty]) => PolygonalFeature | undefined + getFeatureByKey: (key: Properties[KeyProperty]) => BahiaFeature | undefined } type BuildGeometryModuleOptions< @@ -63,7 +58,7 @@ export function buildGeometryModuleFromTopology< | GeometryModuleBase | IndexedGeometryModule { const features = feature(topology, topology.objects[objectName]) - .features as PolygonalFeature[] + .features as BahiaFeature[] const base: GeometryModuleBase = { topology, diff --git a/src/lib/bahiaMunicipalityGeometries.ts b/src/lib/bahiaMunicipalityGeometries.ts index 8c956f68..ef4819da 100644 --- a/src/lib/bahiaMunicipalityGeometries.ts +++ b/src/lib/bahiaMunicipalityGeometries.ts @@ -6,7 +6,11 @@ import type { import { buildGeometryModuleFromTopology } from '@/lib/bahiaGeometryModuleFactory' import municipalityTopologyJson from '@/lib/geometries/bahia-municipalities.topo.json' -const { topology, features, getFeatureByKey } = buildGeometryModuleFromTopology({ +const { topology, features, getFeatureByKey } = buildGeometryModuleFromTopology< + BahiaMunicipalityFeature['properties'], + 'municipalities', + 'codarea' +>({ topology: municipalityTopologyJson as unknown as MunicipalityTopology, objectName: 'municipalities', keyProperty: 'codarea', @@ -14,6 +18,6 @@ const { topology, features, getFeatureByKey } = buildGeometryModuleFromTopology( export const municipalityGeometryModule: MunicipalityGeometryModule = { topology, - features: features as readonly BahiaMunicipalityFeature[], + features, getMunicipalityFeature: getFeatureByKey, } diff --git a/src/lib/bahiaTerritoryGeometries.ts b/src/lib/bahiaTerritoryGeometries.ts index e5c8c51b..68dc3ee5 100644 --- a/src/lib/bahiaTerritoryGeometries.ts +++ b/src/lib/bahiaTerritoryGeometries.ts @@ -6,12 +6,15 @@ import type { import { buildGeometryModuleFromTopology } from '@/lib/bahiaGeometryModuleFactory' import territoryTopologyJson from '@/lib/geometries/bahia-identity-territories.topo.json' -const { topology, features } = buildGeometryModuleFromTopology({ +const { topology, features } = buildGeometryModuleFromTopology< + BahiaTerritoryFeature['properties'], + 'territories' +>({ topology: territoryTopologyJson as unknown as TerritoryTopology, objectName: 'territories', }) export const territoryGeometryModule: TerritoryGeometryModule = { topology, - features: features as readonly BahiaTerritoryFeature[], + features, }