Skip to content

Commit 0d8839d

Browse files
arnaudleclercArnaud Leclerc
andauthored
Add support of GetClusterLeaves and GetClusterExpansionZoom on Datasource (#95)
* Add support of GetClusterLeaves * Add support of GetClusterExpansionZoom * Unit tests should return task * Fix unit tests --------- Co-authored-by: Arnaud Leclerc <arnaud.leclerc@ascent.io>
1 parent 31e80a3 commit 0d8839d

38 files changed

+600
-385
lines changed

samples/AzureMapsControl.Sample/Components/Pages/Demos/ClusterAggregates.razor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060

6161
if(cluster is not null && cluster.Properties.ContainsKey("cluster"))
6262
{
63+
var clusterLeaves = await _datasource.GetClusterLeavesAsync(int.Parse(cluster.Id), 10, 0);
64+
var clusterZoomExpansionLevel = await _datasource.GetClusterExpansionZoomAsync(int.Parse(cluster.Id));
65+
6366
var html = string.Join(string.Empty,
6467
new[] {
6568
"<div style=\"padding:10px;\">",

src/AzureMapsControl.Components/Atlas/Feature.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public TGeometry Geometry
4141
}
4242
set {
4343
_geometry = value;
44-
_geometry.Id = Id;
44+
if (_geometry != null)
45+
{
46+
_geometry.Id = Id;
47+
}
4548
}
4649
}
4750

src/AzureMapsControl.Components/Atlas/Shape.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public TGeometry Geometry
3434
}
3535
set {
3636
_geometry = value;
37-
_geometry.Id = Id;
37+
if (_geometry != null)
38+
{
39+
_geometry.Id = Id;
40+
}
3841
}
3942
}
4043

src/AzureMapsControl.Components/Constants/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ internal static class Source
111111
internal static class Datasource
112112
{
113113
internal const string GetShapes = "getShapes";
114+
internal const string GetClusterLeaves = "getClusterLeaves";
115+
internal const string GetClusterExpansionZoom = "getClusterExpansionZoom";
114116
}
115117

116118
internal static class GriddedDatasource

src/AzureMapsControl.Components/Data/DataSource.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,44 @@ public async ValueTask<IEnumerable<Shape<Geometry>>> GetShapesAsync()
9292
return await JSRuntime.InvokeAsync<IEnumerable<Shape<Geometry>>>(Constants.JsConstants.Methods.Datasource.GetShapes.ToDatasourceNamespace(), Id);
9393
}
9494

