How to turn visibility on/off using js onclick event:
layerName.setVisibility(false);
Can you explain a bit more what you are looking for? Would one of these sample help?
Toggle layer visibility | ArcGIS API for JavaScript
Dynamically create layer list | ArcGIS API for JavaScript
are you building a custom js method or are you using an open source method?
second map layer. if i change "false" to "true" (or "hide" to "show") by typing it in to code, i got what i expected, but i need to make button on map, that after onClick event gona change layer visibility on/off.
var ortofotokarte = new Tiled("http://127.0.0.1/MapServer");
map.addLayer(ortofotokarte);
ortofotokarte.setVisibility(false);
//ortofotokarte.hide();
It looks like a timing issue. You are trying to set the visibility before the layer is loaded. Try setting the visiibility property or setting the visibility after the load event.
var ortofotokarte = new Tiled("http://127.0.0.1/MapServer,{visible:false});
or
ortofotokarte.on('load',function(){
});
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.