2

I am using ESRI Javascript 3.7 framework to develop a map application, in it I am trying to display labels created using LabelLayer at certain scales only, say from 1:1 to 1:500 scale only.

How can I achieve this?

I played a little with ScaleDependentRenderer but it results in 2 firebug exceptions. Not sure if the ScaleDependentRenderer is the right answer or not.

var occupancyLabelLayer = new esri.layers.LabelLayer({ id: "labels" });
// add the label layer to the map
map.addLayer(occupancyLabelLayer);

var labelField = "FLOOR";
// create a text symbol to define the style of labels

var spaceLabelColor = new dojo.Color("red");
var spaceOccupancyLabel = new esri.symbol.TextSymbol().setColor(spaceLabelColor);
//spaceOccupancyLabel.font.setSize("14pt");
spaceOccupancyLabel.font.setFamily("arial");
var spaceOccupancyLabelRenderer = new esri.renderer.SimpleRenderer(spaceOccupancyLabel);

var spaceLabelScaleDependentRenderer = new ScaleDependentRenderer({
    rendererInfos: [{
        renderer: spaceOccupancyLabelRenderer,
        minScale: 500,
        maxScale: 1
    }]
});

occupancyLabelLayer.addFeatureLayer(featureLayer, spaceLabelScaleDependentRenderer, "${" + labelField + "}");

Firebug Exceptions:

1)exception in animation handler for: onEnd
http://js.arcgis.com/3.7/ (line 45)
2)TypeError: b is undefined
http://js.arcgis.com/3.7/js/esri/layers/LabelLayer.js    Line 21

1 Answer 1

2

All layers in the API support minScale and maxScale (and all tiled layers have minZoom and maxZoom) constructor options. The label layer API ref should document this, I'll make sure we get that updated.

Instead of using a scale dependent renderer, use minScale and maxScale to specify your scales (note that since we're talking scales, max scale is the smaller number as that represents a large scale where more area is visible). Here's an example (zoom in to see labels, if you're on a small screen you might need to zoom in twice): http://jsbin.com/aCicEhe

Relevant code:

var labels = new LabelLayer({ 
  id: "labels",
  minScale: 10000000,
  maxScale: 0
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.