Esri / storymap-series

The Story Map Series lets you present a series of maps via tabs, numbered bullets, or a side accordion.
Apache License 2.0
63 stars 59 forks source link

Web Map Change Event? #49

Open pmacMaps opened 4 years ago

pmacMaps commented 4 years ago

I am working on developing a JavaScript solution to add the alt attribute to images in map popups. Using the events listed in this repo's readme, I cannot get consistent results when changing between webmaps. I have tried the code in different topic.subscribe sections within the custom-scripts.js file.

Is there an event that fires when the webmaps change? I'll provide my sample code below. Any help is greatly appreciated:

let webmap = app.map;

webmap.on('click', function() {

        // only execute code if a popup is displayed on click
        if (webmap.infoWindow.isShowing) {

            // img elements within the feature popup
            let popupImage = document.querySelectorAll('div.image > img')[0];

            if (typeof popupImage !== 'undefined') {  
               // popup title - bridge name
               let bridgeNameElement = document.querySelectorAll('div.esriViewPopup > div.mainSection > div.header')[0].innerHTML;

                // add alt attribute using bridge's name
               popupImage.setAttribute('alt', bridgeNameElement);// || 'some string'
           }          

       }

});