Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE 11 Issues with Custom Code #93

Open
pmacMaps opened this issue Oct 5, 2018 · 0 comments
Open

IE 11 Issues with Custom Code #93

pmacMaps opened this issue Oct 5, 2018 · 0 comments

Comments

@pmacMaps
Copy link

pmacMaps commented Oct 5, 2018

I'm working on upgrading a v1.4.9 to v2.7.0 app. The development site is https://gis.ccpa.net/labs/caedc-idm/. I have some custom code that creates a legend. The app is working on Google Chrome, but not Internet Explorer. The issue appears to be related to some custom code. Even after running the code through https://babeljs.io/repl, I am still getting the following error in IE: "SCRIPT1014: Invalid character; File: init.js, Line: 28, Column: 392".

When I comment out the code, the app loads in IE and Chrome (but without creating the legend).

The ES6 code is at https://github.com/pmacMaps/shortlist-storytelling-template-js/blob/master/app/custom-scripts.js#L7.

Here is the transpiled code:

require(["esri/request"], function(esriRequest) {
            // function to get legend info in json format
            function requestLegendJson(url) {
                // request object
                const requestHandle = esriRequest({
                    url: url,
                    content: {f: "json"},
                    handleAs: 'json',
                    callbackParamName: 'callback'
                });           
                // make request
                requestHandle.then(
                    function(response) {
                        // https://babeljs.io/repl was used to convert ES6 code at 
                        // https://github.com/pmacMaps/shortlist-storytelling-template-js/blob/master/app/custom-scripts.js
                        // into IE compatible code
                        // legend container element
                        const legendElement = $('#customLegend');                     
                        // layers in response                        
                        const layers = response.layers;
                        var _iteratorNormalCompletion = true;
                        var _didIteratorError = false;
                        var _iteratorError = undefined;

                        try {
                          for (var _iterator = layers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
                            var item = _step.value;

                            // default layer name
                            var layerName = item.layerName;
                            // loop through legend properties
                            var _iteratorNormalCompletion2 = true;
                            var _didIteratorError2 = false;
                            var _iteratorError2 = undefined;

                            try {
                              for (var _iterator2 = item.legend[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
                                var element = _step2.value;

                                // open legend list element
                                var legendContent = "<ul>";
                                // if the label element is empty, we'll use item.layerName as the name of the legend element
                                // if it is not, we'll use the label property of the legeng as the name for the legend element
                                if (element.label === " " || element.label === "") {
                                  legendContent += "<li>" + layerName + "</li>";
                                } else {
                                  legendContent += "<li>" + element.label + "</li>";
                                }
                                // create image element
                                legendContent += "<li><img height=" + element.height + " width=" + element.width + " src=\"data:" + element.contentType + ";base64," + element.imageData + "\" alt=\"legend icon representing " + layerName + "\" /></li>"; // close list element
                                legendContent += "</ul>";
                                // append legend item to legend
                                legendElement.append(legendContent);
                              } // end for element of item.legend                                             
                            } catch (err) {
                              _didIteratorError2 = true;
                              _iteratorError2 = err;
                            } finally {
                              try {
                                if (!_iteratorNormalCompletion2 && _iterator2.return) {
                                  _iterator2.return();
                                }
                              } finally {
                                if (_didIteratorError2) {
                                  throw _iteratorError2;
                                }
                              }
                            }
                          } // end for item of layers
                        } catch (err) {
                          _didIteratorError = true;
                          _iteratorError = err;
                        } finally {
                          try {
                            if (!_iteratorNormalCompletion && _iterator.return) {
                              _iterator.return();
                            }
                          } finally {
                            if (_didIteratorError) {
                              throw _iteratorError;
                            }
                          }
                        }
                                
                }, // end function(response)
                    function(error) {
                        console.warn(`Error creating legend element for url ${url}`);
                        console.warn("Error: ", error.message);
                        // feel free to update error reporting code
                    });
            } // end requestLegendJson(url)
            
            // Map Service Legend Urls
            const municipalityLegendUrl = 'https://gis.ccpa.net/arcgiswebadaptor/rest/services/ArcGIS_Online/MunicipalBoundaries/MapServer/legend';
            const landTrailsLegendUrl = 'https://gis.ccpa.net/arcgiswebadaptor/rest/services/ArcGIS_Online/LandTrailsData/MapServer/legend';
            const waterTrailsLegendUrl = 'https://gis.ccpa.net/arcgiswebadaptor/rest/services/ArcGIS_Online/WaterTrailsData/MapServer/legend';
            const parksLegendUrl = 'https://gis.ccpa.net/arcgiswebadaptor/rest/services/ArcGIS_Online/ParksData/MapServer/legend';           
            
            // call functions to get legend JSON and construct legend elements  
            requestLegendJson(municipalityLegendUrl);
            requestLegendJson(landTrailsLegendUrl);
            requestLegendJson(waterTrailsLegendUrl);
            requestLegendJson(parksLegendUrl);           
        }); // end require(["esri/request"], function(esriRequest) {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant