arnaudleclerc / AzureMapsControl.Components

Razor Components for azure-maps-control
MIT License
34 stars 12 forks source link

[Question] A sample how to build clustering expressions #70

Open mitikov opened 2 years ago

mitikov commented 2 years ago

Hey folks, could you please provide an example on how to build complex AzureMapsControl.Components.Atlas.Expression during clustering.

I'm doing a POC for migrating from pure JS to Blazor, and I've stumbled upon the task of converting datasource expressions.

The things I do in JS:

  1. Different valueGetter based on isCluster: ['case', isCluster, ['get', 'cluster_hits'], ['get', 'hits']];
  2. Is cluster: isCluster = ['has', 'point_count'];
  3. Specify aggregation, f.e. sum: ['+', valueGetter]
  4. Convert to 'boss' view, leaving only 2 digits for fraction

The JS constructs look quite readable; at the same time I could not build anything close using Blazor wrapper. The docs show straightforward value getter as of now.

Thanks, Nik

mitikov commented 2 years ago

Oke, I think I got an understanding how expressions are expected to be built:

        private readonly Expression isCluster = new(new[] { new ExpressionOrString("has"), new ExpressionOrString("point_count") });

        private Expression leafValue(DisplayedMode mode) => new(new[] { new ExpressionOrString("get"), new ExpressionOrString(mode.Name) });

        private readonly Expression clusterValue = new(new[] { new ExpressionOrString("get"), new ExpressionOrString("total") });

        private Expression ConstuctValueFactory(DisplayedMode mode) => new(new[] { new ExpressionOrString("case"), isCluster, clusterValue, leafValue(mode) });

I might add a few helpers to reduce boilerplate, such as well-known case statement, or cluster check.

Thanks,

mitikov commented 2 years ago

Here is the PR #71 that reduces volume of boilerplate code for consumers.

Thanks.

arnaudleclerc commented 2 years ago

Thanks for the PR! A new 1.12.0-alpha0019 version has just been published. Would you mind testing this version and telling me if this behaves like you expect it to ?

If so, I will generate a stable version afterwards.

mitikov commented 2 years ago

Hey @arnaudleclerc , thanks for approving the PR. The code I'm contributing flows from extension methods I've already used in my project; I'm pretty sure it works.

I'd like to supply a few more PRs, like #72 prior calling it a day. How does that sound?

Regards / Nik

arnaudleclerc commented 2 years ago

Sounds good, feel free to open the PRs. Thanks for contributing 👍

DavidThielen commented 7 months ago

Is how to create a cluster documented anywhere? This shows how to set it up using JavaScript. But everything I've tried to apply this to the DataSource and SymbolLayer doesn't work. It's still just all individual pins (symbols).

thanks - dave