Legend widget for tiled map service

765
1
Jump to solution
09-12-2016 09:10 AM
JohnFell
Occasional Contributor III

Does anyone have an example for the legend widget using a tiled map service?

When I try to load the legend using our tiled map service I don't see the map service initially nor does the legend display. Please help. See code below.

<!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>Tiled map service</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.17/esri/css/esri.css">
    <style>
      html, body, #map{
        height: 100%;
        width: 100%;
        padding: 0;
        margin: 0;
      }
      #info{
        top: 0px;
        right: 0px;
        position: absolute;
        z-index: 99;
        opacity: 0.9;
        background-color: whitesmoke;
        border-bottom-left-radius: 8px;
        padding: 0px 0px 0px 10px;
      }
    </style>

    <script src="https://js.arcgis.com/3.17/"></script>
    <script>
      var map;

      require(["esri/map", "esri/layers/ArcGISTiledMapServiceLayer", "dojo/domReady!", "esri/dijit/Legend"],
        function(Map, ArcGISTiledMapServiceLayer, Legend) {
          map = new Map("map", [{center: [ -96.851, 32.807 ]}]);
          


          var tiled = new ArcGISTiledMapServiceLayer("https://maps.dcad.org/prdwa/rest/services/Property/PropMap/MapServer");          
          map.addLayer(tiled);
          
          map.on("load", function(evt){
            var legend = new Legend({
              map: map,
            }, "legendDiv");
              
            legend.startup(); 
          });
        }
      );
    </script>
  </head>
  <body>
    <div id="map"></div>
    <div id="info"><div id="legendDiv"></div></div>
  </body>
</html>
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

The arguments in your function don't match the modules in the require statement. If you change it to this, it works properly.

require(["esri/map", "esri/layers/ArcGISTiledMapServiceLayer", "esri/dijit/Legend", "dojo/domReady!"],
    function(Map, ArcGISTiledMapServiceLayer, Legend) {‍‍

View solution in original post

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

The arguments in your function don't match the modules in the require statement. If you change it to this, it works properly.

require(["esri/map", "esri/layers/ArcGISTiledMapServiceLayer", "esri/dijit/Legend", "dojo/domReady!"],
    function(Map, ArcGISTiledMapServiceLayer, Legend) {‍‍
0 Kudos