Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spatial index widgets #34

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Copy link
Member

@donmccurdy donmccurdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is nicely structured! A few comments/questions, still working my way though the code review. :)

@@ -30,7 +33,7 @@ type UrlParameters = {
};

export const h3QuerySource = async function (
options: H3QuerySourceOptions
options: Omit<H3QuerySourceOptions, 'spatialDataType'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primarily H3QuerySourceOptions represents the public-facing option types of the h3QuerySource function. Since users would never pass the 'spatialDataType' prop here, I think we can remove it from the 'H3QuerySourceOptions' definition.

(And similar for other sources)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, if we do this, where do we define the spatialDataType prop then?
Because the spatialDataColumn prop is defined in QuerySourceOptions and TableSourceOptions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other thing I was considering was moving this prop definition to WidgetBaseSourceProps

Copy link
Member

@donmccurdy donmccurdy Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only consequence if it isn't defined explicitly (as on main branch now) is that the following...

const data = await h3QuerySource({..., spatialDataType: 'quadbin'});

... is a runtime error instead of a compile-time error. A compile-time error would be better, I agree, but the user must be able to import and use H3QuerySourceOptions themselves and the required/optional fields should match what h3QuerySource accepts. So perhaps instead of removing the override, we can just change its (still optional) value as spatialDataType?: 'h3' rather than spatialDataType: 'h3'?

export type H3QuerySourceOptions = SourceOptions &
  QuerySourceOptions &
  AggregationOptions &
  FilterOptions & {
    spatialDataType?: 'h3';
  };

Copy link
Author

@juandjara juandjara Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's perfect, I was working on a second proposal for this, but this one is easier to understand

src/sources/h3-query-source.ts Show resolved Hide resolved
return undefined;
}

const currentZoom = viewState.zoom ?? 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor — Since viewState.zoom is required input, I'd slightly prefer not giving it a fallback here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok we will remove this variable then

filterOwner,
spatialFilter,
spatialFiltersMode,
spatialFiltersResolution,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure yet if we should do this, so no need to make the change now, but ... would it work if instead of asking the user to provide spatialFiltersResolution, we computed it internally from the WidgetBaseSource's own props, and a (new) viewState prop that the user would pass into getCategories etc.? Or is this something the user needs to directly control?

I'm a bit worried about all of the default values used inside 'getSpatialFiltersResolution', and things like tileSize, because it would be easy for the user to forget something. It would be nice if all the default values were populated before the 'source' is passed into the getSpatialFiltersResolution function, and this would make implementation in the widget web components simpler.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, user should be able to specify a concrete spatialFiltersResolution I think. I'm also a bit worried about all the conditional logic inside of that function, but since is inherited legacy code, I decided not to question it very much. We can find a way to adapt it if you would like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @zbigg @felixpalmer does this concern make sense, and do you have any immediate preferences?

If we're all not sure then maybe it's best to go ahead and try setting up 1-2 of the example widgets (https://github.com/CartoDB/carto-api-client/tree/main/examples/components/widgets) to test with spatial index sources.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I'll let you know when I have the examples ready

const DEFAULT_TILE_SIZE = 512;
const QUADBIN_ZOOM_MAX_OFFSET = 4;

export function getSpatialFiltersResolution({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does similar logic exist in C4R now, and could you share a link to it for comparison?

I'm not sure about using tileSize without also referring to tileResolution, that seems a bit strange to me, but maybe this is just how it already works?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks! I think at least for the aggregationResLevel we should make sure the user doesn't need to specify that twice (once for the source, and again for getSpatialFiltersResolution). But there's more than one way to do this, so I think it will depend on the question above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants