Select to view content in your preferred language

Adding KML Layer from file

1998
2
10-22-2011 04:18 PM
xplorerxplorer
New Contributor
Hi,
I tried the following code that was posted in this forum. I can see what appears to be the KML layer however It renders extremely small (almost a dot). It appears to be a projection issue however I am not sure what I am missing. Also the graphic count of the layer is 0.

OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "KML files (.kml)|*.kml|Compressed KML files
(.kmz)|*.kmz|All Files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;

bool? userClickedOK = openFileDialog1.ShowDialog();
if (userClickedOK == true)
{
                System.IO.Stream fileStream = openFileDialog1.File.OpenRead();
                var layer = new KmlLayer();
                layer.SetSource(myFiledDialog.File);
                myMap.Layers.Add(layer);
}
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
Have you looked at this SDK sample? http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#KmlLayerSimple. To create a KML layer, you want to set its Url property.
0 Kudos
CHRISTOSCHARMATZIS
Deactivated User
Hi,
I tried the following code that was posted in this forum. I can see what appears to be the KML layer however It renders extremely small (almost a dot). It appears to be a projection issue however I am not sure what I am missing. Also the graphic count of the layer is 0.

OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "KML files (.kml)|*.kml|Compressed KML files
(.kmz)|*.kmz|All Files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;

bool? userClickedOK = openFileDialog1.ShowDialog();
if (userClickedOK == true)
{
                System.IO.Stream fileStream = openFileDialog1.File.OpenRead();
                var layer = new KmlLayer();
                layer.SetSource(myFiledDialog.File);
                myMap.Layers.Add(layer);
}


Create a button and on the click event in code behind write
private void OnOpenButtonClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "KML files (.kml)|*.kml|Compressed KML files (.kmz)|*.kmz|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;

            bool? userClickedOK = openFileDialog1.ShowDialog();
            if (userClickedOK == true)
            {
                System.IO.Stream fileStream = openFileDialog1.File.OpenRead();
                var layer = new KmlLayer();
                layer.SetSource(fileStream);
                MyMap.Layers.Add(layer);
            }
        }
0 Kudos