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

Feature/193 feature edits #194

Merged
merged 4 commits into from
Jul 13, 2023
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 @@ -16,7 +16,6 @@

namespace dymaptic.GeoBlazor.Core.Sample.Maui.Platforms.Android;

#nullable enable
/// <summary>
/// Borrowed from https://github.com/MackinnonBuck/MauiBlazorPermissionsExample
/// </summary>
Expand Down
252 changes: 250 additions & 2 deletions src/dymaptic.GeoBlazor.Core/Components/Layers/FeatureLayer.cs

Large diffs are not rendered by default.

51 changes: 46 additions & 5 deletions src/dymaptic.GeoBlazor.Core/Components/Layers/Field.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using dymaptic.GeoBlazor.Core.Serialization;
using dymaptic.GeoBlazor.Core.Components.Widgets;
using dymaptic.GeoBlazor.Core.Serialization;
using Microsoft.AspNetCore.Components;
using System.Text.Json.Serialization;

Expand All @@ -8,10 +9,7 @@ namespace dymaptic.GeoBlazor.Core.Components.Layers;
/// <summary>
/// Information about each field in a layer. Field objects must be constructed when creating a FeatureLayer from
/// client-side graphics. This class allows you to define the schema of each field in the FeatureLayer.
/// <a target="_blank" href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html">
/// ArcGIS
/// JS API
/// </a>
/// <a target="_blank" href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html">ArcGIS JS API</a>
/// </summary>
public class Field : MapComponent
{
Expand Down Expand Up @@ -131,6 +129,49 @@ public Field(FieldType type, string? name = null, string? alias = null, string?
[Parameter]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public FieldValueType? ValueType { get; set; }

/// <summary>
/// The domain associated with the field. Domains are used to constrain the values allowed in a field. There are two types of domains: RangeDomain and CodedValueDomain.
/// </summary>
public Domain? Domain { get; set; }

/// <inheritdoc />
public override async Task RegisterChildComponent(MapComponent child)
{
switch (child)
{
case Domain domain:
if (!domain.Equals(Domain))
{
Domain = domain;
}

break;
default:
await base.RegisterChildComponent(child);

break;
}
}

/// <inheritdoc />
public override async Task UnregisterChildComponent(MapComponent child)
{
switch (child)
{
case Domain domain:
if (domain.Equals(Domain))
{
Domain = null;
}

break;
default:
await base.UnregisterChildComponent(child);

break;
}
}
}

/// <summary>
Expand Down
18 changes: 18 additions & 0 deletions src/dymaptic.GeoBlazor.Core/Components/Views/MapView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,24 @@ public async Task<ScreenPoint> ToScreen(Point mapPoint)
CancellationTokenSource.Token, mapPoint, Id);
}

/// <summary>
/// Returns the current cursor when hovering over the view.
/// </summary>
public async Task<string> GetCursor()
{
return await ViewJsModule!.InvokeAsync<string>("getCursor",
CancellationTokenSource.Token, Id);
}

/// <summary>
/// Sets the cursor for the view.
/// </summary>
public async Task SetCursor(string cursor)
{
await ViewJsModule!.InvokeVoidAsync("setCursor",
CancellationTokenSource.Token, cursor, Id);
}

/// <summary>
/// The callback method for returning a chunk of data from a Blazor Server hit test.
/// </summary>
Expand Down
136 changes: 136 additions & 0 deletions src/dymaptic.GeoBlazor.Core/Components/Widgets/Domain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using Microsoft.AspNetCore.Components;
using System.Text.Json;
using System.Text.Json.Serialization;


namespace dymaptic.GeoBlazor.Core.Components.Widgets;

/// <summary>
/// Domains define constraints on a layer field. There are two types of domains: coded values and range domains. This is an abstract class.
/// <a target="_blank" href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Domain.html">ArcGIS JS API</a>
/// </summary>
[JsonConverter(typeof(DomainConverter))]
public abstract class Domain : MapComponent
{
/// <summary>
/// The domain type.
/// </summary>
public abstract string Type { get; }

/// <summary>
/// The domain name.
/// </summary>
[Parameter]
public string? Name { get; set; }
}

/// <summary>
/// Information about the coded values belonging to the domain. Coded value domains specify a valid set of values for a field. Each valid value is assigned a unique name. For example, in a layer for water mains, water main features may be buried under different types of surfaces as signified by a GroundSurfaceType field: pavement, gravel, sand, or none (for exposed water mains). The coded value domain includes both the actual value that is stored in the database (for example, 1 for pavement) and a more user-friendly description of what that value actually means.
/// <a target="_blank" href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-CodedValueDomain.html">ArcGIS JS API</a>
/// </summary>
public class CodedValueDomain : Domain
{
/// <inheritdoc />
public override string Type => "coded-value";

/// <summary>
/// An array of the coded values in the domain.
/// </summary>
public HashSet<CodedValue>? CodedValues { get; set; }

/// <inheritdoc />
public override async Task RegisterChildComponent(MapComponent child)
{
switch (child)
{
case CodedValue codedValue:
CodedValues ??= new HashSet<CodedValue>();

CodedValues.Add(codedValue);

break;
default:
await base.RegisterChildComponent(child);

break;
}
}

/// <inheritdoc />
public override async Task UnregisterChildComponent(MapComponent child)
{
switch (child)
{
case CodedValue codedValue:
CodedValues?.Remove(codedValue);

break;
default:
await base.UnregisterChildComponent(child);

break;
}
}
}

/// <summary>
/// The coded value in a domain.
/// <a target="_blank" href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-CodedValueDomain.html#CodedValue">ArcGIS JS API</a>
/// </summary>
public class CodedValue : MapComponent
{
/// <summary>
/// The name of the coded value.
/// </summary>
[Parameter]
public string? Name { get; set; }

/// <summary>
/// The value of the code.
/// </summary>
[Parameter]
public string? Code { get; set; }
}

/// <summary>
/// Range domains specify a valid minimum and maximum valid value that can be stored in numeric and date fields.
/// <a target="_blank" href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-RangeDomain.html">ArcGIS JS API</a>
/// </summary>
public class RangeDomain : Domain
{
/// <inheritdoc />
public override string Type => "range";

/// <summary>
/// The maximum valid value.
/// </summary>
[Parameter]
public double? MaxValue { get; set; }

/// <summary>
/// The minimum valid value.
/// </summary>
[Parameter]
public double? MinValue { get; set; }
}

internal class DomainConverter : JsonConverter<Domain>
{
public override Domain? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var json = JsonDocument.ParseValue(ref reader);
var type = json.RootElement.GetProperty("type").GetString();

return type switch
{
"coded-value" => JsonSerializer.Deserialize<CodedValueDomain>(json.RootElement.GetRawText(), options),
"range" => JsonSerializer.Deserialize<RangeDomain>(json.RootElement.GetRawText(), options),
_ => null
};
}

public override void Write(Utf8JsonWriter writer, Domain value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, (object)value, options);
}
}
Loading