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

4826
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
Thanks Robert,
I plan on doing that, at least they are aware of a few bugs to work through and it is getting closer.  I will deploy my App without it for now, and look foward to better KML support when it comes out.
If you were working on a Widget, let me know if you get it done.  I think I may continue to look at the code at my end as well.

Thanks,
Don
0 Kudos
DonCopple
Occasional Contributor III
OK,
So I have created a widget that will allow a user to add a kml (attached screenshot).  It works with the ones that work, and others will not because of bugs (same ones I have mention above from NOAA).  Hopefully the bugs will be worked out in the next release, or patch.

Anyway, with my widget, it will load the kml as a layer, but assigns it a name in the layer list (see screen shot).  How do I go about giving the user the ability to change the layer title in the layerlist.  I have been trying to find the code that will do that.  The screen shot show lightning data loaded from the BLM as a kml.  Can anyone help me out?

Another thing I would like to add would be to delete that layer from the list also, since it may be a temporary layer (kind of like the add bookmark, I can delete added bookmarks, but not the programmed ones.

Thanks,
Don
0 Kudos
BjornSvensson
Esri Regular Contributor
... look foward to better KML support when it comes out.


If you had a KML file that didn't work properly, please try again.  The KML support has been improved.  You don't need to do anything to take advantage of it. No need to recompile etc.  It is the underlying utility service we are using that has been updated.

BTW, if you have a URL that still doesn't work with the 2.4 Flex API/Viewer, go to http://www.arcgis.com/home/webmap/viewer.html and try to add it there (Add -> Add Layer from Web -> KML). If it fails there too, click the "Contact Us" link on the bottom left of the page and report that the KML doesn't work. Don't forget to include the URL of the KML file.
0 Kudos
DonCopple
Occasional Contributor III
OK Bjorn,
I tried the second approach, still no lcuk, the online map will not bring up networked links, I think it states that in the load file from Web, and KML types that can be loaded link.

So still no luck.  In my application, it will populate the TOC and even have the drill down in the menu all the way to the data, but the data comes up as a ? in the TOC and no information is displayed on the map.  I did include the links in the contact us message, and they are here in my earlier messages.

Hopefully someone will get back to me on the rest of my post so I can get my widget up and running, it is running, just need it to be better.

Thanks,
Don
0 Kudos
DonCopple
Occasional Contributor III
So I am close to adding th eKML widget.  It will allow you to add one kml, overwrite it, and deleted it from the map and layer list.  I think if I could figure out how to program an array now, then you could add our remove multiple kml layers at the same time.  I have a public var then one that needs the array so kmlLayer I think to add multiples.  I have attached the code for adding, removing the 1 kml.  Any coders that could help me with the array, I would appreciate it.  I will be happy to share the widget, and uncompiled code when I get it completed.
Thanks,

Here's the code:

import com.esri.ags.layers.KMLLayer;
   import com.esri.ags.layers.Layer;
   import com.esri.ags.layers.supportClasses.KMLFeatureInfo;
   import com.esri.ags.layers.supportClasses.KMLFolder;
   import com.esri.ags.layers.supportClasses.LayerInfoWindowRenderer;
   import com.esri.viewer.AppEvent;
   import com.esri.viewer.components.toc.TOC;
   import com.esri.viewer.components.toc.tocClasses.TocKmlFolderItem;
   import com.esri.viewer.components.toc.tocClasses.TocKmlNetworkLinkItem;
   import com.esri.viewer.components.toc.tocClasses.TocMapLayerItem;
  
   import flash.display.Sprite;
  
   import flashx.textLayout.events.SelectionEvent;
  
   import mx.events.ValidationResultEvent;
   import mx.messaging.Consumer;
   import mx.rpc.http.Operation;
   import mx.utils.object_proxy;
   import mx.validators.ValidationResult;
   import mx.validators.Validator;
  
   import widgets.InfoTemplates.SimpleInfoWinWidget;

   private const ICON_URL:String = "assets/images/";
   private var KMLLocation:String;
   public var kmlLayer:KMLLayer= new KMLLayer();
   //this function called when the widget's configuration is loaded
  
   private function init():void
   {
    if (configXML) // checking for valid content in the configuration file
    {
     lbl.text = configXML.content || getDefaultString("KMLLayerWidgetContent");
    }
    KMLLayerWgt.addTitlebarButton(ICON_URL + "Google-Earth-24.png","Load KML",showstateLoadKML);
    KMLLayerWgt.addTitlebarButton(ICON_URL + "Google-Earth-24rmv.png","Remove KML",showstateDelete);
   }
  
   private function showstateLoadKML():void
   {
    this.currentState="KMLInput";
    KMLLayerWgt.selectedTitlebarButtonIndex = 1;
   }
   private function showstateDelete():void
   {
    this.currentState="removeKML";
    KMLLayerWgt.selectedTitlebarButtonIndex = 0;
   }
//todo figure out an array to add a new kml, or add a field to ask if you want new?
   public function LoadKML():void
   {
    kmlLayer.url = KMLAddress.text;
    kmlLayer.name = kmlname.text;
    map.addLayer(kmlLayer);
    this.ClearForm();   
   }
  
   public function ClearForm():void
   {
    KMLAddress.text="";
    kmlname.text="";
   }
     
   private function removeLayer():void
   {
    map.getLayer(kmlLayer.name);
    map.removeLayer(kmlLayer);
   }
0 Kudos
BjornSvensson
Esri Regular Contributor
Clarification - How To Report a "problem" KML

Option A. Verify that it works in ArcGIS.com Viewer
Go to http://www.arcgis.com/home/webmap/viewer.html and try to add it there (Add -> Add Layer from Web -> KML). If it fails there too, click the "Contact Us" link on the bottom left of the page and report that the KML doesn't work. Don't forget to include the URL of the KML file. If it works on ArcGIS.com Viewer, but not with Flex API or Flex Viewer, see option B and C below.

Option B. Report it to Esri Support - http://support.esri.com.

Option C. Report it on the Esri Forums


Requirements/Limitations:

  • Your KML needs to be publicly accessibly.


Known issues:

  • If your KML contains areas outside of Web Mercator scope (i.e North pole, South pole) as in some of the NOAA feeds, then it will fail if your Map is in Web Mercator. If your basemap is in geographic, it works fine. This issue will be fixed in the next version.

0 Kudos
DanielKonde
New Contributor

I am having problems accessing the .swc file to import. I have to

   import com.esri.viewer.AppEvent;

   import com.esri.viewer.components.toc.TOC;

   import com.esri.viewer.components.toc.tocClasses.TocKmlFolderItem;

   import com.esri.viewer.components.toc.tocClasses.TocKmlNetworkLinkItem;

   import com.esri.viewer.components.toc.tocClasses.TocMapLayerItem;

My end result will be to load KML into Flexxviewer. Where can I find the correct library?

0 Kudos