How to display WMS layers using ArcGIS Javascript API in MapView?

104
3
08-16-2022 07:10 AM
RehanChaudhary
Occasional Contributor

i am trying to display a WMS layer which is coming from a server. The WMS has multiple sublayers. I am using the sandbox for developing and testing the code for now. I am able to access the WMS on the SceneView but i cannot access it over the mapview. How can i configure my code to be able to view the map in 2D or in map view?

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-wms 

 

 

0 Kudos
3 Replies
ReneRubalcava
Frequent Contributor II

That sample sets the SpatialReference of the View, so when switching to the MapView, don't set the SpatialReference and let the view adopt the SR of the layer if it's the basemap layer.

0 Kudos
RehanChaudhary
Occasional Contributor

@ReneRubalcava  I dont want it to be the basemap layer. I want to add it over a basemap
layer

0 Kudos
UndralBatsukh
Esri Regular Contributor

This WMS service has WGS84 projection so it can only be displayed over basemaps that are in WGS84 or the MapView.spatialReference needs to be in wgs84. 

const layer = new WMSLayer({
  url: "https://ows.terrestris.de/osm/service",
  sublayers: [{
    name: "OSM-WMS"
  }]
});

const map = new Map({
  basemap: new Basemap({
    portalItem: {
      id: "02b1f120c3674bfe896ac81731be1739"
    }
  }),
  layers: [layer]
});

const view = new MapView({
  container: "viewDiv",
  map: map
});


Here are ArcGIS online basemaps that are in WGS84: https://www.arcgis.com/home/group.html?id=4c790318395940c18a16e8acd721de25&view=list&focus=maps-webm...