I have a WMS layer I need to render in my application but for some reason it does not want to render unless I have set a basemap. This sadly will not work for me as I need the application to work offline I have followed the WMS layer (URL) example to a tee and the only way I can make the layer show is if I have defiend a basemap style.
I have tested that it is possible to add a WMS layer without a basemap by using the example from the sample app and that works fine.
Working Code:
private readonly Uri _wmsUrlVFR = new Uri("https://wms.chartbundle.com/mp/service?SERVICE=WMS&REQUEST=GetCapabilities");
private readonly List<string> _wmsLayerNamesVFR = new List<string> { "sec_3857" };
private async void Initialize()
{
Map myMap = new Map(BasemapStyle.ArcGISDarkGray);
// Add the map to the mapview.
MyMapView.Map = myMap;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// Create a new WMS layer displaying the specified layers from the service.
_VFRChart = new WmsLayer(_wmsUrlVFR, _wmsLayerNamesVFR);
MyMapView.Map.OperationalLayers.Add(_VFRChart);
}
Not working code:
private readonly Uri _wmsUrlVFR = new Uri("https://wms.chartbundle.com/mp/service?SERVICE=WMS&REQUEST=GetCapabilities");
private readonly List<string> _wmsLayerNamesVFR = new List<string> { "sec_3857" };
private async void Initialize()
{
Map myMap = new Map();
// Add the map to the mapview.
MyMapView.Map = myMap;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// Create a new WMS layer displaying the specified layers from the service.
_VFRChart = new WmsLayer(_wmsUrlVFR, _wmsLayerNamesVFR);
MyMapView.Map.OperationalLayers.Add(_VFRChart);
}
You will see the only difference is line 8
Solved! Go to Solution.
Map myMap = new Map(SpatialReferences.WebMercator);
Ah, I need to set the spatial reference.
Map myMap = new Map(SpatialReferences.WebMercator);