Select to view content in your preferred language

LabelClass minScale and maxScale issue

722
4
02-15-2023 06:12 AM
KonstantinArbogastEBP
Emerging Contributor

Dear community,

I have a Feature Layer with two separate label classes. One that should be visible up to a scale of 1:10000, and the other one from that scale. So for one label class, I have added 10000 as maxScale and for the other as minScale.

I now expect to see Label Class 1 at 1:9999 and Label Class 2 at 1:10001. However, reality shows Label Class 1 from 1:10500 and Label Class 2 up to 1:13500. At around 1:11000, there are no labels at all. Below you can find a code example with a default scale of 1:11000 showing no labels at all. Zooming in will show "Class 1", zooming out will show "Class 2".

 

<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>ArcGIS Maps SDK for JavaScript Tutorials: Add a feature layer</title>
  <style>
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>
  <link rel="stylesheet" href="https://js.arcgis.com/4.25/esri/themes/light/main.css">
  <script src="https://js.arcgis.com/4.25/"></script>

  <script>
  require([
    "esri/config",
    "esri/Map",
    "esri/views/MapView",

    "esri/layers/FeatureLayer"

  ], function(esriConfig,Map, MapView, FeatureLayer) {

  esriConfig.apiKey = "<YOUR API KEY>";

  const map = new Map({
    basemap: ""
  });

  const view = new MapView({
    container: "viewDiv",
    map: map,
    center: [-118.80543,34.04000],
    scale: 11000
  });
    
    const labelClass1 = {  // autocasts as new LabelClass()
      symbol: {
        type: "text",  // autocasts as new TextSymbol()
        color: "white",
        haloColor: "blue",
        haloSize: 1,
        font: {  // autocast as new Font()
           family: "Ubuntu Mono",
           size: 14,
           weight: "bold"
         }
      },
      labelPlacement: "above-right",
      labelExpressionInfo: {
        expression: "'Class 1'"
      },
      maxScale: 0,
      minScale: 10000
    };
    const labelClass2 = {  // autocasts as new LabelClass()
      symbol: {
        type: "text",  // autocasts as new TextSymbol()
        color: "white",
        haloColor: "blue",
        haloSize: 1,
        font: {  // autocast as new Font()
           family: "Ubuntu Mono",
           size: 14,
           weight: "bold"
         }
      },
      labelPlacement: "above-right",
      labelExpressionInfo: {
        expression: "'Class 2'"
      },
      maxScale: 10000,
      minScale: 0
    };

  //Trails feature layer (lines)
  const trailheadsLayer = new FeatureLayer({
    url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0",
    labelingInfo: [labelClass1, labelClass2]
  });

  map.add(trailheadsLayer);

  });
</script>

</head>
<body>
  <div id="viewDiv"></div>
</body>
</html>​

 

Am I missing something? Or is this a bug?

4 Replies
Noah-Sager
Esri Regular Contributor

Hi @KonstantinArbogastEBP, thanks for posting your question here. I looked at your sample code, and I think there's an issue with the min/max scales. For example, for label class 2, the minscale is smaller than the maxscale. However, I'm not 100% sure if setting the scale to zero should be a factor or not.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-LabelClass.html#mi...

Here is an updated test-app, that appears to handle better in my testing.

updated test-app

https://codepen.io/noash/pen/JjaoKGY?editors=1000

See if this helps, otherwise, can you share an app that more clearly demonstrates the issue with min/max label scaling?

0 Kudos
KonstantinArbogastEBP
Emerging Contributor

Hi @Noah-Sager,

thank you for your input! At first it did look like the problem might be solved, but unfortunately it's just because the basemap forces certain zoom levels. If I remove the basemap, the problem remains.

Our application unfortunately needs custom zoom levels, and at 1:11000 or 1:12000, there are no labels, even though they should be there according to the LabelClasses

0 Kudos
Noah-Sager
Esri Regular Contributor

Hmm, in my test app, I see labels at both 1:11000 and 1:12000.

0 Kudos
KonstantinArbogastEBP
Emerging Contributor

While the basemap is active, you won't actually be at the scales 1:11000 and 1:12000, those are rounded to the next defined zoom level which is at around 1:18000. There it works.

Have you tried disabling the basemap and trying again with these scales?

0 Kudos