WMSLayer Not Working : Failed to load layer/Cannot read property 'indexOf' of undefined

1378
1
12-11-2019 02:04 AM
JerryChen
New Contributor III

I'm working with JavaScript API 4.12.

I tried using the url in Sample - WMSLayer which should work fine but instead giving me the error '[esri.layers.WMSLayer] #load() Failed to load layer (title: 'WMS Layer', id: '16ef4567998-layer-4') TypeError: Cannot read property 'indexOf' of undefined'.

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

Thought it was a spatial reference relevant error, I've tried setting 'wmsLayer.spatialReference = 102100;' but still got the same error. After googling WMS url usage, I tried putting the url with the complete parameters and got a 'XML Parse error'.

let wmsLayer = new WMSLayer({
title: "WMS Layer",
url: "https://neo.sci.gsfc.nasa.gov/wms/wms?version=1.3.0&request=GetMap&layers=MOD14A1_M_FIRE&style=rgb&crs=CRS:84&bbox=-180,-90,180,90&width=720&height=360&format=image/png"
});

var basemap = new Basemap({
baseLayers: [wmsLayer]
});

var map = new Map({
basemap: basemap,
layers: [gridLayer, forceSymbolLayer, measurementLayer, sketchLayer]
});

I'm new to the GIS development, and really confused about the WMS format to set as the url, especially when the sample from official website doesn't work.

0 Kudos
1 Reply
AnneFitz
Esri Regular Contributor

Hi Jerry,

Are you using the same sublayer as the sample in your app or a different sublayer? Currently, I cannot reproduce your error. If you could share a little more information about your app, I might be able to help you figure out the problem. 


Thanks,

Anne

0 Kudos