Skip to content
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
1 change: 1 addition & 0 deletions src/OpenLayers.Blazor/Internal/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Layer
public double? MaxZoom { get; set; }
public double Preload { get; set; } = 0;
public Source Source { get; set; } = new();
public string? Credentials { get; set; }
public bool UseInterimTilesOnError { get; set; } = true;
public Dictionary<string, object>? Properties { get; set; } = new();
public dynamic? Options { get; set; }
Expand Down
11 changes: 11 additions & 0 deletions src/OpenLayers.Blazor/Layer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ public string? ServerType
set => _internalLayer.Source.ServerType = value;
}

/// <summary>
/// Set credentials of query only for TileWMS (set header Authorization Basic)
/// It should be the Base64 value of "user:password"
/// </summary>
[Parameter]
public string? Credentials
{
get => _internalLayer.Credentials;
set => _internalLayer.Credentials = value;
}

/// <summary>
/// Gets or sets the layers the layer parameter for the source tile layers
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions src/OpenLayers.Blazor/wwwroot/openlayers_interop.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,23 @@ MapOL.prototype.prepareLayers = function(layers) {
break;
case "TileWMS":
source = new ol.source.TileWMS(l.source);
if (l.credentials) {
source.tileLoadFunction = function (tile, src) {
var client = new XMLHttpRequest();
client.responseType = 'blob';
client.open('GET', src);
client.setRequestHeader("Authorization", "Basic " + l.credentials);
client.onload = function() {
const url = URL.createObjectURL(client.response);
const img = tile.getImage();
img.addEventListener('load', function() {
URL.revokeObjectURL(url);
});
img.src = url;
};
client.send();
};
}
break;
case "WMTS":
source = new ol.source.WMTS(l.source);
Expand Down