Basic Viewer - ArcGISDynamicMapServiceLayer where to place definition (newbie)

577
1
03-25-2013 11:02 AM
NewUser
New Contributor
I'm new to the JS api.  In looking at samples, I was wondering, where does one place the layer definitions and initial extent for a ArcGISDynamicMapServiceLayer in the 3.4 Basic Viewer template?  In older versions of the template, you just plopped them in the init() function in the index.html.  Do they go somewhere in the initMap function in the layout.js now?  Any direction or sample would be much appreciated.
0 Kudos
1 Reply
NewUser
New Contributor
I modified one line and added two in the createMap function in layout.js. It looks like it accomplishes setting a custom extent and adding a ArcGISDynamicMapServiceLayer in the 3.4 Basic Viewer template. Is this the right approach?

function createMap(webmapitem) {
 
    var mapDeferred = esri.arcgis.utils.createMap(webmapitem, "map", {
        mapOptions: {
            slider: configOptions.displaySlider,
            sliderStyle: 'small',
            wrapAround180: !configOptions.constrainmapextent,
            showAttribution: true,
            //set wraparound to false if the extent is limited.
            logo: !configOptions.customlogo.image //hide esri logo if custom logo is provided
        },
        ignorePopups: false,
        bingMapsKey: configOptions.bingmapskey
    });

    mapDeferred.addCallback(function (response) {
        //add webmap's description to details panel 
        if (configOptions.description === "") {
            if (response.itemInfo.item.description !== null) {
                configOptions.description = response.itemInfo.item.description;
            }
        }
        
        //initialExtent = response.map.extent;
        initialExtent = new esri.geometry.Extent({"xmin":-12345,"ymin":12345,"xmax":-12345,"ymax":12345,"spatialReference":{"wkid":102100}});
        
        if (configOptions.extent) {
            var extent = new esri.geometry.Extent(dojo.fromJson(configOptions.extent));
            initialExtent = extent;
        }

        configOptions.owner = response.itemInfo.item.owner;
        document.title = configOptions.title || response.itemInfo.item.title;
        //add a title
        if (configOptions.displaytitle === "true" || configOptions.displaytitle === true) {
            configOptions.title = configOptions.title || response.itemInfo.item.title;
            dojo.create("p", {
                id: 'webmapTitle',
                innerHTML: configOptions.title
            }, "header");
            dojo.style(dojo.byId("header"), "height", "38px");
        } else if (!configOptions.link1.url && !configOptions.link2.url) {
            //no title or links - hide header
            esri.hide(dojo.byId('header'));
            dojo.addClass(dojo.body(), 'embed');
            dojo.query("html").addClass("embed");
        }


        //get the popup click handler so we can disable it when measure tool is active
        clickHandler = response.clickEventHandle;
        clickListener = response.clickEventListener;
        map = response.map;

        //Constrain the extent of the map to the webmap's initial extent
        if (configOptions.constrainmapextent) {
            webmapExtent = response.map.extent.expand(1.5);
        }



        if (map.loaded) {
            initUI(response);
        } else {
            dojo.connect(map, "onLoad", function () {
                initUI(response);
            });
        }
        map.setExtent(initialExtent);
        var MapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://mywebsite.com/arcgis/rest/services/Blah/MapServer");
        map.addLayer(MapServiceLayer);
    });

    mapDeferred.addErrback(function (error) {
        alert(i18n.viewer.errors.createMap + " : " + dojo.toJson(error.message));
    });
}
0 Kudos