Flex API 2.4 KML support added - need sample of how to add kml

4822
26
08-01-2011 07:57 AM
DonCopple
Occasional Contributor III
I see kml support added and in the documentation it says the <layer> tag now supports type = "kml".

I have been trying to add that as a layer in my config.xml file as such:
<Layer> label="Mesowest Observations" type="kml" visible="false"
            url="http://www.srh.noaa.gov/gis/kml/mesowest/mesowestlink.kml"/>

I get an error on load Fault code: Client.CouldNotDecode
                             Fault info: Error #1085
                             Fault details: null

I cannot find any documentation on how to envoke the new layer easily, looks like I could go in and code something to load it, maybe.  Anyone else figured out how to add the kml layers?  I am combining kml and GIS layers.
Tags (2)
0 Kudos
26 Replies
DonCopple
Occasional Contributor III
Ok was able to figure out the config file error here is the correct format:
<layer label="Spot Forecast" type="kml" visible="true"
                   url="http://www.srh.noaa.gov/gis/kml/SpotForecast/spotLink.kml"/>

However, it isn't working.  I believe the kml has the autorefresh mode set as well, maybe that is the problem.  It will not load.  The above KML is spot weather forecasts for the United States.  I did notice that I do not have the newest Flex SDK, so will load that and try again.  Do you think that would cause the error?  Although the kml layer load is in com.esri sdk.....If it works I will update, or delete this thread.  P.S. The copper mines kml included in the apps.config-kml.xml loads fine, the other layers do not (included with the 2.4 flex app).