95+
/// <summary>
96+
/// Retrieves shapes that are within the cluster.
97+
/// </summary>
98+
/// <param name="clusterId">The ID of the cluster</param>
99+
/// <param name="limit">The maximum number of features to return</param>
100+
/// <param name="offset">The number of shapes to skip. Allows you to page through the shapes in the cluster</param>
101+
/// <returns>Shapes that are within the cluster</returns>
102+
public async ValueTask<IEnumerable<Feature<Geometry>>> GetClusterLeavesAsync(int clusterId, int limit, int offset)
103+
{
104+
Logger?.LogAzureMapsControlInfo(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, "DataSource - GetClusterLeavesAsync");
105+
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"Id: {Id}");
106+
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"ClusterId: {clusterId}");
107+
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"Limit: {limit}");
108+
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"Offset: {offset}");
109+
110+
EnsureJsRuntimeExists();
111+
EnsureNotDisposed();
112+
113+
return await JSRuntime.InvokeAsync<IEnumerable<Feature<Geometry>>>(Constants.JsConstants.Methods.Datasource.GetClusterLeaves.ToDatasourceNamespace(), Id, clusterId, limit, offset);
114+
}
115+
116+
/// <summary>
117+
/// Calculates a zoom level at which the cluster starts expanding or break apart.
118+
/// </summary>
119+
/// <param name="clusterId">ID of the cluster</param>
120+
/// <returns>Zoom level at which the cluster starts expanding or break apart</returns>
121+
public async ValueTask<int> GetClusterExpansionZoomAsync(int clusterId)
122+
{
123+
Logger?.LogAzureMapsControlInfo(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, "DataSource - GetClusterExpansionZoomAsync");
124+
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"Id: {Id}");
125+
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"ClusterId: {clusterId}");
126+
127+
EnsureJsRuntimeExists();
128+
EnsureNotDisposed();
129+
130+
return await JSRuntime.InvokeAsync<int>(Constants.JsConstants.Methods.Datasource.GetClusterExpansionZoom.ToDatasourceNamespace(), Id, clusterId);
131+
}
132+
95133
internal void DispatchEvent(DataSourceEventArgs eventArgs)
96134
{
97135
switch (eventArgs.Type)

src/AzureMapsControl.Components/Logger/Extensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ internal enum AzureMapLogEvent
6969
Source_GetOptionsAsync = 7005,
7070
Source_SetOptionsAsync = 7006,
7171
DataSource_GetShapesAsync = 7100,
72+
DataSource_GetClusterLeavesAsync = 7101,
7273
GriddedDataSource_GetCellChildren = 7200,
7374
GriddedDataSource_GetGridCells = 7201,
7475
GriddedDataSource_GetPoints = 7202,
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as azmaps from 'azure-maps-control';
22
import { Core } from '../core/core';
3-
import { Shape } from '../geometries/geometry';
3+
import { Shape, Feature } from '../geometries/geometry';
44

55
export class Datasource {
66

@@ -9,4 +9,31 @@ export class Datasource {
99
return shapes?.map(shape => Core.getSerializableShape(shape));
1010
}
1111

12+
public static async getClusterLeaves(datasourceId: string, clusterId: number, limit: number, offset: number): Promise<(Shape | Feature)[]> {
13+
return new Promise(resolve => {
14+
(Core.getMap().sources.getById(datasourceId) as azmaps.source.DataSource).getClusterLeaves(clusterId, limit, offset).then(clusterLeaves => {
15+
16+
const resultLeaves = clusterLeaves.map(leaf => {
17+
if (leaf instanceof azmaps.Shape) {
18+
return Core.getSerializableShape(leaf);
19+
}
20+
21+
if (leaf instanceof azmaps.data.Feature) {
22+
return Core.getSerializableFeature(leaf);
23+
}
24+
});
25+
26+
resolve(resultLeaves);
27+
});
28+
});
29+
}
30+
31+
public static async getClusterExpansionZoom(datasourceId: string, clusterId: number): Promise<number> {
32+
return new Promise(resolve => {
33+
(Core.getMap().sources.getById(datasourceId) as azmaps.source.DataSource).getClusterExpansionZoom(clusterId).then(zoom => {
34+
resolve(zoom);
35+
});
36+
});
37+
}
38+
1239
}

tests/AzureMapsControl.Components.Tests/Animations/Animation.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.Threading.Tasks;
56

67
using AzureMapsControl.Components.Animations;
78
using AzureMapsControl.Components.Runtime;
@@ -115,7 +116,7 @@ public void Should_Create(string animationType)
115116

116117
[Theory]
117118
[MemberData(nameof(AllAnimationsTypes))]
118-
public async void Should_DisposeAsync(string animationType)
119+
public async Task Should_DisposeAsync(string animationType)
119120
{
120121
var id = "id";
121122
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -128,7 +129,7 @@ public async void Should_DisposeAsync(string animationType)
128129

129130
[Theory]
130131
[MemberData(nameof(AllAnimationsTypes))]
131-
public async void Should_ThrowAnimationDisposedException_DisposeAsync(string animationType)
132+
public async Task Should_ThrowAnimationDisposedException_DisposeAsync(string animationType)
132133
{
133134
var id = "id";
134135
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -141,7 +142,7 @@ public async void Should_ThrowAnimationDisposedException_DisposeAsync(string ani
141142

142143
[Theory]
143144
[MemberData(nameof(AllPauseAnimationsTypes))]
144-
public async void Should_PauseAsync(string animationType)
145+
public async Task Should_PauseAsync(string animationType)
145146
{
146147
var id = "id";
147148
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -153,7 +154,7 @@ public async void Should_PauseAsync(string animationType)
153154

154155
[Theory]
155156
[MemberData(nameof(AllPauseAnimationsTypes))]
156-
public async void Should_ThrowAnimationDisposedException_PauseAsync(string animationType)
157+
public async Task Should_ThrowAnimationDisposedException_PauseAsync(string animationType)
157158
{
158159
var id = "id";
159160
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -166,7 +167,7 @@ public async void Should_ThrowAnimationDisposedException_PauseAsync(string anima
166167

167168
[Theory]
168169
[MemberData(nameof(AllPlayAnimationsTypes))]
169-
public async void Should_PlayAsync(string animationType)
170+
public async Task Should_PlayAsync(string animationType)
170171
{
171172
var id = "id";
172173
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -178,7 +179,7 @@ public async void Should_PlayAsync(string animationType)
178179

179180
[Theory]
180181
[MemberData(nameof(AllPlayAnimationsTypes))]
181-
public async void Should_ThrowAnimationDisposedException_PlayAsync(string animationType)
182+
public async Task Should_ThrowAnimationDisposedException_PlayAsync(string animationType)
182183
{
183184
var id = "id";
184185
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -191,7 +192,7 @@ public async void Should_ThrowAnimationDisposedException_PlayAsync(string animat
191192

192193
[Theory]
193194
[MemberData(nameof(AllResetAnimationsTypes))]
194-
public async void Should_ResetAsync(string animationType)
195+
public async Task Should_ResetAsync(string animationType)
195196
{
196197
var id = "id";
197198
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -203,7 +204,7 @@ public async void Should_ResetAsync(string animationType)
203204

204205
[Theory]
205206
[MemberData(nameof(AllResetAnimationsTypes))]
206-
public async void Should_ThrowAnimationDisposedException_ResetAsync(string animationType)
207+
public async Task Should_ThrowAnimationDisposedException_ResetAsync(string animationType)
207208
{
208209
var id = "id";
209210
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -216,7 +217,7 @@ public async void Should_ThrowAnimationDisposedException_ResetAsync(string anima
216217

217218
[Theory]
218219
[MemberData(nameof(AllSeekAnimationsTypes))]
219-
public async void Should_SeekAsync(string animationType)
220+
public async Task Should_SeekAsync(string animationType)
220221
{
221222
var id = "id";
222223
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -229,7 +230,7 @@ public async void Should_SeekAsync(string animationType)
229230

230231
[Theory]
231232
[MemberData(nameof(AllSeekAnimationsTypes))]
232-
public async void Should_ThrowAnimationDisposedException_SeekAsync(string animationType)
233+
public async Task Should_ThrowAnimationDisposedException_SeekAsync(string animationType)
233234
{
234235
var id = "id";
235236
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -243,7 +244,7 @@ public async void Should_ThrowAnimationDisposedException_SeekAsync(string animat
243244

244245
[Theory]
245246
[MemberData(nameof(AllStopAnimationsTypes))]
246-
public async void Should_StopAsync(string animationType)
247+
public async Task Should_StopAsync(string animationType)
247248
{
248249
var id = "id";
249250
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
@@ -255,7 +256,7 @@ public async void Should_StopAsync(string animationType)
255256

256257
[Theory]
257258
[MemberData(nameof(AllStopAnimationsTypes))]
258-
public async void Should_ThrowAnimationDisposedException_StopAsync(string animationType)
259+
public async Task Should_ThrowAnimationDisposedException_StopAsync(string animationType)
259260
{
260261
var id = "id";
261262
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);

0 commit comments

Comments
 (0)