Vary point sizes by scale

This sample demonstrates how to generate a renderer that changes icon sizes in a point layer by view scale. The same workflow will also work for polyline layers, and is only supported for visualizations in a MapView.

When setting a static size of 10px to a marker symbol in a simple renderer on a point layer, the visualization will look good a larger (regional) scales, but will look too cluttered at small scales.

1
2
3
4
5
6
7
8
9
10
11
layer.renderer = new SimpleRenderer({
  symbol: {
    type: "simple-marker",
    color: [100, 100, 100],
    outline: {
      color: [255, 255, 255, 0.7],
      width: 0.5
    },
    size: "10px"
  }
});
10px icons clutter the view at a global extent...but look good at regional extents
scale-small-bad scale-large-good

On the other hand when setting a smaller icon size of 2px to a marker symbol in a simple renderer the visualization will look good at smaller scales, but may be too difficult to see at larger (regional) scales.

1
2
3
4
5
6
7
8
9
10
11
12
layer.renderer = new SimpleRenderer({
  label: "Weather Station",
  symbol: {
    type: "simple-marker",
    color: [100, 100, 100],
    outline: {
      color: [255, 255, 255, 0.7],
      width: 0.5
    },
    size: "2px"
  }
});
2px icons look good at a global extent...but can be too difficult to see at regional extents
scale-small-good scale-large-bad

The location.createRenderer() method (and other Smart Mapping renderer creator methods) has a sizeOptimizationEnabled parameter that when set to true generates a Size Variable that maps icon sizes to view scales.

1
2
3
4
5
6
7
8
9
10
11
12
13
// generates a new renderer with a scale-dependent
// size visual variable to vary icon size by scale
locationRendererCreator.createRenderer({
  layer: layer,
  view: view,
  sizeOptimizationEnabled: sizeOptimizationEnabled
}).then((rendererResponse) => {
  // the renderer contains a size variable with stops
  // mapping icon sizes to scale values
  layer.renderer = rendererResponse.renderer;
}).catch((error) => {
  console.error(error);
});

This variables is part of the output renderer, which when set on the input layer, gives a much better visual that works well across various scales.

Sizes are smaller at global extents...and larger at regional extents
location zoomed out location zoomed in

Once the variable is generated for the layer, you can clone it and use it in any other renderer set to that layer. This avoids unnecessary calls to Smart Mapping methods.

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
// icon sizes will linearly change
// depending on the view.scale
// This variable was generated using the previous snippet
const sizeVariable = {
  type: "sizeInfo",
  valueExpression: "$view.scale",
  stops: [
    {
      size: 7.5,
      value: 1155581.108577
    },
    {
      size: 6,
      value: 9244648.868618
    },
    {
      size: 3,
      value: 73957190.948944
    },
    {
      size: 1.5,
      value: 591657527.591555
    }
  ]
};

const renderer = layer.renderer.clone();
renderer.visualVariables.push(sizeVariable);
layer.renderer = renderer;

A word of caution

Keep in mind that generating renderers should be avoided in most applications because of the performance cost affecting the end user. As stated in the Smart Mapping guide topic, the Smart Mapping APIs were designed for two types of applications: data exploration apps and visualization authoring apps similar to ArcGIS Online. In all other cases, renderers should be saved to the layer or manually created using any of the renderer classes.

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

The developer dashboard has moved

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close