1

In CARTO VL linear function expects a date or numeric field as its first argument. But when the data source is a GeoJSON, date fields are stored as categorical/strings and it returns an error like this:

CartoValidationError: [Property with an incorrect type]: linear(): invalid first parameter 'input' expected type was one of number,date, actual type was 'category'

You can test it in this visualizer replacing the current CARTO VL viz style with something like:

 filter: animation(
             linear(
                    $date,
                    time('2019-01-01T00:00:00Z'),
                    time('2019-01-31T00:00:00Z')
                ),
                20,
                fade(0.5, 0.5))

Is there any workaround to convert this (string/categorical) date field to a proper date/timestamp field in CARTO VL?

2

The GeoJSON source method has an option to indicate the 'date' columns.

Can you try with something like this?

const dateColumns = ['date'];
const options = { dateColumns };
const newSource = new carto.source.GeoJSON(JSON.parse(this.source), options);

:wave

  • Thanks Victor! :magic: – ramiroaznar Aug 7 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.