JSFiddle - React, Tailwind, and code Playground

by Alex Azuero

HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>MapImageLayer with SubLayers - 4.0</title>

  <link rel="stylesheet" href="https://js.arcgis.com/4.0/esri/css/main.css">
  <script src="https://js.arcgis.com/4.0/"></script>

  <script>
    require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/MapImageLayer",
        "dojo/on",
        "dojo/domReady!"
      ],
      function(
        Map, MapView, MapImageLayer, on
      ) {

        /*****************************************************************
         * Create a MapImageLayer instance pointing to a Map Service
         * containing data about US Cities, Counties, States and Highways.
         * Define sublayers with visibility for each layer in Map Service.
         *****************************************************************/
        var layer = new MapImageLayer({
          url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
          sublayers: [
          {
            id: 0,
            visible: true
          },
          {
            id: 1,
            visible: true
          },
          {
            id: 2,
            visible: true
          },
          {
            id: 3,
            visible: false
          }]
        });

        /*****************************************************************
         * Add the layer to a map
         *****************************************************************/
        var map = new Map({
          basemap: "dark-gray",
          layers: [layer]
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 4,
          center: [-99, 39]
        });

        /*****************************************************************
         * Wait for Layer to load and update the page to refelect which
         * layers are visible in the Map...