Adding a WMSLayer using ESRI JavaScript 3.10 API

967
3
09-03-2014 06:34 AM
MatthewTucknott
New Contributor III

Hi,

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">


<html>

  <head>

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

   <title>Simple Map</title>

  <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">

  <script src="http://js.arcgis.com/3.10/"></script>

   <script type="text/javascript">

    alert ("-1");
   dojo.require("esri.map");

  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");

  myMap.addLayer(wmsLayer);

  }

alert ("0");
  dojo.addOnLoad(init);
alert ("1");

  
</script>


 
</head>


 
<body class="tundra">

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


 
</body>


</html>

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

Tuckers

0 Kudos
3 Replies
RiyasDeen
Occasional Contributor III

Hi Matthew,

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

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

0 Kudos
KenBuja
MVP Esteemed 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.

MatthewTucknott
New Contributor III

Hi,

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