+ Reply to Thread
Results 1 to 3 of 3

Thread: scale dependent visibility for graphics layer

  1. #1
    dan becker
    Join Date
    Apr 2010
    Posts
    182
    Points
    21
    Answers Provided
    3


    0

    Default scale dependent visibility for graphics layer

    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!

    Code:
    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[i].geometry.x + 50;
    			var y = featureSet.features[i].geometry.y + 50;
    			featureSet.features[i].geometry.x = x;
    			featureSet.features[i].geometry.y = y;
    			var graphic = featureSet.features[i].attributes.site_code;
    			var textSymbol = new esri.symbol.TextSymbol(graphic, font, new dojo.Color([0, 0, 0]));
    			var symb = featureSet.features[i];
    			symb.setSymbol(textSymbol);
    			lbls.add(symb);
    		};
    		map.addLayer(lbls);
    	});
    }

  2. #2
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    893
    Answers Provided
    165


    0
    This post is marked as the answer

    Default Re: scale dependent visibility for graphics layer

    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.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  3. #3
    dan becker
    Join Date
    Apr 2010
    Posts
    182
    Points
    21
    Answers Provided
    3


    0

    Default Re: scale dependent visibility for graphics layer

    works perfect...after setting var lbls globally.

    Code:
    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)
    }

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts