Suffii
Suffii

Reputation: 5784

How to Update Basemap Of ArcGIS API for JS Using jQuery

Can some one please let me know if it is possible to update ArcGIS API Basemap by using jQuery

Here is what I have tried

HTML

<select id="base-map-options">
   <option value="0">Imagery</option>
   <option value="1">Topographic With Lable</option>
</select>

   var map;
   var basemap = ['topo','streets','imagarey']
        require([
        "esri/map",
        "esri/layers/ArcGISDynamicMapServiceLayer",
        "dojo/domReady!"
        ], function(Map) {
                            map = new Map("mapDiv", {
                            center: [-126.687482, 54.793577],
                            zoom: 5,
                            basemap: basemap[0]
      });

   $("#base-map-options").on("change", function () {
       basemap[$('option:selected').val()];
    });
});

as you can see I am trying to update selected index in basemap[] through

   $("#base-map-options").on("change", function () {
       basemap[$('option:selected').val()];
    }); 

but I don't know how to bind this to basemap property of the map object?

Upvotes: 0

Views: 301

Answers (1)

jimSampica
jimSampica

Reputation: 12410

Use the setBasemap function available through the Map class.

$("#base-map-options").on("change", function () {
    map.setBasemap(basemap[$('option:selected').val()]);
}); 

Upvotes: 1

Related Questions