-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Hello !
I'm currently trying to implement a new Model extending the GeoJsonCatalogItem Model.
My use case is that i have
I wanted to make it so when the layer is first added it's loading the geometry, and when the timeframe is playing, the values of the polygons' attributes are updated. (First request is GeoJSON, subsequent ones are CSV)
So far i'm pretty close, the request are handled correctly, but my layer is not updating.
I'm using this :
export default class DynamicGeoJsonCatalogItem extends GeoJsonCatalogItem {
private clockDisposer?: () => void;
private lastFetchedDate?: string; // ISO date like "2025-05-22"
constructor(id: string, terria: Terria) {
super(id, terria);
// Attach clock tick listener after data is loaded
if (!this.clockDisposer) {
this.clockDisposer = this.terria.timelineClock.onTick.addEventListener(clock => {
const currentIso = JulianDate.toDate(clock.currentTime).toISOString();
const currentDate = currentIso.slice(0, 10); // 'YYYY-MM-DD'
if (currentDate !== this.lastFetchedDate) {
this.lastFetchedDate = currentDate;
this.updateFromTime(currentIso);
}
});
}
}
async updateFromTime(currentTime: string) {
try {
const timeKey = currentTime.slice(0, 10); // e.g. '2025-05-22'
const csvUrl = this.baseCsvUrl + `${timeKey}`;
const csvData = await loadCsv(csvUrl);
runInAction(() => {
this.applyCsvDataToGeoJson(csvData);
});
} catch (e) {
console.error("Error loading or parsing CSV:", e);
}
}
applyCsvDataToGeoJson(csvRows: any[]) {
if (!this.geoJsonData || !this.geoJsonData.features) return;
for (const feature of this.geoJsonData.features) {
const lakeId = feature.properties.id;
const row = csvRows.find((r: any) => r.id === lakeId);
if (row) {
feature.properties.level = row.level;
}
}
// Force refresh of features
this.setTrait(CommonStrata.user, "geoJsonData", this.geoJsonData);
}Not sure if
this.setTrait(CommonStrata.user, "geoJsonData", this.geoJsonData);
is the right method to use, or if my data formatting is wrong (i think it's the former)
just in case, here is what my data looks like
{"type" : "FeatureCollection", "features" : [{"type": "Feature", "geometry": {"type":"Polygon","coordinates": []}, "properties": {"id": 4460, "datetime": "2023-01-01T00:00:00+00:00", "etc": [] }}]}and
[{"id":1,"datetime":"2020-02-26T00:00:00+00:00","etc": []},
{"id":3,"datetime":"2020-02-26T00:00:00+00:00","etc": []},