Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@

if(cluster is not null && cluster.Properties.ContainsKey("cluster"))
{
var clusterLeaves = await _datasource.GetClusterLeavesAsync(int.Parse(cluster.Id), 10, 0);
var clusterZoomExpansionLevel = await _datasource.GetClusterExpansionZoomAsync(int.Parse(cluster.Id));

var html = string.Join(string.Empty,
new[] {
"<div style=\"padding:10px;\">",
Expand Down
5 changes: 4 additions & 1 deletion src/AzureMapsControl.Components/Atlas/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public TGeometry Geometry
}
set {
_geometry = value;
_geometry.Id = Id;
if (_geometry != null)
{
_geometry.Id = Id;
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/AzureMapsControl.Components/Atlas/Shape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public TGeometry Geometry
}
set {
_geometry = value;
_geometry.Id = Id;
if (_geometry != null)
{
_geometry.Id = Id;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/AzureMapsControl.Components/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ internal static class Source
internal static class Datasource
{
internal const string GetShapes = "getShapes";
internal const string GetClusterLeaves = "getClusterLeaves";
internal const string GetClusterExpansionZoom = "getClusterExpansionZoom";
}

internal static class GriddedDatasource
Expand Down
38 changes: 38 additions & 0 deletions src/AzureMapsControl.Components/Data/DataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,44 @@ public async ValueTask<IEnumerable<Shape<Geometry>>> GetShapesAsync()
return await JSRuntime.InvokeAsync<IEnumerable<Shape<Geometry>>>(Constants.JsConstants.Methods.Datasource.GetShapes.ToDatasourceNamespace(), Id);
}

/// <summary>
/// Retrieves shapes that are within the cluster.
/// </summary>
/// <param name="clusterId">The ID of the cluster</param>
/// <param name="limit">The maximum number of features to return</param>
/// <param name="offset">The number of shapes to skip. Allows you to page through the shapes in the cluster</param>
/// <returns>Shapes that are within the cluster</returns>
public async ValueTask<IEnumerable<Feature<Geometry>>> GetClusterLeavesAsync(int clusterId, int limit, int offset)
{
Logger?.LogAzureMapsControlInfo(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, "DataSource - GetClusterLeavesAsync");
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"Id: {Id}");
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"ClusterId: {clusterId}");
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"Limit: {limit}");
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"Offset: {offset}");

EnsureJsRuntimeExists();
EnsureNotDisposed();

return await JSRuntime.InvokeAsync<IEnumerable<Feature<Geometry>>>(Constants.JsConstants.Methods.Datasource.GetClusterLeaves.ToDatasourceNamespace(), Id, clusterId, limit, offset);
}

/// <summary>
/// Calculates a zoom level at which the cluster starts expanding or break apart.
/// </summary>
/// <param name="clusterId">ID of the cluster</param>
/// <returns>Zoom level at which the cluster starts expanding or break apart</returns>
public async ValueTask<int> GetClusterExpansionZoomAsync(int clusterId)
{
Logger?.LogAzureMapsControlInfo(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, "DataSource - GetClusterExpansionZoomAsync");
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"Id: {Id}");
Logger?.LogAzureMapsControlDebug(AzureMapLogEvent.DataSource_GetClusterLeavesAsync, $"ClusterId: {clusterId}");

EnsureJsRuntimeExists();
EnsureNotDisposed();

return await JSRuntime.InvokeAsync<int>(Constants.JsConstants.Methods.Datasource.GetClusterExpansionZoom.ToDatasourceNamespace(), Id, clusterId);
}

