Skip to content

Instantly share code, notes, and snippets.

@DGuidi
Created April 8, 2021 14:26
Show Gist options
  • Save DGuidi/f014dd1b2d503a96a67df826ca6d7c9b to your computer and use it in GitHub Desktop.
Save DGuidi/f014dd1b2d503a96a67df826ca6d7c9b to your computer and use it in GitHub Desktop.
WmsLayer extension for [BlazorLeaflet](https://github.com/Mehigh17/BlazorLeaflet)
addWmslayer: function (mapId, wmsLayer, objectReference) {
const layer = L.tileLayer.wms(wmsLayer.urlTemplate, {
attribution: wmsLayer.attribution,
pane: wmsLayer.pane,
// ---
tileSize: wmsLayer.tileSize ? L.point(wmsLayer.tileSize.width, wmsLayer.tileSize.height) : undefined,
opacity: wmsLayer.opacity,
updateWhenZooming: wmsLayer.updateWhenZooming,
updateInterval: wmsLayer.updateInterval,
zIndex: wmsLayer.zIndex,
bounds: wmsLayer.bounds && wmsLayer.bounds.item1 && wmsLayer.bounds.item2 ? L.latLngBounds(wmsLayer.bounds.item1, wmsLayer.bounds.item2) : undefined,
// ---
minZoom: wmsLayer.minimumZoom,
maxZoom: wmsLayer.maximumZoom,
subdomains: wmsLayer.subdomains,
errorTileUrl: wmsLayer.errorTileUrl,
zoomOffset: wmsLayer.zoomOffset,
// TMS
zoomReverse: wmsLayer.isZoomReversed,
detectRetina: wmsLayer.detectRetina,
// WMS
layers: wmsLayer.layers.join(),
styles: wmsLayer.styles.join(),
format: wmsLayer.format,
transparent: wmsLayer.transparent,
version: wmsLayer.version,
uppercase: wmsLayer.uppercase,
// crossOrigin
});
addLayer(mapId, layer, wmsLayer.id);
},
_map.AddLayer(new WmsLayer
{
UrlTemplate = "http://ows.mundialis.de/services/service?",
Layers = new string[] { "TOPO-WMS", "OSM-Overlay-WMS" }
});
namespace BlazorLeaflet.Models
{
public class WmsLayer : TileLayer
{
/// <summary>
/// List of layers to show.
/// </summary>
public string[] Layers { get; set; } = new string[0];
/// <summary>
/// List of styles to use.
/// </summary>
public string[] Styles { get; set; } = new string[0];
/// <summary>
/// WMS image format: use <c>'image/png'</c> for layers with transparency).
/// </summary>
public string Format { get; set; } = "image/jpeg";
/// <summary>
/// If <c>true</c>, the WMS service will return images with transparency.
/// </summary>
public bool Transparent { get; set; }
/// <summary>
/// Version of the WMS service to use
/// </summary>
public string Version { get; set; } = "1.1.1";
/// <summary>
/// If true, WMS request parameter keys will be uppercase.
/// </summary>
public bool Uppercase { get; set; }
// NOTE: CRS ignored (https://leafletjs.com/reference-1.7.1.html#tilelayer-wms)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment