Create web map from JSON

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:esri="http://www.esri.com/2008/ags"
               initialize="application_initializeHandler(event)">
    <!--
    Description:
    This sample demonstrates how to use WebMapUtil.createMapByItem to create
    a map using an object that is a by value representation of the webmap.
    This is an alternative to other samples in this folder that create a map
    using the webmap id from ArcGIS.com.

    Documentation:
    For more information, see the API documentation.
    https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/events/WebMapEvent.html
    https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/portal/WebMapUtil.html#createMapByItem()
    -->

    <fx:Script>
        <![CDATA[
            import com.esri.ags.Map;
            import com.esri.ags.events.WebMapEvent;
            import com.esri.ags.layers.ArcGISTiledMapServiceLayer;

            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            import mx.rpc.events.FaultEvent;

            private var item:Object;
            private var itemData:Object;

            protected function application_initializeHandler(event:FlexEvent):void
            {
                item = {
                        "extent": [
                        [
                        -139.4916,
                        10.7191
                        ],
                        [
                        -52.392,
                        59.5199
                        ]
                        ],
                        "snippet": "This map shows the Soil Survey Geographic (SSURGO) by the United States Department of Agriculture's Natural Resources Conservation Service.",
                        "title": "Soil Survey Map of USA"
                    };

                itemData = {
                        "baseMap": {
                            "baseMapLayers": [
                            {
                                "opacity": 1,
                                "url": "http://services.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer",
                                "visibility": true
                            },
                            {
                                "isReference": true,
                                "opacity": 1,
                                "url": "http://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Reference_Overlay/MapServer",
                                "visibility": true
                            }
                            ],
                            "title": "World_Terrain_Base"
                        },
                        "operationalLayers": [
                        {
                            "itemId": "204d94c9b1374de9a21574c9efa31164",
                            "opacity": 0.75,
                            "title": "Soil Survey Map",
                            "url": "http://server.arcgisonline.com/ArcGIS/rest/services/Specialty/Soil_Survey_Map/MapServer",
                            "visibility": true
                        }
                        ],
                        "version": "1.1"
                    };

                webMapUtil.createMapByItem(item, itemData);
            }

            protected function webMapUtil_createMapByItemCompleteHandler(event:WebMapEvent):void
            {
                /*
                 * event.item (the web map item)
                 * event.itemData (the actual information that makes up the web map [ baseMap, operationalLayers, version, etc])
                 *
                 * var webMapItem:Object = event.item;
                 * webMapItem.id (web map id)
                 * webMapItem.owner (Who owns the document on ArcGIS.com)
                 * webMapItem.snippet (web map summary)
                 * webMapItem.title (web map title)
                 */
                webMapTitle.text = event.item.title;
                webMapDescription.text = event.item.snippet;
                var map:Map = event.map;
                mapContainer.addElement(map);
                var legendLayer:ArcGISTiledMapServiceLayer = ArrayCollection(map.layers).getItemAt(1) as ArcGISTiledMapServiceLayer;
                webMapLegend.layers = [ legendLayer ];
                webMapLegend.map = map;
            }

            protected function esriService_faultHandler(event:FaultEvent):void
            {
                Alert.show(event.fault.faultString);
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <esri:WebMapUtil id="webMapUtil"
                         createMapByItemComplete="webMapUtil_createMapByItemCompleteHandler(event)"
                         fault="esriService_faultHandler(event)"/>
    </fx:Declarations>

    <s:controlBarLayout>
        <s:VerticalLayout gap="10"
                          paddingBottom="7"
                          paddingLeft="10"
                          paddingRight="10"
                          paddingTop="7"/>
    </s:controlBarLayout>
    <s:controlBarContent>
        <s:RichText width="100%">
            This sample demonstrates how to use WebMapUtil.createMapByItem to create
            a map using an object that is a by value representation of the webmap.
            This is an alternative to other samples in this folder that create a map
            using the webmap id from ArcGIS.com.
        </s:RichText>
        <s:Label id="webMapTitle" fontSize="16"/>
        <s:Label id="webMapDescription"
                 width="100%"
                 paddingLeft="7"/>
    </s:controlBarContent>


    <s:HGroup width="100%" height="100%"
              gap="0">
        <s:Group id="mapContainer"
                 width="70%" height="100%"/>
        <esri:Legend id="webMapLegend"
                     width="30%" height="100%"/>
    </s:HGroup>
</s:Application>