Is this what you were looking for?http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#KmlLayerSimple
You need to start with the source code for the KMLLayer classes mentioned above (get the bits from codeplex). Then modify the constructor and initializer code to accept a stream or byte array as a source input (instead of setting source URI). Find the place in there where the webclient_downloadcomplete routine hands off the stream to the kml parser and plug in your source data there. The rest should work as-is.
Nothing I said is really specific to ESRI classes or concepts. This is basic .NET stuff. Download the codeplex source code and put it into a project, then step through the calls to see how it works. I wouldn't want to rob you of the learning process by just pasting some code here for you to copy.
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); }
Thank you for your reply! To be clear, though, I am not wanting to load a kml from a local machine/client to the silverlight app/host/server. Rather, I would like the host map data to come from a kml file on the server (with no user interaction). This can be done with Javascript, I believe. Am I still barking up the wrong tree? Another way to clarify is that I do not have the capability to serve out my own data as a service. Therefore I must find a way to host my data in another form (perhaps similar to a Graphics Layer stored with the Silverlight Assets?). If this is not viable, maybe Silverlight is not the way to go for me. I do see that others on this list have asked about ways to host kmls and shapefiles directly in their maps.
Did you look at the SDK sample? http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#KmlLayerSimpleIt pulls KML data straight from a website: <esri:KmlLayer ID="KmlLayer" Url="http://kml-samples.googlecode.com/svn/trunk/KML_Samples.kml" />
You cannot read files directly from a local folder on disk if you are using Silverlight (that would be a HUGE security risk). You can use the OpenFileDialog class to let the user browse to a kml file. This will give you a stream to the kml file. Next use the SetSource method and use the stream as the parameter. Last add KML layer that to your map.Something along the lines of this (untested): 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); }
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.