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.46/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.46/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.46/"></script>
<script>
var map;
require(["esri/map", "esri/layers/WMSLayer", "esri/config", "dojo/domReady!"],
function(Map, WMSLayer, esriConfig) {
var corsEnabledServers = esriConfig.defaults.io.corsEnabledServers;
corsEnabledServers.push("sampleserver6.arcgisonline.com");
map = new Map("map", {
basemap: "streets-vector",
center: [-98, 37],
zoom: 2
});
var wmsLayer = new WMSLayer("https://sampleserver6.arcgisonline.com/arcgis/services/USA/MapServer/WMSServer", {
format: "png",
visibleLayers: [1, 2]
});
map.addLayer(wmsLayer);
});
</script>
</head>
<body>
<div id="map">
</div>
</body>
</html>