Hide Table of Contents
View WMS layer sample in sandbox
WMS layer

Description

This sample shows how to work with an OGC Web Map Service (WMS). When WMSLayers are added to the map only the specified layers are displayed.

Code

<!DOCTYPE html>
<html> 
  <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
   
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Map with WMS</title> 

    <link rel="stylesheet" href="https://js.arcgis.com/3.29/dijit/themes/claro/claro.css"> 
    <link rel="stylesheet" href="https://js.arcgis.com/3.29/esri/css/esri.css">
    <style>
      html, body, #map {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
      body {
        background-color: #FFF;
        overflow: hidden;
        font-family: "Trebuchet MS";
      }
    </style>
    <script src="https://js.arcgis.com/3.29/"></script> 
    
    <script> 
      var map;

      require(["esri/map", "esri/layers/WMSLayer", "esri/config", "dojo/domReady!"],
        function(Map, WMSLayer, esriConfig) {

          esriConfig.defaults.io.proxyUrl = "/proxy/";
          
          map = new Map("map", {
            basemap: "streets",
            center: [-98, 37],
            zoom: 5
          });

          var wmsLayer = new WMSLayer("https://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer", {
            format: "png",
            visibleLayers: [2]
          });
          
          map.addLayer(wmsLayer);
      });
    </script> 
  </head> 
  
  <body> 
      <div id="map">
      </div>
  </body> 
</html>
 
          
Show Modal