Select to view content in your preferred language

Hide individual graphics

3990
8
11-23-2010 07:09 AM
MatthewPilgrim
New Contributor III
Hi,

Is it possible to hide individual graphics after they have been added to a graphics layer.  I can't see a visibility property and this doesn't work:

searchgraphicsLayer.Graphics[0].Attributes.Add("Visibility", Visibility.Collapsed);

What are the alternatives?

Thanks in advance, Matt
0 Kudos
8 Replies
AliMirzabeigi
New Contributor
Unfortunately individual Graphic elements in a GraphicsLayer do not have a public Visibility property and you cannot change their visibility however; you could define an invisible symbology for your Graphic symbols and set it to the desired Graphic object. For example, if you have a SimpleMarkerSymbol you could define a marker symbol resource in your user control having either its Color set to Transparent or its Size set to zero.
Hope this helps.
0 Kudos
dotMorten_esri
Esri Notable Contributor
or just do this:
myGraphic.Symbol = null;
0 Kudos
lanceweaver
New Contributor III

setting the symbol to null does not seem to dynamically hide the symbol. You'd still have to remove and add the graphic to the map for it to take effect?

0 Kudos
lanceweaver
New Contributor III

Here's an example of the only thing I could get to work.... and even then, it rearranges the draw order of the graphics... which I couldn't figure out a way to prohibit.

I'm using a slider to hide or peal through graphics.

var searchslider = new RangeSlider({
name: "slider",
value: [ 0, 500000 ],
minimum: 0,
maximum: 500000,
intermediateChanges: true,
//discreteValues:100, //The number of possible discrete slider values (make increments of 10) no worky
skip:1000,
showButtons: false, // false by default?
style: "width:300px;",

onChange: function(values){
console.log( values[0]+", "+values[1] );
var min = addCommas( values[0].toFixed(0) ); // cutt off all decimals
var max = addCommas( values[1].toFixed(0) );
$("#rngMin").html("1:"+min);
$("#rngMax").html("1:"+max);
//console.log(graphicsLayer.graphics);
console.log(graphicsLayer.graphics.length);
if (graphicsLayer.graphics.length > 0){
var tempFeatures = graphicsLayer.graphics.items;
dojo.forEach(tempFeatures, function(g){
console.log(g);
if (g.visible = true && g.attributes.scale_1 > values[1]){
//console.log("true!");
graphicsLayer.remove(g);
var hiddenGraphic = new Graphic({
geometry: g.geometry,
attributes: g.attributes,
popupTemplate: template,
symbol: hiddensymbol,
visible: false
});
graphicsLayer.add(hiddenGraphic);
} else if (g.visible == false && g.attributes.scale_1 < values[1]){
graphicsLayer.remove(g);
var visibleGraphic = new Graphic({
geometry: g.geometry,
attributes: g.attributes,
popupTemplate: template,
symbol: fillSymbol,
visible: true
});
graphicsLayer.add(visibleGraphic);
}
}); //end .each
} // end if
} // end onchange()
}, "mapbib-slider");

0 Kudos
MatthewPilgrim
New Contributor III
Thanks,

The graphic contains text that I don't want to loose - as it will be made visible again at some point.  So I have put these graphics on anew layer and turn that layer on/off.

Matt
0 Kudos
dotMorten_esri
Esri Notable Contributor
Setting the symbol to null doesn't change the attributes of the graphic, so I'm not sure why you think that would make it lose its "text" (I assume this is stored in the attribute).
You could also as you mention move the graphic out of the layer. There's no need to put it in a layer that is turned off though. A private list of "hidden" graphics should do the job.
0 Kudos
MatthewPilgrim
New Contributor III
Thanks for the response.  You are of course correct about the text not being lost.  In fact the user picks the colour/size of the text as its added so this is what would be lost by setting the symbol to null.  The second layer approach is working fine.

Matt
0 Kudos
BjørnarSundsbø
Occasional Contributor
If you define a ControlTemplate for the symbol (such as in use with a Renderer), you can try to bind the topmost control in the template to your Visible attribute. I haven't tried it myself, but it should work. At least I hope it does, as I would like to do the same myself soon.
0 Kudos