internal void DispatchEvent(DataSourceEventArgs eventArgs)
{
switch (eventArgs.Type)
Expand Down
1 change: 1 addition & 0 deletions src/AzureMapsControl.Components/Logger/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ internal enum AzureMapLogEvent
Source_GetOptionsAsync = 7005,
Source_SetOptionsAsync = 7006,
DataSource_GetShapesAsync = 7100,
DataSource_GetClusterLeavesAsync = 7101,
GriddedDataSource_GetCellChildren = 7200,
GriddedDataSource_GetGridCells = 7201,
GriddedDataSource_GetPoints = 7202,
Expand Down
29 changes: 28 additions & 1 deletion src/AzureMapsControl.Components/typescript/sources/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as azmaps from 'azure-maps-control';
import { Core } from '../core/core';
import { Shape } from '../geometries/geometry';
import { Shape, Feature } from '../geometries/geometry';

export class Datasource {

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

public static async getClusterLeaves(datasourceId: string, clusterId: number, limit: number, offset: number): Promise<(Shape | Feature)[]> {
return new Promise(resolve => {
(Core.getMap().sources.getById(datasourceId) as azmaps.source.DataSource).getClusterLeaves(clusterId, limit, offset).then(clusterLeaves => {

const resultLeaves = clusterLeaves.map(leaf => {
if (leaf instanceof azmaps.Shape) {
return Core.getSerializableShape(leaf);
}

if (leaf instanceof azmaps.data.Feature) {
return Core.getSerializableFeature(leaf);
}
});

resolve(resultLeaves);
});
});
}

public static async getClusterExpansionZoom(datasourceId: string, clusterId: number): Promise<number> {
return new Promise(resolve => {
(Core.getMap().sources.getById(datasourceId) as azmaps.source.DataSource).getClusterExpansionZoom(clusterId).then(zoom => {
resolve(zoom);
});
});
}

}
25 changes: 13 additions & 12 deletions tests/AzureMapsControl.Components.Tests/Animations/Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using AzureMapsControl.Components.Animations;
using AzureMapsControl.Components.Runtime;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void Should_Create(string animationType)

[Theory]
[MemberData(nameof(AllAnimationsTypes))]
public async void Should_DisposeAsync(string animationType)
public async Task Should_DisposeAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -128,7 +129,7 @@ public async void Should_DisposeAsync(string animationType)

[Theory]
[MemberData(nameof(AllAnimationsTypes))]
public async void Should_ThrowAnimationDisposedException_DisposeAsync(string animationType)
public async Task Should_ThrowAnimationDisposedException_DisposeAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -141,7 +142,7 @@ public async void Should_ThrowAnimationDisposedException_DisposeAsync(string ani

[Theory]
[MemberData(nameof(AllPauseAnimationsTypes))]
public async void Should_PauseAsync(string animationType)
public async Task Should_PauseAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -153,7 +154,7 @@ public async void Should_PauseAsync(string animationType)

[Theory]
[MemberData(nameof(AllPauseAnimationsTypes))]
public async void Should_ThrowAnimationDisposedException_PauseAsync(string animationType)
public async Task Should_ThrowAnimationDisposedException_PauseAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -166,7 +167,7 @@ public async void Should_ThrowAnimationDisposedException_PauseAsync(string anima

[Theory]
[MemberData(nameof(AllPlayAnimationsTypes))]
public async void Should_PlayAsync(string animationType)
public async Task Should_PlayAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -178,7 +179,7 @@ public async void Should_PlayAsync(string animationType)

[Theory]
[MemberData(nameof(AllPlayAnimationsTypes))]
public async void Should_ThrowAnimationDisposedException_PlayAsync(string animationType)
public async Task Should_ThrowAnimationDisposedException_PlayAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -191,7 +192,7 @@ public async void Should_ThrowAnimationDisposedException_PlayAsync(string animat

[Theory]
[MemberData(nameof(AllResetAnimationsTypes))]
public async void Should_ResetAsync(string animationType)
public async Task Should_ResetAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -203,7 +204,7 @@ public async void Should_ResetAsync(string animationType)

[Theory]
[MemberData(nameof(AllResetAnimationsTypes))]
public async void Should_ThrowAnimationDisposedException_ResetAsync(string animationType)
public async Task Should_ThrowAnimationDisposedException_ResetAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -216,7 +217,7 @@ public async void Should_ThrowAnimationDisposedException_ResetAsync(string anima

[Theory]
[MemberData(nameof(AllSeekAnimationsTypes))]
public async void Should_SeekAsync(string animationType)
public async Task Should_SeekAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -229,7 +230,7 @@ public async void Should_SeekAsync(string animationType)

[Theory]
[MemberData(nameof(AllSeekAnimationsTypes))]
public async void Should_ThrowAnimationDisposedException_SeekAsync(string animationType)
public async Task Should_ThrowAnimationDisposedException_SeekAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -243,7 +244,7 @@ public async void Should_ThrowAnimationDisposedException_SeekAsync(string animat

[Theory]
[MemberData(nameof(AllStopAnimationsTypes))]
public async void Should_StopAsync(string animationType)
public async Task Should_StopAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand All @@ -255,7 +256,7 @@ public async void Should_StopAsync(string animationType)

[Theory]
[MemberData(nameof(AllStopAnimationsTypes))]
public async void Should_ThrowAnimationDisposedException_StopAsync(string animationType)
public async Task Should_ThrowAnimationDisposedException_StopAsync(string animationType)
{
var id = "id";
var animation = AnimationFactory.GetAnimation(animationType, id, _jsRuntime.Object);
Expand Down
Loading