How to display WMS layer from Geoserver in ArcGIS Javascript API?

10084
2
Jump to solution
04-08-2015 08:07 AM
JasonCantrell
New Contributor III

I'm having trouble getting a WMS layer from my Geoserver to display in my ArcGIS test application. I'm just learning the ArcGIS Javascript API. For my test application, I started with the "WMS- resource info" sample  https://developers.arcgis.com/javascript/jssamples/layers_wmsresourceinfo.html

I basically replaced the WMS layer from the sample with my own:

var layer1 = new WMSLayerInfo({

name: 'testSave.0',

title: 'testSave.0'

});

var resourceInfo = {

extent: new Extent(-120.77027961360123, 35.79776317148635, -120.74876891832204, 35.812242893139256, {

  wkid: 3857

}),

layerInfos: [layer1]

};

var wmsLayer = new WMSLayer('http://localhost:8040/geoserver/reproj/wms', {

resourceInfo: resourceInfo,

visibleLayers: ['testSave.0']

});

map.addLayers([wmsLayer]);

When I run my application, I get the following error message when the WMS layer tries to load:

<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3.0" xsi:schemaLocation="http://www.opengis.net/ogc http://localhost:8040/geoserver/schemas/wms/1.3.0/exceptions_1_3_0.xsd">
<ServiceException code="InvalidCRS">
Error occurred decoding the espg code urn:x-ogc:def:crs:EPSG:102100 No code "EPSG:102100" from authority "European Petroleum Survey Group" found for object of type "IdentifiedObject".
</ServiceException>
</ServiceExceptionReport>

The problem seems to be related to the spatial reference of the ESRI basemap (ESRI:102100) and my Geoserver's inability to process that spatial reference. I've tried changing the spatial reference of my layer (to EPSG:3857, which I believe is the EPSG equivalent to ESRI:102100). I've also tried adding ESRI:102100 as a custom CRS to my Geoserver, but it added it as EPSG:102100 which is not valid. And both attempts resulted in the same error message.

Does anybody know how I could get this layer to display in my application?

Tags (2)
1 Solution

Accepted Solutions
JasonCantrell
New Contributor III

So I found the answer myself from a previously answered question (https://community.esri.com/message/380733). It seems that you have to override the spatialReferences array of the WMSLayer object. Adding this line right before adding the layer to the map seems to do the trick:

wmsLayer.spatialReferences[0] = 3857;

That worked for a layer with spatial reference set to EPSG:4326, and for another layer that I had used a tool to reproject to ESPG:3857. I couldn't find how to add a ESRI spatial reference to my Geoserver, so this seemed to best way to work around it.

View solution in original post

0 Kudos
2 Replies
JasonCantrell
New Contributor III

So I found the answer myself from a previously answered question (https://community.esri.com/message/380733). It seems that you have to override the spatialReferences array of the WMSLayer object. Adding this line right before adding the layer to the map seems to do the trick:

wmsLayer.spatialReferences[0] = 3857;

That worked for a layer with spatial reference set to EPSG:4326, and for another layer that I had used a tool to reproject to ESPG:3857. I couldn't find how to add a ESRI spatial reference to my Geoserver, so this seemed to best way to work around it.

0 Kudos
GeorgeReece_Jr_
New Contributor III

Thanks for the information. It will be useful going forward.