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

Release Merge #226

Merged
merged 10 commits into from
Sep 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
</div>
<p>Need help creating your own Geospatial Information System, maps, or data applications?</p>
<p>Visit <a href="https://www.dymaptic.com">dymaptic.com</a> or <a href="mailto:geoblazor@dymaptic.com">email us</a> and let us know how we can help you!</p>

<a id="follow-button" class="btn" title="Follow @@GeoBlazor on Twitter"
href="https://twitter.com/intent/follow?original_referer=https%3A%2F%2Fpublish.twitter.com%2F&amp;ref_src=twsrc%5Etfw%7Ctwcamp%5Ebuttonembed%7Ctwterm%5Efollow%7Ctwgr%5EGeoBlazor&amp;region=follow_link&amp;screen_name=GeoBlazor">
<img src="_content/dymaptic.GeoBlazor.Core.Sample.Shared/images/twitter.svg" style="width: 14px; height: 14px; margin: 0 6px 3px 0" /><span class="label" id="l">Follow <b>@@GeoBlazor</b></span>
</a>
<div class="pro">
Go Pro with the <a href="https://docs.geoblazor.com/pages/pro.html">GeoBlazor Pro</a> package!
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
font: normal normal normal 12px/18px 'Helvetica Neue', Arial, sans-serif;
}

.pro {
color: gold;
font-style: italic;
font-weight: bold;
padding: 1rem 0;
}

.pro a {
color: gold!important;
Copy link
Contributor

Choose a reason for hiding this comment

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

just poking in to say generally speaking, it's best not to use !important most of the time in CSS. Specifying the class and element like you did here should be enough to ensure no other rules in this file take priority. Is there maybe another reason !important is needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@agnesstelmach you are absolutely correct, and it was a shortcut months ago that I used instead of taking the time to figure out why it didn't work without it. I will try to revisit soon, or feel free when you're working in GB to update!

}

