Basemap change Event on api javascript or web app builder

1649
4
Jump to solution
04-03-2018 08:56 AM
GuillaumeArnaud
Occasional Contributor

Hi

I want to check if the basemap is change by another widget. I see that it exist an event on the esri map object but I didn't know how to connect it. 

I search one on webappbuilder but I don't find. Does it exist?

Thanks.

Guillaume Arnaud

0 Kudos
1 Solution

Accepted Solutions
GuillaumeArnaud
Occasional Contributor

Fine, 

I finally check "layer-add" event of map objet.

//Stocke les Basemaps dans une variable pour check le changement
this.bms = ls.getBasemapLayerObjects();

//Surveille l'évenement d'ajout de couche
this.map.on("layer-add", lang.hitch(this, function() {
   //Si le(s) basemaps son modifiées
   if (this.bms != ls.getBasemapLayerObjects()){
      //Stocke les Basemaps dans une variable pour check le changement
      this.bms = ls.getBasemapLayerObjects();
      //Parcours les Basemaps
      this.bms.forEach(lang.hitch(this, this.fct_Add_Basemap));
   }
}));

It works.

Thanks.

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

You can gain access to the map simply with "this.map" within your widget.

0 Kudos
GuillaumeArnaud
Occasional Contributor

Sure, I try this : 


dojo.connect(this.map, "onBasemapChange", lang.hitch(this, function(a) {
   console.log("connect");
   console.log(a);
}));

and this :


this.map.on("basemap-change", lang.hitch(this, function(a) {
   console.log("on");
   console.log(a);
}));

but it doesn't work. I don't know how to connect these 2 events because it's ok with other event like click or extent-change.

I change basemap with eBaseMapGallery or BaseMapGallery widget of WebAppBuilder

Thanks

0 Kudos
KenBuja
MVP Esteemed Contributor

You're correct. That event isn't fired when the Basemap Gallery is used. You have to listen to the Basemap Gallery's 'selection-change' event. https://community.esri.com/message/84178 This means you'd have to get the Gallery from the Basemap widget and listen for the change.

0 Kudos
GuillaumeArnaud
Occasional Contributor

Fine, 

I finally check "layer-add" event of map objet.

//Stocke les Basemaps dans une variable pour check le changement
this.bms = ls.getBasemapLayerObjects();

//Surveille l'évenement d'ajout de couche
this.map.on("layer-add", lang.hitch(this, function() {
   //Si le(s) basemaps son modifiées
   if (this.bms != ls.getBasemapLayerObjects()){
      //Stocke les Basemaps dans une variable pour check le changement
      this.bms = ls.getBasemapLayerObjects();
      //Parcours les Basemaps
      this.bms.forEach(lang.hitch(this, this.fct_Add_Basemap));
   }
}));

It works.

Thanks.

0 Kudos