Skip to content

Commit

Permalink
Merge branch 'bug/174_c_sharp_attributes' into beta/2.2.0-beta-3
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPurdum committed May 20, 2023
2 parents cc3856c + 899776d commit 341863d
Show file tree
Hide file tree
Showing 11 changed files with 4,491 additions and 5,193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public dymaptic.GeoBlazor.Core.Objects.AttributesDictionary Attributes { get; se
#### Property Value
[AttributesDictionary](dymaptic.GeoBlazor.Core.Objects.AttributesDictionary.html 'dymaptic.GeoBlazor.Core.Objects.AttributesDictionary')

### Remarks
This collection should only be set via the constructor or as a markup parameter/attribute. To add or remove
members, use the methods defined in [AttributesDictionary](dymaptic.GeoBlazor.Core.Objects.AttributesDictionary.html 'dymaptic.GeoBlazor.Core.Objects.AttributesDictionary')

<a name='dymaptic.GeoBlazor.Core.Components.Layers.Graphic.Geometry'></a>

## Graphic.Geometry Property
Expand Down
4,330 changes: 2,157 additions & 2,173 deletions docs/pages/classes/dymaptic.GeoBlazor.Core.Components.Views.MapView.md

Large diffs are not rendered by default.

5,174 changes: 2,196 additions & 2,978 deletions docs/pages/classes/dymaptic.GeoBlazor.Core.Model.GeometryEngine.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ public System.Collections.Generic.Dictionary<string,object>.KeyCollection Keys {
Event that is fired when an attribute is added, updated or removed

```csharp
public Microsoft.AspNetCore.Components.EventCallback OnChange { get; set; }
public System.Func<System.Threading.Tasks.Task>? OnChange { get; set; }
```

#### Property Value
[Microsoft.AspNetCore.Components.EventCallback](https://docs.microsoft.com/en-us/dotnet/api/Microsoft.AspNetCore.Components.EventCallback 'Microsoft.AspNetCore.Components.EventCallback')
[System.Func&lt;](https://docs.microsoft.com/en-us/dotnet/api/System.Func-1 'System.Func`1')[System.Threading.Tasks.Task](https://docs.microsoft.com/en-us/dotnet/api/System.Threading.Tasks.Task 'System.Threading.Tasks.Task')[&gt;](https://docs.microsoft.com/en-us/dotnet/api/System.Func-1 'System.Func`1')
<a name='dymaptic.GeoBlazor.Core.Objects.AttributesDictionary.this[string]'></a>

## AttributesDictionary.this[string] Property

Gets or the value associated with the specified key.
Gets or sets the value associated with the specified key.

```csharp
public object this[string key] { get; }
public object this[string key] { get; set; }
```
#### Parameters

Expand All @@ -107,6 +107,9 @@ The key to get the value for
#### Property Value
[System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.Object 'System.Object')
### Remarks
Setter is obsolete and potentially unstable due to calling async from sync code.

<a name='dymaptic.GeoBlazor.Core.Objects.AttributesDictionary.Values'></a>

## AttributesDictionary.Values Property
Expand Down Expand Up @@ -147,6 +150,26 @@ The value to add or update
#### Returns
[System.Threading.Tasks.Task](https://docs.microsoft.com/en-us/dotnet/api/System.Threading.Tasks.Task 'System.Threading.Tasks.Task')
<a name='dymaptic.GeoBlazor.Core.Objects.AttributesDictionary.AddOrUpdate(System.Collections.Generic.Dictionary_string,object_)'></a>

## AttributesDictionary.AddOrUpdate(Dictionary<string,object>) Method

Updates the AttributesDictionary with new key/value pairs from a [System.Collections.Generic.Dictionary&lt;&gt;](https://docs.microsoft.com/en-us/dotnet/api/System.Collections.Generic.Dictionary-2 'System.Collections.Generic.Dictionary`2')
```csharp
public System.Threading.Tasks.Task AddOrUpdate(System.Collections.Generic.Dictionary<string,object> newEntries);
```
#### Parameters

<a name='dymaptic.GeoBlazor.Core.Objects.AttributesDictionary.AddOrUpdate(System.Collections.Generic.Dictionary_string,object_).newEntries'></a>

`newEntries` [System.Collections.Generic.Dictionary&lt;](https://docs.microsoft.com/en-us/dotnet/api/System.Collections.Generic.Dictionary-2 'System.Collections.Generic.Dictionary`2')[System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')[,](https://docs.microsoft.com/en-us/dotnet/api/System.Collections.Generic.Dictionary-2 'System.Collections.Generic.Dictionary`2')[System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.Object 'System.Object')[&gt;](https://docs.microsoft.com/en-us/dotnet/api/System.Collections.Generic.Dictionary-2 'System.Collections.Generic.Dictionary`2')
The new key/value pairs to add or update

#### Returns
[System.Threading.Tasks.Task](https://docs.microsoft.com/en-us/dotnet/api/System.Threading.Tasks.Task 'System.Threading.Tasks.Task')
<a name='dymaptic.GeoBlazor.Core.Objects.AttributesDictionary.Clear()'></a>

## AttributesDictionary.Clear() Method
Expand Down
59 changes: 38 additions & 21 deletions samples/dymaptic.GeoBlazor.Core.Sample.Shared/Pages/Scene.razor
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
<code>new TestObject("T1", "Test Object", 42, DateTime.UtcNow, false)</code>
</div>
<SceneView Longitude="_longitude" Latitude="_latitude" Class="map-view"
ZIndex="2000" Tilt="76">
ZIndex="2000" Tilt="76" OnMapRendered="OnMapRendered">
<Map Ground="world-elevation" ArcGISDefaultBasemap="satellite">
<GraphicsLayer>
<GraphicsLayer @ref="_graphicsLayer">
<Graphic @ref="_polygonGraphic" Attributes="_graphicAttributes">
<Polygon Rings="@(new[] { _mapRings })" />
<SimpleFillSymbol Color="@(new MapColor(81, 46, 132, 0.8))">
Expand All @@ -63,26 +63,19 @@

@code
{
private readonly double _latitude = 33.95;
private readonly double _longitude = -118.805;

private readonly MapPath _mapRings = new(new MapPoint(-118.818984489994, 34.0137559967283),
new MapPoint(-118.806796597377, 34.0215816298725),
new MapPoint(-118.791432890735, 34.0163883241613),
new MapPoint(-118.79596686535, 34.008564864635),
new MapPoint(-118.808558110679, 34.0035027131376));
private readonly Dictionary<string, object> _graphicAttributes = new()
private async Task OnMapRendered()
{
{ "Name", "This is a Title" },
{ "Description", "And a Description" },
{ "Number", 1 },
{ "Date", DateTime.Now },
{ "Boolean", true },
{ "Object", new TestObject("T1", "Test Object", 42, DateTime.UtcNow, false) }
};

private Graphic? _polygonGraphic;

if (_cSharpGraphic is null)
{
_cSharpGraphic = new Graphic(new Point(-118.83, 34.027),
new SimpleMarkerSymbol(color: new MapColor("green")),
new PopupTemplate("{Name}",
"{Description}<br/>Number: {Number}<br/>{Date}: {Date}<br/>Bool: {Boolean}</br>Object: {Object}"),
_graphicAttributes);
await _graphicsLayer!.Add(_cSharpGraphic);
}
}

private async Task UpdateAttribute(ChangeEventArgs arg, string attributeName)
{
if (attributeName == "Date")
Expand All @@ -92,6 +85,7 @@
var currentDate = (DateTime)_graphicAttributes["Date"];
var dt = new DateTime(newDate.Year, newDate.Month, newDate.Day, currentDate.Hour, currentDate.Minute, 0);
await _polygonGraphic!.Attributes.AddOrUpdate(attributeName, dt);
await _cSharpGraphic!.Attributes.AddOrUpdate(attributeName, dt);
}
}
else if (attributeName == "Time")
Expand All @@ -101,13 +95,36 @@
var currentDate = (DateTime)_graphicAttributes["Date"];
var dt = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, newDate.Hour, newDate.Minute, 0);
await _polygonGraphic!.Attributes.AddOrUpdate("Date", dt);
await _cSharpGraphic!.Attributes.AddOrUpdate("Date", dt);
}
}
else
{
await _polygonGraphic!.Attributes.AddOrUpdate(attributeName, arg.Value!);
await _cSharpGraphic!.Attributes.AddOrUpdate(attributeName, arg.Value!);
}
}

private readonly double _latitude = 33.95;
private readonly double _longitude = -118.805;

private readonly MapPath _mapRings = new(new MapPoint(-118.818984489994, 34.0137559967283),
new MapPoint(-118.806796597377, 34.0215816298725),
new MapPoint(-118.791432890735, 34.0163883241613),
new MapPoint(-118.79596686535, 34.008564864635),
new MapPoint(-118.808558110679, 34.0035027131376));
private readonly Dictionary<string, object> _graphicAttributes = new()
{
{ "Name", "This is a Title" },
{ "Description", "And a Description" },
{ "Number", 1 },
{ "Date", DateTime.Now },
{ "Boolean", true },
{ "Object", new TestObject("T1", "Test Object", 42, DateTime.UtcNow, false) }
};

private Graphic? _polygonGraphic;
private Graphic? _cSharpGraphic;
private GraphicsLayer? _graphicsLayer;
private record TestObject(string Name, string Description, int Number, DateTime Date, bool Boolean);
}
13 changes: 7 additions & 6 deletions src/dymaptic.GeoBlazor.Core/Components/Layers/Graphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Graphic(Geometry? geometry = null, Symbol? symbol = null, PopupTemplate?
Attributes = attributes;
}
#pragma warning restore BL0005
Attributes.OnChange = EventCallback.Factory.Create(this, OnAttributesChanged);
Attributes.OnChange = OnAttributesChanged;
ToSerializationRecord();
}

Expand All @@ -81,6 +81,10 @@ public Graphic(Geometry? geometry = null, Symbol? symbol = null, PopupTemplate?
/// <summary>
/// Name-value pairs of fields and field values associated with the graphic.
/// </summary>
/// <remarks>
/// This collection should only be set via the constructor or as a markup parameter/attribute. To add or remove
/// members, use the methods defined in <see cref="AttributesDictionary"/>
/// </remarks>
[Parameter]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public AttributesDictionary Attributes { get; set; } = new();
Expand Down Expand Up @@ -316,11 +320,8 @@ public override async Task SetParametersAsync(ParameterView parameters)

_updateAttributes = true;
}

if (!Attributes.OnChange.HasDelegate)
{
Attributes.OnChange = EventCallback.Factory.Create(this, OnAttributesChanged);
}

Attributes.OnChange ??= OnAttributesChanged;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/dymaptic.GeoBlazor.Core/Model/LogicComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ public void OnJavascriptError(JavascriptError error)
{
var exception = new JavascriptException(error);

#pragma warning disable CS0618
if (OnJavascriptErrorHandler is not null)

{
OnJavascriptErrorHandler?.Invoke(exception);
}
#pragma warning restore CS0618
else
{
throw exception;
Expand Down
60 changes: 54 additions & 6 deletions src/dymaptic.GeoBlazor.Core/Objects/AttributesDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static explicit operator Dictionary<string, object>(AttributesDictionary
/// Event that is fired when an attribute is added, updated or removed
/// </summary>
[JsonIgnore]
public EventCallback OnChange { get; set; }
public Func<Task>? OnChange { get; set; }

/// <summary>
/// The number of attribute entries in the dictionary
Expand Down Expand Up @@ -167,7 +167,29 @@ public async Task AddOrUpdate(string key, object value)
{
_backingDictionary[key] = value;

await OnChange.InvokeAsync();
if (OnChange is not null)
{
await OnChange();
}
}

/// <summary>
/// Updates the AttributesDictionary with new key/value pairs from a <see cref="Dictionary{TKey,TValue}"/>
/// </summary>
/// <param name="newEntries">
/// The new key/value pairs to add or update
/// </param>
public async Task AddOrUpdate(Dictionary<string, object> newEntries)
{
foreach (KeyValuePair<string, object> kvp in newEntries)
{
_backingDictionary[kvp.Key] = kvp.Value;
}

if (OnChange is not null)
{
await OnChange();
}
}

/// <summary>
Expand All @@ -180,7 +202,10 @@ public async Task Remove(string key)
{
_backingDictionary.Remove(key);

await OnChange.InvokeAsync();
if (OnChange is not null)
{
await OnChange();
}
}

/// <summary>
Expand All @@ -190,7 +215,10 @@ public async Task Clear()
{
_backingDictionary.Clear();

await OnChange.InvokeAsync();
if (OnChange is not null)
{
await OnChange();
}
}

/// <summary>
Expand Down Expand Up @@ -266,12 +294,32 @@ internal AttributeSerializationRecord[] ToSerializationRecord()
private readonly Dictionary<string, object> _backingDictionary;

/// <summary>
/// Gets or the value associated with the specified key.
/// Gets or sets the value associated with the specified key.
/// </summary>
/// <remarks>
/// Setter is obsolete and potentially unstable due to calling async from sync code.
/// </remarks>
/// <param name="key">
/// The key to get the value for
/// </param>
public object this[string key] => _backingDictionary[key];
public object this[string key]
{
get => _backingDictionary[key];
[Obsolete("Use AddOrUpdate instead")]
set
{
if (_backingDictionary.ContainsKey(key) && _backingDictionary[key] == value)
{
return;
}
_backingDictionary[key] = value;

if (OnChange is not null)
{
Task.Run(OnChange);
}
}
}
}

[ProtoContract(Name = "Attribute")]
Expand Down
4 changes: 2 additions & 2 deletions src/dymaptic.GeoBlazor.Core/dymaptic.GeoBlazor.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</Description>
<Title>GeoBlazor</Title>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageVersion>2.1.1-beta-1</PackageVersion>
<Version>2.1.1-beta-1</Version>
<PackageVersion>2.2.0-beta-2</PackageVersion>
<Version>2.2.0-beta-2</Version>
<Authors>Tim Purdum, Christopher Moravec, Mara Stoica, Tim Rawson</Authors>
<Company>dymaptic</Company>
<Copyright>©2023 by dymaptic</Copyright>
Expand Down
4 changes: 2 additions & 2 deletions src/dymaptic.GeoBlazor.Core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/dymaptic.GeoBlazor.Core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dymaptic.GeoBlazor.Core",
"version": "2.1.1-beta-1",
"version": "2.2.0-beta-2",
"description": "https://www.geoblazor.com",
"main": "arcGisInterop.js",
"scripts": {
Expand Down

0 comments on commit 341863d

Please sign in to comment.