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

Bug fixes and support for pro freatures #219

Merged
merged 3 commits into from
Aug 9, 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 @@ -30,6 +30,7 @@

private void OnLayerViewCreate(LayerViewCreateEvent evt)
{
if (evt.Layer is not FeatureLayer layer) return;
_layerView = evt.LayerView as FeatureLayerView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
new("basemaps", "Basemaps", "oi-map"),
new("feature-layers", "Feature Layers", "oi-layers"),
new("popups", "Popups", "oi-chat"),
new("bookmarks", "Bookmarks", "oi-bookmark"),
new("popup-actions", "Popup Actions", "oi-bullhorn"),
new("bookmarks", "Bookmarks", "oi-bookmark"),
new("vector-layer", "Vector Layer", "oi-arrow-right"),
new("layer-lists", "Layer Lists", "oi-list"),
new("basemap-layer-lists", "Basemap Layer Lists", "oi-spreadsheet"),
Expand Down
80 changes: 79 additions & 1 deletion src/dymaptic.GeoBlazor.Core/Components/Widgets/LegendWidget.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using dymaptic.GeoBlazor.Core.Components.Layers;
using dymaptic.GeoBlazor.Core.Serialization;
using Microsoft.AspNetCore.Components;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -26,6 +27,17 @@ public class LegendWidget : Widget
/// </summary>
public HashSet<LayerInfo> LayerInfos { get; set; } = new();

/// <summary>
/// Indicates the style of the legend. The style determines the legend's layout and behavior.
/// You can either specify a string or an object to indicate the style.
/// The known string values are the same values listed in the table within the type property.
/// <a target="_blank" href=" https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend.html#style">
/// ArcGIS
/// JS API
/// </a>
/// </summary>
public LegendStyle? Style { get; set; }

/// <inheritdoc />
public override async Task RegisterChildComponent(MapComponent child)
{
Expand All @@ -34,6 +46,10 @@ public override async Task RegisterChildComponent(MapComponent child)
case LayerInfo layerInfo:
LayerInfos.Add(layerInfo);

break;
case LegendStyle style:
Style = style;

break;
default:
await base.RegisterChildComponent(child);
Expand All @@ -50,6 +66,10 @@ public override async Task UnregisterChildComponent(MapComponent child)
case LayerInfo layerInfo:
LayerInfos.Remove(layerInfo);

break;
case LegendStyle:
Style = null;

break;
default:
await base.UnregisterChildComponent(child);
Expand All @@ -67,6 +87,8 @@ internal override void ValidateRequiredChildren()
layerInfo.ValidateRequiredChildren();
}

Style?.ValidateRequiredChildren();

base.ValidateRequiredChildren();
}
}
Expand Down Expand Up @@ -99,4 +121,60 @@ public class LayerInfo : MapComponent
[Parameter]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public int[]? SublayerIds { get; set; }
}
}

/// <summary>
/// The widget legend style, sets the display style of the legend widget.
/// <a target="_blank" href=" https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend.html#style">
/// ArcGIS
/// JS API
/// </a>
/// </summary>
public class LegendStyle : MapComponent
{
/// <summary>
/// The Legend style type.
/// </summary>
[Parameter]
public LegendStyleType? Type { get; set; }

/// <summary>
/// The legend style layout when there are multiple legends
/// </summary>
[Parameter]
public LegendStyleLayout? Layout { get; set; }
}


/// <summary>
/// The Legend style type.
/// <a target="_blank" href=" https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend.html#style">
/// ArcGIS
/// JS API
/// </a>
/// </summary>
[JsonConverter(typeof(EnumToKebabCaseStringConverter<LegendStyleType>))]
public enum LegendStyleType
{
#pragma warning disable CS1591
Card,
AndersenBell marked this conversation as resolved.
Show resolved Hide resolved
Classic,
#pragma warning restore CS1591
}

/// <summary>
/// The legend style layout when there are multiple legends
/// <a target="_blank" href=" https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend.html#style">
/// ArcGIS
/// JS API
/// </a>
/// </summary>
[JsonConverter(typeof(EnumToKebabCaseStringConverter<LegendStyleLayout>))]
public enum LegendStyleLayout
{
#pragma warning disable CS1591
Auto,
SideBySide,
Stack
#pragma warning restore CS1591
}
10 changes: 5 additions & 5 deletions src/dymaptic.GeoBlazor.Core/Objects/TimeInterval.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using dymaptic.GeoBlazor.Core.Serialization;
using dymaptic.GeoBlazor.Core.Extensions;
using dymaptic.GeoBlazor.Core.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;


Expand Down Expand Up @@ -35,9 +37,7 @@ public class TimeInterval
/// </a>
/// Used by Feature Layer.
/// </summary>


[JsonConverter(typeof(EnumToKebabCaseStringConverter<TemporalTime>))]
[JsonConverter(typeof(TimeEnumToKebabCaseStringConverter<TemporalTime>))]
public enum TemporalTime
{
#pragma warning disable CS1591
Expand All @@ -52,4 +52,4 @@ public enum TemporalTime
Decades,
Centuries
#pragma warning restore CS1591
}
}
15 changes: 14 additions & 1 deletion src/dymaptic.GeoBlazor.Core/Scripts/arcGisJsInterop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,9 @@ export async function updateWidget(widgetObject: any, viewId: string): Promise<v
switch (widgetObject.type) {
case 'bookmarks':
let bookmarks = currentWidget as Bookmarks;
bookmarks.bookmarks = widgetObject.bookmarks.map(buildJsBookmark)
if (hasValue(widgetObject.bookmarks)) {
bookmarks.bookmarks = widgetObject.bookmarks.map(buildJsBookmark);
}
break;
}
unsetWaitCursor(viewId);
Expand Down Expand Up @@ -1653,6 +1655,17 @@ async function createWidget(widget: any, viewId: string): Promise<Widget | null>
return jsLayerInfo;
});
}
if (hasValue(widget.style)) {
if (hasValue(widget.style.layout)) {
legend.style = {
type: widget.style.type,
layout: widget.style.layout
};
}
else {
legend.style = widget.style.type;
}
}
break;
case 'home':
const homeBtn = new Home({
Expand Down
2 changes: 1 addition & 1 deletion src/dymaptic.GeoBlazor.Core/Scripts/jsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ export function buildJsFeatureEffect(dnFeatureEffect: DotNetFeatureEffect): Feat
}
}
featureEffect.excludedLabelsVisible = dnFeatureEffect.excludedLabelsVisible ?? undefined;
if (hasValue(dnFeatureEffect?.excludedLabelsVisible)) {
if (hasValue(dnFeatureEffect?.filter)) {
featureEffect.filter = buildJsFeatureFilter(dnFeatureEffect.filter) as FeatureFilter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,32 @@ public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions
string resultString = stringVal!.ToKebabCase();
writer.WriteStringValue(resultString);
}
}


/// <summary>
/// Converts an enum to a kebab case string for serialization. Used with TimeInerval which returns esriTimeUnits from the ESRI JS.
/// </summary>
/// <typeparam name="T"></typeparam>
public class TimeEnumToKebabCaseStringConverter<T> : EnumToKebabCaseStringConverter<T> where T : notnull
{
/// <inheritdoc />
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string? value = reader.GetString()
?.Replace("-", string.Empty)
.Replace("esriTimeUnits", string.Empty)
.Replace(typeof(T).Name, string.Empty);

try
{
return value is not null ? (T)Enum.Parse(typeof(T), value, true) : default(T)!;
}
catch (Exception ex)
{
Console.WriteLine(ex);

return default(T)!;
}
}
}