Adding a WMSLayer using ESRI JavaScript 3.10 API

09-03-2014 06:34 AM
New Contributor III


I have a very simple question. I have a WMS serving a British National Grid Map. I onnly need that layer to be displayed. I have so far failed to get this to display.

The code I am using is shown below




   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

   <title>Simple Map</title>

  <link rel="stylesheet" href="">

  <script src=""></script>

   <script type="text/javascript">

    alert ("-1");

  function init() {
  var myMap = new esri.Map("mapDiv");
  //note that if you do not have public Internet access then you will need to point this url to your own locally accessible cached service.

  var wmsLayer = new esri.layers.WMSLayer("http://localhost:6080/arcgis/services/test/MapServer/WMSServer");



alert ("0");
alert ("1");



<body class="tundra">

   <div id="mapDiv" style="width:900px; height:600px; border:1px solid #000;"></div>



I am new to the ESRI JavaScript API so would appreciate any help. BTW I can view the map in GeoExplorer so I know the service is working.

Many thanks


0 Kudos
3 Replies
Regular Contributor

Hi Matthew,

You may want to require "esri.layers.WMSLayer" as well.

Add, dojo.require("esri.layers.WMSLayer"); after dojo.require("");

0 Kudos
MVP Honored Contributor

In the WMSLayer documentation‌, it mentions that the default behavior requires the use of a proxy. However, of the two samples that use WMSLayer, one uses a proxy and one gets around the need for a proxy with the use of resourceInfo object.

If you're new to the Javascript API, you should review how to write your code using AMD (or Asynchronous Module Definition) instead of the legacy style that your code is currently using.

New Contributor III


Thanks for replying. I contacted support...and I still need to try this

Judging from the bit of code you included, you are referencing the WMS service correctly, but you are not specifying any layers to be displayed. 

If you have a look at the following link, it stipulates that “When WMSLayers are added to the map only the specified layers are displayed.

So hope this works.

0 Kudos