Skip to content

Commit

Permalink
New LayerId for base layer on SwissMap (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: lolochristen <[email protected]>
  • Loading branch information
lolochristen and lolochristen authored Oct 23, 2023
1 parent 960c5f9 commit 73bae33
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
25 changes: 19 additions & 6 deletions src/OpenLayers.Blazor.Demo.Components/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@
<h5 class="card-subtitle">Coordinates in VL95/EPSG:2056</h5>
</div>
<div class="card-body">

<button class="btn btn-primary" @onclick="CenterLocation">Center to current location</button>
<button class="btn btn-primary" @onclick="AddMarkLocation">Add Mark at current location</button>
<button class="btn btn-primary" @onclick="SetVisibleExtent">Beautiful</button>
<input type="range" min="1" max="15" @bind-value="_zoom"> <code>@_zoom</code>
<div class="btn-toolbar gap-1" role="toolbar">
@if (_map != null)
{
<select id="layerId" @bind="_map.LayerId">
<option value="ch.swisstopo.pixelkarte-farbe">ch.swisstopo.pixelkarte-farbe</option>
<option value="ch.swisstopo.pixelkarte-grau">ch.swisstopo.pixelkarte-grau</option>
<option value="ch.swisstopo.pixelkarte-farbe-winter">ch.swisstopo.pixelkarte-farbe-winter</option>
<option value="ch.swisstopo.swissimage">ch.swisstopo.swissimage</option>
</select>
}
<button class="btn btn-primary" @onclick="CenterLocation">Center to current location</button>
<button class="btn btn-primary" @onclick="AddMarkLocation">Add Mark at current location</button>
<button class="btn btn-primary" @onclick="SetVisibleExtent">Beautiful</button>
<div class="input-group">
<label for="zoom" class="form-label">Zoom @_zoom</label>
<input type="range" class="form-range" id="zoom" min="1" max="15" @bind-value="_zoom">
</div>
</div>
<p>
<pre>
<pre>
Center:@_map?.Center
Last Position: @_lastPosition?.X / @_lastPosition?.Y
Altitude @(_altitude)m
Expand Down
41 changes: 34 additions & 7 deletions src/OpenLayers.Blazor/SwissMap.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
namespace OpenLayers.Blazor;
using Microsoft.AspNetCore.Components;

namespace OpenLayers.Blazor;

public class SwissMap : Map
{
public SwissMap()
{
LayersList.Add(new Layer
LayerId = "ch.swisstopo.pixelkarte-farbe";
SetBaseLayer(LayerId);
Center = new Coordinate { X = 2660013.54, Y = 1185171.98 }; // Swiss Center
Zoom = 2.4;
Defaults.CoordinatesProjection = "EPSG:2056"; // VT95
}


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

protected override Task OnParametersSetAsync()
{
if (LayersList.Count > 0 && LayersList[0].SourceParameters["LAYERS"] != LayerId)
SetBaseLayer(LayerId);
return base.OnParametersSetAsync();
}

protected void SetBaseLayer(string layerId)
{
Console.WriteLine($"SetBaseLayer {layerId}");
var layer = new Layer
{
Extent = new double[] { 2420000, 1030000, 2900000, 1350000 },
SourceType = SourceType.TileWMS,
Url = "https://wms.geo.admin.ch/",
CrossOrigin = "anonymous",
SourceParameters = new Dictionary<string, object> { { "LAYERS", "ch.swisstopo.pixelkarte-farbe" }, { "FORMAT", "image/jpeg" } },
SourceParameters = new Dictionary<string, object> { { "LAYERS", layerId }, { "FORMAT", "image/jpeg" } },
ServerType = "mapserver",
Attributions = "© <a href=\"https://www.swisstopo.admin.ch/en/home.html\" target=\"_blank\">swisstopo</a>"
});
Center = new Coordinate { X = 2660013.54, Y = 1185171.98 }; // Swiss Center
Zoom = 2.4;
Defaults.CoordinatesProjection = "EPSG:2056"; // VT95
};

if (LayersList.Count == 0)
LayersList.Add(layer);
else
{
LayersList[0] = layer;
}
}

/// <summary>
Expand Down

0 comments on commit 73bae33

Please sign in to comment.