-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Severity
P3 — Architecture
Description
`getFeatureId` in `src/utils/index.ts:36-45` contains Vido-specific logic to parse `properties.metadata` as a JSON string:
```ts
// Vido support: shouldn't be part of this plugin
let metadata = feature.properties.metadata
if (typeof metadata === 'string') {
try {
metadata = JSON.parse(metadata)
}
catch {
metadata = undefined
}
}
```
The comment already acknowledges this doesn't belong here. This couples a generic clustering library to a specific data provider's format.
Suggested Approach
Add a `getFeatureId` option to `TeritorioClusterOptions`:
```ts
getFeatureId?: (feature: GeoJSONFeature) => string
```
Default implementation:
```ts
(feature) => {
if (feature.properties.cluster) {
if (!feature.id) throw new Error('Cluster feature is missing "id".')
return feature.id.toString()
}
return (feature.properties?.id ?? feature.id).toString()
}
```
Vido consumers would provide their own implementation that handles the metadata JSON parsing.
Impact
This is a breaking change for Vido consumers who rely on the implicit metadata parsing. Coordinate with Vido team.
Files
- `src/utils/index.ts:29-48`
- `src/types.ts` (add option type)
- `src/teritorio-cluster.ts` (wire up the option)