WMS Layer not showing in Webmercator projection

704
3
04-12-2018 08:01 AM
MarvinKalani
New Contributor II

I like to show a Webmercator projection but instead always the WGS84 projection is shown.

I tried to set the SpatialReference in front of loading the WmsLayer but it still uses the WGS84 projection:

MainMapView = new MapView
            {
                Map = new Esri.ArcGISRuntime.Mapping.Map(SpatialReferences.WebMercator)
            };

The only solution is to disable WGS84 projections in the server component.

Is there any other way? In ArcgisRuntime 10.2.7 it was possible. Now with Version 100.x it seems the WMSLayer always tries to get the CRS:84 projection.

0 Kudos
3 Replies
MatveiStefarov
Esri Contributor

In Runtime 100.x, layers select a spatial reference when they become loaded. If a layer is forced to load before it is associated with a Map, then it will have to choose a default. For WMSLayer that default is WGS84.

Try rearranging the code so that the WMSLayer is added to a Map before calling LoadAsync on it. It should then choose a matching spatial reference and draw.

0 Kudos
MatveiStefarov
Esri Contributor

Correction: I investigated this more, and the timing of LoadAsync actually does not matter in current version of Runtime. You should be able to add a WMSLayer to that Map before or after the layer loads. So there is something else going on.

I'm having trouble reproducing this problem on my machine with sample WMS services. Would you be able to share more information about your WMS service and about the code?

0 Kudos
MarvinKalani
New Contributor II

Actually I had an error in using the Map in the xaml itself, now I initialize only the used Map of the MainMapView. It now behaves as I wanted and uses the correct projection for 3857.

So this is actually the solution for the 3857 projection but not for the 4326 because it tries to use the unallowed CRS:84 instead of EPSG:4326

Start a WPF Application:

MainWindow.xaml:

<Window x:Class="Map.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Map"
        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        >
    <Grid>
        <esri:MapView x:Name="MainMapView"/>
    </Grid>
</Window>

The Code behind in MainWindow.xaml.cs is:

            var wmsUrl = new Uri("http://wmsServer/wmsservice?");
            WmsLayer myWmsLayer = new WmsLayer(wmsUrl, new[] { "WMS3857" });
            MainMapView.Map = new Esri.ArcGISRuntime.Mapping.Map(SpatialReferences.WebMercator) { Basemap = new Basemap(myWmsLayer) };

The wrong used CRS:84 appears by using :

            var wmsUrl = new Uri("http://wmsServer/wmsservice?");
            WmsLayer myWmsLayer = new WmsLayer(wmsUrl, new[] { "WMS4326" });
            MainMapView.Map = new Esri.ArcGISRuntime.Mapping.Map(SpatialReferences.Wgs84) { Basemap = new Basemap(myWmsLayer) };

It should use EPSG:4326 as in ArcgisRuntime 10.2.7

0 Kudos