@media (max-width: 799px) {
#feature-inset {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@page "/click-to-add"
<PageTitle>Click to Add Points</PageTitle>
<h1>Click To Add Points</h1>
<div class="links-div">
<a class="btn btn-primary" target="_blank" href="https://www.arcgis.com/home/item.html?id=1e126e7520f9466c9ca28b8f28b5e500">World Ocean Basemap</a>
</div>

<p class="instructions">
Click anywhere to see a point added to the map. Click on the point again to see a popup. Click on the popup action to add the point to the list below.
</p>

<MapView Class="map-view" OnClick="OnClick" Zoom="4">
<Map>
<Basemap>
<TileLayer>
<PortalItem Id="1e126e7520f9466c9ca28b8f28b5e500" />
</TileLayer>
</Basemap>
<GraphicsLayer @ref="_graphicsLayer" />
</Map>
</MapView>

<div>
<h2>Points Clicked</h2>
@foreach (Point point in _points)
{
<p>Long: @point.Longitude!.Value.ToString("N2") Lat: @point.Latitude!.Value.ToString("N2")</p>
}
</div>

@code {
private async Task OnClick(ClickEvent arg)
{
Point point = arg.MapPoint;
if (_graphic is null)
{
_graphic = new Graphic(point);
await _graphicsLayer!.Add(_graphic);
}

SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(new Outline(new MapColor("blue")),
new MapColor("yellow"), 10);

ActionButton actionButton = new ActionButton("Click to Add to List",
"./_content/dymaptic.GeoBlazor.Core.Sample.Shared/images/dymaptic_logo.png", "test-1", AddPoint);
PopupTemplate popupTemplate = new PopupTemplate(
$"New Point at Long: {point.Longitude!.Value:N2} Lat: {point.Latitude!.Value:N2}",
actions: new[]{ actionButton });

await _graphic.SetPopupTemplate(popupTemplate);
await _graphic.SetSymbol(symbol);
await _graphic.SetGeometry(point);
}

private async Task AddPoint()
{
_points.Add(((Point)_graphic!.Geometry!).Clone());
await InvokeAsync(StateHasChanged);
}

private Graphic? _graphic;
private GraphicsLayer? _graphicsLayer;
private readonly List<Point> _points = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
new("", "Home", "oi-home"),
new("navigation", "Navigation", "oi-compass"),
new("drawing", "Drawing", "oi-pencil"),
new("click-to-add", "Click to Add Point", "oi-map-marker"),
new("many-graphics", "Many Graphics", "oi-calculator"),
new("scene", "Scene & Attributes", "oi-globe"),
new("widgets", "Widgets", "oi-location"),
Expand Down
95 changes: 95 additions & 0 deletions src/dymaptic.GeoBlazor.Core/Components/ActionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,56 @@ internal record ActionBaseSerializationRecord([property: JsonIgnore(Condition =
/// </summary>
public class ActionButton : ActionBase
{
/// <summary>
/// Parameterless constructor for use as a razor component.
/// </summary>
public ActionButton()
{
}

/// <summary>
/// Constructor for use in code.
/// </summary>
/// <param name="title">
/// The title of the action.
/// </param>
/// <param name="image">
/// The URL to an image that will be used to represent the action. This property will be used as a background image
/// </param>
/// <param name="id">
/// The name of the ID assigned to this action.
/// </param>
/// <param name="callbackFunction">
/// The action function to perform on click.
/// </param>
/// <param name="className">
/// This adds a CSS class to the ActionButton's node.
/// </param>
/// <param name="active">
/// Set this property to true to display a spinner icon.
/// </param>
/// <param name="disabled">
/// Indicates whether this action is disabled.
/// </param>
/// <param name="visible">
/// Indicates if the action is visible.
/// </param>
public ActionButton(string? title = null, string? image = null, string? id = null,
Func<Task>? callbackFunction = null, string? className = null, bool? active = null, bool? disabled = null,
bool? visible = null)
{
#pragma warning disable BL0005
Title = title;
Image = image;
Id = id;
CallbackFunction = callbackFunction;
ClassName = className;
Active = active;
Disabled = disabled;
Visible = visible;
#pragma warning restore BL0005
}

/// <inheritdoc />
public override string Type => "button";

Expand Down Expand Up @@ -141,6 +191,51 @@ internal override ActionBaseSerializationRecord ToSerializationRecord()
/// </summary>
public class ActionToggle : ActionBase
{
/// <summary>
/// Parameterless constructor for use as a razor component.
/// </summary>
public ActionToggle()
{
}

/// <summary>
/// Constructor for use in code.
/// </summary>
/// <param name="title">
/// The title of the action.
/// </param>
/// <param name="id">
/// The name of the ID assigned to this action.
/// </param>
/// <param name="callbackFunction">
/// The action function to perform on click.
/// </param>
/// <param name="value">
/// Indicates the value of whether the action is toggled on/off.
/// </param>
/// <param name="active">
/// Set this property to true to display a spinner icon.
/// </param>
/// <param name="disabled">
/// Indicates whether this action is disabled.
/// </param>
/// <param name="visible">
/// Indicates if the action is visible.
/// </param>
public ActionToggle(string? title = null, string? id = null, Func<Task>? callbackFunction = null,
bool? value = null, bool? active = null, bool? disabled = null, bool? visible = null)
{
#pragma warning disable BL0005
Title = title;
Id = id;
CallbackFunction = callbackFunction;
Value = value;
Active = active;
Disabled = disabled;
Visible = visible;
#pragma warning restore BL0005
}

/// <inheritdoc />
public override string Type => "toggle";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ internal PopupTemplateSerializationRecord ToSerializationRecord()
FieldInfos?.Select(f => f.ToSerializationRecord()),
Content.Select(c => c.ToSerializationRecord()),
ExpressionInfos?.Select(e => e.ToSerializationRecord()), OverwriteActions,
ReturnGeometry, Actions?.Select(a => a.ToSerializationRecord()));
ReturnGeometry, Actions?.Select(a => a.ToSerializationRecord()), Id.ToString());
}
}

Expand Down Expand Up @@ -362,5 +362,8 @@ internal record PopupTemplateSerializationRecord([property: JsonIgnore(Condition
bool? ReturnGeometry = null,
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[property: ProtoMember(9)]
IEnumerable<ActionBaseSerializationRecord>? Actions = null)
IEnumerable<ActionBaseSerializationRecord>? Actions = null,
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[property: ProtoMember(10)]
string? id = null)
: MapComponentSerializationRecord;
45 changes: 45 additions & 0 deletions src/dymaptic.GeoBlazor.Core/Components/Views/MapView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,51 @@ public async Task OnJavascriptLayerViewCreateError(LayerViewCreateErrorEvent err
/// </summary>
[Parameter]
public int? GraphicSerializationChunkSize { get; set; }

/// <summary>
/// For internal use only, this looks up a missing <see cref="DotNetObjectReference"/> for a <see cref="PopupTemplate"/>
/// and returns it to JavaScript.
/// </summary>
[JSInvokable]
public DotNetObjectReference<PopupTemplate>? GetDotNetPopupTemplateObjectReference(Guid popupTemplateId)
{
foreach (Graphic graphic in Graphics)
{
if (graphic.PopupTemplate?.Id == popupTemplateId)
{
return graphic.PopupTemplate.DotNetPopupTemplateReference;
}
}

foreach (Layer layer in Map!.Layers)
{
switch (layer)
{
case FeatureLayer { Source: not null } featureLayer:
foreach (Graphic graphic in featureLayer.Source)
{
if (graphic.PopupTemplate?.Id == popupTemplateId)
{
return graphic.PopupTemplate.DotNetPopupTemplateReference;
}
}

break;
case GraphicsLayer graphicsLayer:
foreach (Graphic graphic in graphicsLayer.Graphics)
{
if (graphic.PopupTemplate?.Id == popupTemplateId)
{
return graphic.PopupTemplate.DotNetPopupTemplateReference;
}
}

break;
}
}

return null;
}

#endregion

Expand Down
1 change: 1 addition & 0 deletions src/dymaptic.GeoBlazor.Core/Scripts/definitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export interface DotNetPopupTemplate {
overwriteActions: boolean;
returnGeometry: boolean;
dotNetPopupTemplateReference: any;
id: string;

actions: any[];
}
Expand Down
13 changes: 12 additions & 1 deletion src/dymaptic.GeoBlazor.Core/Scripts/jsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Extent from "@arcgis/core/geometry/Extent";
import Graphic from "@arcgis/core/Graphic";
import PopupTemplate from "@arcgis/core/PopupTemplate";
import { arcGisObjectRefs, triggerActionHandler } from "./arcGisJsInterop";
import {arcGisObjectRefs, dotNetRefs, triggerActionHandler} from "./arcGisJsInterop";
import Geometry from "@arcgis/core/geometry/Geometry";
import Point from "@arcgis/core/geometry/Point";
import Polyline from "@arcgis/core/geometry/Polyline";
Expand Down Expand Up @@ -227,6 +227,7 @@ export function buildJsPopupTemplate(popupTemplateObject: DotNetPopupTemplate, v
} else {
content = async (featureSelection) => {
try {
await lookupDotNetRefForPopupTemplate(popupTemplateObject, viewId as string);
let results: DotNetPopupContent[] | null = await popupTemplateObject.dotNetPopupTemplateReference
.invokeMethodAsync("OnContentFunction", buildDotNetGraphic(featureSelection.graphic));
return results?.map(r => buildJsPopupContent(r));
Expand Down Expand Up @@ -272,11 +273,13 @@ export function buildJsPopupTemplate(popupTemplateObject: DotNetPopupTemplate, v
reactiveUtils.once(() => view.popup.on !== undefined)
.then(() => {
templateTriggerActionHandler = view.popup.on("trigger-action", async (event: PopupTriggerActionEvent) => {
await lookupDotNetRefForPopupTemplate(popupTemplateObject, viewId as string);
await popupTemplateObject.dotNetPopupTemplateReference.invokeMethodAsync("OnTriggerAction", event.action.id);
});
})
} else {
templateTriggerActionHandler = view.popup.on("trigger-action", async (event: PopupTriggerActionEvent) => {
await lookupDotNetRefForPopupTemplate(popupTemplateObject, viewId as string);
await popupTemplateObject.dotNetPopupTemplateReference.invokeMethodAsync("OnTriggerAction", event.action.id);
});
}
Expand All @@ -290,6 +293,14 @@ export function buildJsPopupTemplate(popupTemplateObject: DotNetPopupTemplate, v
return template;
}

async function lookupDotNetRefForPopupTemplate(popupTemplateObject: DotNetPopupTemplate, viewId: string) {
if (!hasValue(popupTemplateObject.dotNetPopupTemplateReference)) {
let viewRef = dotNetRefs[viewId];
popupTemplateObject.dotNetPopupTemplateReference =
await viewRef.invokeMethodAsync('GetDotNetPopupTemplateObjectReference', popupTemplateObject.id);
}
}

export let templateTriggerActionHandler: IHandle;

export function buildJsPopupContent(popupContentObject: DotNetPopupContent): ContentProperties | null {
Expand Down
19 changes: 0 additions & 19 deletions src/dymaptic.GeoBlazor.Core/docCopy.ps1

This file was deleted.

9 changes: 2 additions & 7 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.3.0</PackageVersion>
<Version>2.3.0</Version>
<PackageVersion>2.3.2</PackageVersion>
<Version>2.3.2</Version>
<Authors>Tim Purdum, Christopher Moravec, Mara Stoica, Tim Rawson</Authors>
<Company>dymaptic</Company>
<Copyright>©2023 by dymaptic</Copyright>
Expand Down Expand Up @@ -100,11 +100,6 @@
<Exec Command="npm run releaseBuild" />
</Target>

<Target Name="Copy Files" AfterTargets="Build" Condition="$(Configuration) == 'RELEASE' AND $(TargetFrameworks.StartsWith($(TargetFramework))) AND '$(OptOutFromCoreEsBuild)' != 'true'">
<Message Importance="high" Text="Launching Async File Copy Script" />
<ExecAsync FilePath="pwsh" Arguments="./docCopy.ps1" ContinueOnError="true" />
</Target>

<!--Launch a Process in Parallel-->
<UsingTask TaskName="ExecAsync" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
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.

Loading