change basemap with a url

2389
4
Jump to solution
05-14-2020 11:08 PM
rsharma
Frequent Contributor

how to change basemap for a url. I want this layer to become my basemap layer on button click.

like for topo button i want this layer to come as basemap. LINZ/geotiffs (MapServer) 

How to change my code accordingly. Thanks in advance 


var topoBtn =domConstruct.toDom("<div class='map-button esri-component esri-widget--button esri-widget topo mapbtncolor' role='button' title='topo'>TOPO<span aria-hidden='true' role='presentation'></span></div>") ;
var satelliteBtn = domConstruct.toDom("<div class='map-button esri-component esri-widget--button esri-widget sat basmapcolor' id='satt' role='button' title='sattelite'>SATELLITE<span aria-hidden='true' role='presentation'></span></div>") ;

function setbasemap(basemap){
webmap.basemap = basemap;
}
topoBtn.addEventListener('click', function(){
setbasemap('topo');
});
satelliteBtn.addEventListener('click', function(){
setbasemap('satellite');

});

0 Kudos
1 Solution

Accepted Solutions
Egge-Jan_Pollé
MVP Regular Contributor
4 Replies
rsharma
Frequent Contributor

HI

I have created an online arcgis map with basemap as topographic and top layer is this LINZ/geotiffs (MapServer)  I cannot able to use this layer directly as basemap in my app it disturb my functionality so i use topographic layer as basmap for this webmap ,

Furthermore, i have done this on click of button by dynamically changing portalItem id on click, but for this i have to refresh my page for toppo button.

      var webmap = new WebMap({
          portalItem: {
            // autocasts as new PortalItem()
            id: "<?=$map_id?>"
          }
        }); //End WebMap

Is their any other way, i can do it smoothly? Dynamically changing webmap, or any other way???

Hoping for positive response from the community.

Please don't send link of Basemap | ArcGIS API for JavaScript 4.15 

I have already read it, but don't know how to practically implment it.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Egge-Jan_Pollé
MVP Regular Contributor

Hi rajni sharma,

What do you think about this one?

ArcGIS JavaScript with New Zealand data - LINZ Basemapgallery 

BR,

Egge-Jan

rsharma
Frequent Contributor

       // Basemaps Eagle Technology New Zealand
      let LINZ_Topographic_Eagle_NZ = new Basemap({portalItem: {id: "<?=$map_id?>"}}); //NZ - LINZ Topographic

 // Click event on Topo Button
          topoBtn.addEventListener('click', function(){
            setbasemap(LINZ_Topographic_Eagle_NZ);

          });