Thanks,
Don
0 Kudos
DonCopple
Occasional Contributor III
The kml link in my last post still refused to work in flex 2.4.  I was able to find samples in the apps folder for those of you who want a sample config, and finally located that on the websites as well, so I appologize for that lack of looking.  However, with that said, I cannot get any of the freely posted kml link on the NOAA website to work in Flex.  I can load some simple kml files, and load the feed from Inciweb fire incidents (although it is just the points and none of the information associated).  I noticed some of these have some CDATA elements that are parsed by the kml viewer.  I did notice some of the additional links within a kml could not be loaded (http://www.srh.noaa.gov/gis/kml/raws/rawslink.kml) for example.  When opened in ArcGIS Explorer you have to turn on the layers you want to see (Temp & RH for example), but the points appear.  The Spot Forecast example in my last post will work in ArcGIS Explorer, and Arc GIS Desktop, but not in my Flex Application.  Is this a bug, of does anyone have any hints on how to load those.  (Is a seperate KML widget needed to properly parse and display.

I am glad it is starting to support some KML data, but need some help here.

There are a variety of US Govt. NOAA kml data here:http://www.srh.noaa.gov/gis/kml/
I am using some thing from NOAA from thier GIS services, however not all are displayed.  Most are KML.

Please reply......
0 Kudos
SarthakDatt
Occasional Contributor III
Hey Don,

Thanks for reporting this. There are couple of issues here.

The kml(http://www.srh.noaa.gov/gis/kml/SpotForecast/spotLink.kml) contains 1 screen overlay and 1 network link(pointing to http://www.srh.noaa.gov/gis/kml/SpotForecast/spot2.kmz).

- There is a bug in Flex Viewer 2.4, where the TOC does not show a network link which has   default visibility of 0(false), hence not allowing you to turn it on(make the request). If you are working with the viewer code base you can make the following change to TOCMapLayerItem.as(replace createKMLFolderTocItem() and createKmlNetworkLinkTocItem()):

private static function createKmlFolderTocItem(parentItem:TocItem, folder:KMLFolder, folders:Array, layer:KMLLayer):TocKmlFolderItem
    {
        var item:TocKmlFolderItem = new TocKmlFolderItem(parentItem, folder, layer);

        // Handle any sublayers of a group layer
        if (folder.subFolderIds && folder.subFolderIds.length > 0)
        {
            var lookInFeatureInfos:Boolean = true;
            for each (var childId:Number in folder.subFolderIds)
            {
                var childFolder:KMLFolder = findFolderById(childId, folders);
                if (childFolder)
                {
                    item.addChild(createKmlFolderTocItem(item, childFolder, folders, layer));
                }
            }
        }
        else if (folder.featureInfos && folder.featureInfos.length > 0)
        {
            for each (var featureInfo:KMLFeatureInfo in folder.featureInfos)
            {
                if (featureInfo.type == KMLFeatureInfo.NETWORK_LINK)
                {
                    var networkLink:KMLLayer = layer.getFeature(featureInfo) as KMLLayer;
                    item.addChild(createKmlNetworkLinkTocItem(item, networkLink, layer));
                }
            }
        }
        return item;
    }

    private static function createKmlNetworkLinkTocItem(item:TocItem, networkLink:KMLLayer, layer:KMLLayer):TocKmlNetworkLinkItem
    {
        var tocKmlNetworkLinkItem:TocKmlNetworkLinkItem = new TocKmlNetworkLinkItem(item, networkLink, layer);
        if (networkLink.loaded)
        {
            createKMLLayerTocItems(tocKmlNetworkLinkItem, networkLink); // as network link is also a type of KMLLayer
        }
        else
        {
            networkLink.addEventListener(LayerEvent.LOAD, layerLoadHandler);
        }

        function layerLoadHandler(event:LayerEvent):void
        {
            createKMLLayerTocItems(tocKmlNetworkLinkItem, networkLink);
        }

        return tocKmlNetworkLinkItem;
    }



- The screen overlay would still not be shown, it is a bug in the api because of the sizeX and sizeY values being -1 and we are looking to fix that.

This applies to the other kml samples that you have been trying as well.

Hope this helps.
0 Kudos
DonCopple
Occasional Contributor III
This helps greatly, thanks for providing that explanation.  It has been frustrating to figure out.  I am still trying to figure out how to create a widget to load the kml, and I am sure you code will help, just not sure how to create the widget, or where to put the code in yet.

I think a widget, much like the GEORss widget would be a good answer that could easily be thrown out in the code gallery.  Someone let me know if you're working on that so I don't waste my time trying different things.

Thanks again for the reply, and I look forward to updates, patches, or a widget to do this......
0 Kudos
SarthakDatt
Occasional Contributor III
Maybe this would help : http://help.arcgis.com/en/webapps/flexviewer/help/index.html#/Create_your_own_widget/01m300000010000...

You would add KMLLayer as any other layer is added to the map:

var kmlLayer:KMLLayer = new KMLLayer();
kmlLayer.url = // url to kml document                    
map.addLayer(kmlLayer);

0 Kudos
DonCopple
Occasional Contributor III
Thanks,
I will give it a try and reply back here if that doesn't work.  Just for your note, I modified the kml to visibility of 1 and reposted it to my own website to try that.  It now opens the TOC, but then will not populate anything point wise.  Shows a ? in my TOC window.  I assume that is from the network link, however the network link has visibility set to 1 (this is the spot2 kmz file). 

I will try your method to see if that gives me different results.

Thanks,
Don
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Sarthak,

   I got a url for you that your Flex Viewer workaround does not seem to work for:

http://puff.images.alaska.edu/kml_files/volcano/Puff_monitored_Bezymianny.kml

Any Suggestions?
0 Kudos
SarthakDatt
Occasional Contributor III
Robert,

Seems to work fine for me:
0 Kudos
DonCopple
Occasional Contributor III
Sarthak,
I have modified the kml files and posted to my own server with the visibility set to 1 as you described.  I don't think 2.4 handles networked kml links.  Changing the value to 1 does make a layer show up in the TOC as if there were something there.  However, it only lists the first network link.  So the original KML: http://www.srh.noaa.gov/gis/kml/raws/rawslink.kml , I changed the visibilty tag to 1 for each of the network linked elements.  I then saved my modified kml to a website and linked that in my config.xml.  I then went into one of the subelement links http://www.srh.noaa.gov/gis/kml/raws/rawsTfLink.kml  and change the visibility tag to 1 again, and again posted to my own website, this brought up the layer in the TOC again for temp in this case, but still nothing on the map.  So rewriting the kml to visibilty 1 helped add it to the TOC, but did not visually display the data on the map.  All my modification to the kml were visible using GE, so the KMLs are structured correctly even with my rewrites, and that allowed those element to automatically open in GE.  They are in the TOC of my Flex App, but not visible on map.

I need the kml functionality to complete and deploy my Flex Application which is why I have posted so much about kml on the forum.  I have not tried your work around yet, as I haven't figured out where to code that.  I have modified a few widgets to fit my needs so understand modifying some widgets, but just havn't had the time to code a new widget.

Robert, have you tried the links that I posted earlier to see if they work with the modifications suggested?  I see you said the one from Alaska didn't work, so didn't want to put in a bunch of time to have the same happen.  Can you give me any direction to how you used the code to get some of the working if they do?  I still think a widget would be nice, with an xml that would be able to specifiy the url to the kml file, much like GEORss works now.

One more point I noticed, no pop-ups in the included kml samples, of the online sample map.  So if I click on the western railroads kml on the sample map, it does nothing.  So if those popups need seperate xml files in the popups menu, and example of how to create those for a kml would be nice, once the kml is working.  Like I say, I am in need of this functionality to deploy my project.

Thanks.....
0 Kudos