scale dependent visibility for graphics layer

2465
2
Jump to solution
05-03-2012 02:38 PM
danbecker
Occasional Contributor III
I filled a new graphics layer with text symbols; one for each point in a feature layer. The below function works fine and the labels are displayed correctly in their +50,+50 offset location, but how do I control the graphics layer visibility based on scale?

thanks!

function createLabels(){  var queryTask = new esri.tasks.QueryTask("REST url");  var query = new esri.tasks.Query();  query.returnGeometry = true;  query.outFields = ["site_code"];  query.where = "site_code LIKE '%'";  queryTask.execute(query, function(featureSet){   map.graphics.clear();   var lbls = new esri.layers.GraphicsLayer();   var font = new esri.symbol.Font("9px", esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_SMALLCAPS, esri.symbol.Font.WEIGHT_BOLDER);   for (var i=0, il=featureSet.features.length; i<il; i++) {    var x = featureSet.features.geometry.x + 50;    var y = featureSet.features.geometry.y + 50;    featureSet.features.geometry.x = x;    featureSet.features.geometry.y = y;    var graphic = featureSet.features.attributes.site_code;    var textSymbol = new esri.symbol.TextSymbol(graphic, font, new dojo.Color([0, 0, 0]));    var symb = featureSet.features;    symb.setSymbol(textSymbol);    lbls.add(symb);   };   map.addLayer(lbls);  }); }
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
There's no built-in scale dependency for graphics layers (but there is for feature layers).

To do this, you'll need to check the map's scale when the zoom level changes. You can connect to onZoomEnd, check the map's scale, and toggle your graphics layer's visibility with show or hide accordingly.

View solution in original post

0 Kudos
2 Replies
derekswingley1
Frequent Contributor
There's no built-in scale dependency for graphics layers (but there is for feature layers).

To do this, you'll need to check the map's scale when the zoom level changes. You can connect to onZoomEnd, check the map's scale, and toggle your graphics layer's visibility with show or hide accordingly.
0 Kudos
danbecker
Occasional Contributor III
works perfect...after setting var lbls globally.

dojo.connect(map, "onZoomEnd", checkScale);
function checkScale(extent, zoomFactor, anchor, level){
 if (level > 7 && level < 16){
  lbls.show()
 }
 else {
  lbls.hide()
 }
 //we can retreive the scale here, but level works just as well
 //var scale = esri.geometry.getScale(map)
}
0 Kudos