Select to view content in your preferred language

Creating a KmlLayer not working?

966
2
Jump to solution
06-18-2013 02:07 PM
JonathanKillen
Emerging Contributor
I am trying to add a KmlLayer to my Map programmatically.  Here is what I am doing:

MapDisplay _md = null;
string strMachineName = "testmachine";
KmlLayer kmlLayer = new KmlLayer(new Uri(@"http://" + strMachineName + @"/KML/ProjectIndex.kml", UriKind.Absolute));
kmlLayer.Name = "Project Index";
_md.Map.ChildItems.Add(kmlLayer);

When this code completes, the item in the Contents list has a red exclamation point in the icon and the tool-tip "Invalid data source".  If I double-click it, the "Repair KML Network Link" dialog comes up with the URI that I added to my item.  If I click the "Repair" button, the item it "fixed" somehow. 

What does this "repair" do to the KML Node?  How can I do these fixes from my code?
0 Kudos
1 Solution

Accepted Solutions
JonathanKillen
Emerging Contributor
I contacted Support since I was not getting a response.  I learned that I needed to call "kmlLayer.Connect()" right before I add it to the Map.  I hope that helps someone else.

View solution in original post

0 Kudos
2 Replies
JonathanKillen
Emerging Contributor
I realized that I left out a line of code in my previous post.  Here is a corrected sample of code:

           
MapDisplay _md = null;
            _md = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay;
            string strMachineName = "localhost";
            KmlLayer kmlLayer = new KmlLayer(new Uri(@"http://" + strMachineName + @"/KML/Projects.kml", UriKind.Absolute));
            kmlLayer.Name = "LinkToKMLFile";
            _md.Map.ChildItems.Add(kmlLayer);
0 Kudos
JonathanKillen
Emerging Contributor
I contacted Support since I was not getting a response.  I learned that I needed to call "kmlLayer.Connect()" right before I add it to the Map.  I hope that helps someone else.
0 Kudos