AnsweredAssumed Answered

Add basemap dynamically

Question asked by bforbhavin on May 1, 2015
Latest reply on May 1, 2015 by csgeosol1

I want to give users flexibility to add basemap layer after their dynamic service layer is loaded on the map. See following example, I have highlighted code and what works/doesn't work.


I guess basemap must be added as first layer only. basemap's layer id will be always layer0? Is there any workaround if the basemap is not added as a first layer and want to add it after the map is loaded with dynamic service layer?


<!DOCTYPE html>



    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">

    <title>Feature Layer Only Map</title>

    <link rel="stylesheet" href="">


      html, body, #map {

        height: 100%;

        width: 100%;

        margin: 0;

        padding: 0;



    <script src=""></script>









      ], function(






        ) {

          var bounds = new Extent({









          var map = new Map("map", {

            extent: bounds




          var url = "";



          var template = new InfoTemplate("World Regions", "Region: ${REGION}");



          var fl = new FeatureLayer(url, {

            id: "world-regions",

            infoTemplate: template


          //map.setBasemap('streets'); //it works here


         map.setBasemap('streets'); //it doesn't work here






    <div id="map"></div>