Unable to load WMS layer without defining basemap

506
2
Jump to solution
11-17-2022 08:43 AM
ZachRuiz
New Contributor III

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

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
ZachRuiz
New Contributor III

Map myMap = new Map(SpatialReferences.WebMercator);

View solution in original post

0 Kudos
2 Replies
ZachRuiz
New Contributor III

Ah, I need to set the spatial reference. 

 

0 Kudos
ZachRuiz
New Contributor III

Map myMap = new Map(SpatialReferences.WebMercator);

0 Kudos