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

Add a CSSClass parameter to the Map component #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -0,0 +1,52 @@
@page "/css-classes"

<div class="top-container">
<h1 class="page-header">Container CSS class</h1>
</div>

<div class="map-wrapper">
<Map @ref="mapRef" MapOptions="@mapOptions" CssClass="custom-css-class"></Map>
</div>


<div class="side-panel">
<h3 class="header">Functionalities</h3>
<SidePanelButton Label="get center"
IconSrc="@Icons.InitializationGetCenterIconSrc"
OnClick="async () => await GetCenterExample()"/>
<SidePanelButton Label="set view"
IconSrc="@Icons.InitializationSetViewIconSrc"
OnClick="async () => await mapRef.SetView(center)"/>
<SidePanelButton Label="set zoom"
IconSrc="@Icons.InitializationSetZoomIconSrc"
OnClick="async () => await mapRef.SetZoom(zoom: 16)"/>
<SidePanelButton Label="zoom in"
IconSrc="@Icons.InitializationZoomInIconSrc"
OnClick="async () => await mapRef.ZoomIn(zoomDelta: 1)"/>
<SidePanelButton Label="zoom out"
IconSrc="@Icons.InitializationZoomOutIconSrc"
OnClick="async () => await mapRef.ZoomOut(zoomDelta: 3)"/>
<SidePanelButton Label="set zoom around"
IconSrc="@Icons.InitializationSetZoomAroundIconSrc"
OnClick="async () => await mapRef.SetZoomAround(center, 10)"/>
</div>

<style>
.side-panel {
min-width: 400px;
display: grid;
grid-template-rows: minmax(3rem, 5rem) repeat(2, 150px);
grid-template-columns: repeat(4, 1fr);
}

.side-panel .header {
grid-column: 1/-1;
}

.side-panel .icon-wrapper .icon {
height: auto;
}
.custom-css-class {
border: 2px solid red;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Threading.Tasks;

namespace FisSst.BlazorMaps.Examples.Pages
{
public partial class CssClasses
{
private readonly LatLng center;
private Map mapRef;
private MapOptions mapOptions;

public CssClasses()
{
this.center = new LatLng(50.279133, 18.685578);
this.mapOptions = new MapOptions()
{
DivId = "mapId",
Center = center,
Zoom = 13,
UrlTileLayer = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
SubOptions = new MapSubOptions()
{
Attribution = "&copy; <a lhref='http://www.openstreetmap.org/copyright'>OpenStreetMap</a>",
MaxZoom = 18,
TileSize = 512,
ZoomOffset = -1,
}
};
}

[Inject]
private IJSRuntime JsRuntime { get; init; }

private async Task GetCenterExample()
{
LatLng center = await this.mapRef.GetCenter();
await this.JsRuntime.InvokeAsync<string>("alert", $"Map centered at: Lat: {center.Lat}, Lng: {center.Lng}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<div class="circle"></div>
<span class="label">Popups</span>
</NavLink>
<NavLink class="button-wrapper nav-link" href="css-classes">
<div class="circle"></div>
<span class="label">CSS Class</span>
</NavLink>
<NavLink class="button-wrapper nav-link" href="tests">
<div class="circle"></div>
<span class="label">Tests</span>
Expand Down
2 changes: 1 addition & 1 deletion FisSst.BlazorMaps/FisSst.BlazorMaps/Components/Map.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@namespace FisSst.BlazorMaps

<div id="@MapOptions.DivId"></div>
<div id="@MapOptions.DivId" class="@CssClass"></div>
3 changes: 3 additions & 0 deletions FisSst.BlazorMaps/FisSst.BlazorMaps/Components/Map.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public partial class Map : ComponentBase

[Parameter]
public MapOptions MapOptions { get; set; }

[Parameter]
public string CssClass { get; set; }

[Parameter]
public EventCallback AfterRender { get; set; }
Expand Down