MapImageLayer - create dynamic map layers

This sample demonstrates how to create dynamic map layers in a MapImageLayer. A dynamic map layer allows you to alter properties of a map service layer on the fly including labels, renderers, visibility, and definition expressions. A dynamic layer is created as a sublayer to a MapImageLayer. This means that multiple dynamic layers can point to the same map service layer so you can essentially copy layers from the same data source to the MapImageLayer.

In the snippet below, three sublayers are added to a MapImageLayer. The id property of the sublayer does not refer to the layer ID of the service layer in this case. Rather it is determined by the user to uniquely identify the layer. The service layer's layer ID is referenced in the mapLayerId property of the source. The source type in this case is map-layer, which is inferred by the user or developer when they set the mapLayerId property. Notice how all three layers point to the same source layer ID, but alter the properties of that layer dynamically in different ways.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer",
  sublayers: [
    {
      id: 10,
      renderer: {
        type: "class-breaks"
        // set other renderer properties in this object
      },
      source: {
        mapLayerId: 1
      }
    },
    {
      id: 11,
      renderer: {
        type: "unique-value"
        // set other renderer properties in this object
      },
      definitionExpression: "POP07_SQMI >= 5100",
      source: {
        mapLayerId: 1
      }
    },
    {
      id: 12,
      renderer: {
        type: "simple"
        // set other renderer properties in this object
      },
      definitionExpression: "POP07_SQMI >= 5100",
      source: {
        mapLayerId: 1
      }
    }
  ]
});

To see the default renderers for layers in the map service, either remove the references to the renderers defined in this sample or view the MapImageLayer - Toggle sublayer visibility sample.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.