Select to view content in your preferred language

Layer switcher/selector

749
4
06-01-2014 11:03 PM
AlexVM
by
Emerging Contributor
I'm looking for some code to create a layer switcher or selector like the layer switcher widget from flex viewer.
I would need to use it with csv layer, so, I don't know if this is possible to be done.
Can a widget from flex viewer be used in flex api?

Thanks in advance!
Tags (2)
0 Kudos
4 Replies
BradleySnider
Deactivated User
Alex, most of our samples have a basemap switcher.  Is this what you are referring to?  If so download one of the samples from https://github.com/Esri/arcgis-samples-flex.  All, of our examples contain this code.  You will need to create a drop-down list with an array of the layer URLs, and create a TiledMapServiceLayer within the map.
0 Kudos
AlexVM
by
Emerging Contributor
Alex, most of our samples have a basemap switcher.  Is this what you are referring to?  If so download one of the samples from https://github.com/Esri/arcgis-samples-flex.  All, of our examples contain this code.  You will need to create a drop-down list with an array of the layer URLs, and create a TiledMapServiceLayer within the map.


Hi Brad, thanks for your answer. What i'm trying to find is a code example where you can select/deselect map available layers, similar to what you can find in arcgis flex viewer, but for layers, not for basemap.

I'm trying to find the sample code you said in github but no luck yet.

Thanks in advance!
0 Kudos
AlexVM
by
Emerging Contributor
Brad, this is what you were talking about?

<esri:Map id="myMap"
              level="4"
              load="myMap.centerAt(new MapPoint(-11713000, 4822000))">
        <esri:ArcGISTiledMapServiceLayer show="layerShowHandler(event)"
                                         url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
                                         visible="{bb.selectedIndex == 0}"/>
        <esri:ArcGISTiledMapServiceLayer show="layerShowHandler(event)"
                                         url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"
                                         visible="{bb.selectedIndex == 1}"/>
        <esri:ArcGISTiledMapServiceLayer show="layerShowHandler(event)"
                                         url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
                                         visible="{bb.selectedIndex == 2}"/>
        <esri:ArcGISTiledMapServiceLayer show="layerShowHandler(event)"
                                         url="http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer"
                                         visible="{bb.selectedIndex == 3}"/>
        <esri:ArcGISTiledMapServiceLayer show="layerShowHandler(event)"
                                         url="http://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer"
                                         visible="{bb.selectedIndex == 4}"/>
    </esri:Map>
    <s:ButtonBar id="bb"
                 right="5" top="5"
                 requireSelection="true">
        <s:dataProvider>
            <s:ArrayList>
                <fx:String>Streets</fx:String>
                <fx:String>Topographic</fx:String>
                <fx:String>Imagery</fx:String>
                <fx:String>Oceans</fx:String>
                <fx:String>National Geographic</fx:String>
            </s:ArrayList>
        </s:dataProvider>
    </s:ButtonBar>
</s:Application>



BUt i think this is for basemap only, not for layers. I would need to make the same but with a drop-down list and the list of layers (csv in this case), could you help me?

Thanks!
0 Kudos
EvelynHernandez
Frequent Contributor
Just change the url to a layer url mapserver/0, mapserver/1, etc
Also dont forget to put the visible=true in the layer.

Example: For dynamic layer
<esri:ArcGISDynamicMapServiceLayer url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer"/>


Example for Feature layer
<esri:FeatureLayer graphicAdd="featurelayer1_graphicAddHandler(event)"
                           outFields="[FIPS,POP2000]"
                           url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0"> </esri:FeatureLayer>


Source: https://developers.arcgis.com/flex/sample-code/using-samples.htm
0 Kudos