1

I am trying to get the current basemap after user selection, in the sandbox provided by ArcGIS, sandbox link.

I added a piece of code:

basemapGallery.on("selection-change", function() { alert("Here!"); });

It doesn't seem to work anymore. "Here" wasn't triggered when I switched basemaps. And no error messages show up.

Perhaps something changed from ArcGIS for Javasript 3.X to 4, since all answers I found online are working well on 3.20 or before. But no answer on version 4.4 was given.

Also it would be better to teach me how to make it work combined with the expand widget. sandbox link.

3
  • Welcome to GIS SE. Please take the gis.stackexchange.com/tour Tour. What do you mean it doesn't work anymore? Did you get an error message? Commented Jul 28, 2017 at 15:15
  • I speculate that the event name has changed from 'selection-change' to something else. However, the BasemapGallery documentation doesn't list its events.
    – Emily
    Commented Jul 28, 2017 at 15:53
  • Yeah I tried to look at its events but apparently that tag has not been added to the documentation page yet. Commented Jul 28, 2017 at 16:10

1 Answer 1

5

I got an email response from an Esri representative. Copied below:

"BasemapGallery doesn't have any events. If you would like to execute custom behavior whenever the active basemap changes, or the source of the BasemapGallery changes, then this can be handled by setting up a watch on the appropriate property.

https://developers.arcgis.com/javascript/latest/guide/working-with-props/index.html#watching-properties"

Following the provided example, what you should be using is:

var handle = basemapGallery.watch('activeBasemap', function(newValue, oldValue, property, object) {
   alert("Here!");
   console.log("New value: ", newValue,      // The new value of the property
               "<br>Old value: ", oldValue,  // The previous value of the changed property
               "<br>Watched property: ", property,  // In this example this value will always be "basemap.title"
               "<br>Watched object: ", object);     // In this example this value will always be the map object
  });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.