Add wms layer first in selected spatial reference

2927
2
03-09-2016 03:00 AM
RobertDawidziuk
New Contributor


Hello,

I would like to add firstly WmsLayer and than FeatureLayer.

Wms layer suports more than one spatial reference (4326, 3857, 2180).

When I do it in order: wms, feature mapView is set to work in 4326,
but whan i firsty add featureLayer in 3857 and than wms layer mapView is set to 3857.

I need to have 3857 at mapview. Setting spatial reference to mapview.map do not change anything.

Do you know is there any way to force wms layer to open in selected spatial reference ?

0 Kudos
2 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

You need to set both the SpatialReference and the Extent which can be done via the InitialViewpoint property on the Map.

Cheers

Mike

0 Kudos
RobertDawidziuk
New Contributor

thanks for tip, I check it many times but it does not work,

1. code sample:

private async Task WmsWaw()
    {
      SpatialReference sr = new SpatialReference(2180);
      this.MyMapView.Map = new Map()
      {
        SpatialReference = sr
      };


      Esri.ArcGISRuntime.Layers.WmsLayer wms = new Esri.ArcGISRuntime.Layers.WmsLayer(new Uri("http://wms.um.warszawa.pl/serwis"));
      await wms.InitializeAsync();
      string name = "WMS/Raster_orto2010_10cm";
      wms.Layers = new List<string>() { name };


      var nameLayerInfo = wms.ServiceInfo.RootLayer.ChildLayers.FirstOrDefault(l => l.Name == name);


      this.MyMapView.Map.Layers.Add(wms);


      var extent = nameLayerInfo.Extent;
      if (nameLayerInfo.Extent.SpatialReference.Wkid != sr.Wkid)
        extent = GeometryEngine.Project(nameLayerInfo.Extent, sr).Extent;


      this.MyMapView.Map.InitialViewpoint = new Viewpoint(extent);


      await this.MyMapView.LayersLoadedAsync();
    }

Spatial references:

Map 2180

MapView 4326

MapView Extent Envelope[XMin=21.0472112879068, YMin=52.222082410043, XMax=21.0491953019784, YMax=52.2232987533104, Wkid=4326]

so map stil works in 4326

wms.warszawa.pl in root layer informs that supported spatial references is only 4326, child layers have more: 4326 and 2180

2. code sample

private async Task AddGeoportal2()
    {
      SpatialReference sr = new SpatialReference(2180);
      this.MyMapView.Map = new Map()
      {
        SpatialReference = sr
      };


      Esri.ArcGISRuntime.Layers.WmsLayer wms = new Esri.ArcGISRuntime.Layers.WmsLayer(new Uri("http://mapy.geoportal.gov.pl/wss/service/pub/guest/G2_GO_WMS/MapServer/WMSServer"));
      await wms.InitializeAsync();


      var ex = wms.ServiceInfo.RootLayer.Extent;
      if (ex.SpatialReference.Wkid != sr.Wkid)
        ex = GeometryEngine.Project(ex, sr).Extent;


      this.MyMapView.Map.Layers.Add(wms);


      this.MyMapView.Map.InitialViewpoint = new Viewpoint(ex);


      await this.MyMapView.LayersLoadedAsync();
    }

although wms service in root layer has 2180 map still works in 4326

a. I think that you should allow to set expected spatialReference in wmsLayer, it should help in code sample 2

b. when you collect supported spatial refernces you should also take it from child layers, it should help in code sample 1

final efect is that I cant create map with wms layer, even though service return valid data in 2180 with feature layers in 2180

Do I miss sth, or is other workaround ?

Regards,

Robert

0 Kudos