locked
KML Load Problem RRS feed

  • Question

  • I have the following logic were first to layers load fine. (Stormlayer and CorridorLayer)

    KML SPCDay1URL does NOT LOAD

    Weather Tile source works fine... What am I missing here?

                            map.layers.insert(Stormlayer);
                            map.layers.insert(CorridorLayer);
                            
                            //Load the GeoXml module.
                            Microsoft.Maps.loadModule('Microsoft.Maps.GeoXml', function () {
                                //Create an instance of the GeoXmlLayer.
                                var SPClayer = new Microsoft.Maps.GeoXmlLayer();
                                //Add the layer to the map.
                                map.layers.insert(SPClayer);
                            });
                            alert("got past GeoXML defination");
    
                            var proxyService = window.location.href.substring(0, window.location.href.indexOf("/", 8)) + '/GeoXml/GeoXmlLayer%20-%20Cross%20Domain/GeoXmlProxyService.ashx?url=';
                            var SPCDay1URL = "http://www.spc.noaa.gov/products/outlook/day1otlk_cat.kml";    
                            // CORS Enabled
    
                            SPClayer.setDataSource(proxyService + encodeURIComponent(SPCDay1URL), true);
                        //    SPClayer.setDataSource(SPCDay1URL);
                            alert("got past SPC code");
    
    
    
                            if (document.MapForm.Radar[1].checked == true) {
                                // weather radar tiles from Iowa Environmental Mesonet of Iowa State University
                                var weatherTileSource = new Microsoft.Maps.TileSource({
                                      uriConstructor: 'https://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913/{zoom}/{x}/{y}.png'
                               //     uriConstructor: 'https://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-eet-900913/{zoom}/{x}/{y}.png'
                                });
                                var weatherTileLayer = new Microsoft.Maps.TileLayer({
                                    mercator: weatherTileSource,
                                    opacity: 0.8,
                                });
                                map.layers.insert(weatherTileLayer);
    
                            }

    Thanks in Advance

    Friday, April 20, 2018 3:49 PM

Answers

  • You are creating the GeoXmlLayer inside of the module load callback, but setting its datasource outside of the callback. This won't work as your could be trying to set the data source before the module has finished loading, and the instance of the GeoXmlLayer you created is out of scope since it is in another function.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Monday, April 23, 2018 4:56 AM
    • Marked as answer by S1mon_ Tuesday, May 1, 2018 1:58 PM
    Monday, April 23, 2018 4:55 AM