Hi,
I am trying to load a kml file with polygon definistions using the following code:
Reimers.Silverlight.Bing.OverlayManager manager = new Reimers.Silverlight.Bing.OverlayManager(Map1);
manager.ReadKml(mykml);
where Map1 is my bing maps silverlight control.
The sample kml string 'myKml' is below [1].
I get the following error:
'Element is already the child of another element' stack trace is here [2]
Its driving me nuts! :p I have tried a simpler kml file with a single point which displays just fine. Do you have any ideas as to why this error is being generated? Does your librabry support kml polgon definitions? Am I missing the obvious?
Thanks for any pointers
Ben
[1] sample kml string:
public string mykml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<kml xmlns=""http://earth.google.com/kml/2.2"">
<Document>
<name><![CDATA[US States]]></name>
<open>1</open>
<Style id=""Style_5"">
<IconStyle>
<scale>0.4</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/shapes/star.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<color>9900ffff</color>
<scale>1</scale>
</LabelStyle>
<LineStyle>
<color>990000ff</color>
<width>2</width>
</LineStyle>
<PolyStyle>
<color>997f7fff</color>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
</Style>
<Placemark id=""pm269"">
<name><![CDATA[Connecticut (1788)]]></name>
<Snippet maxLines=""0"">empty</Snippet>
<styleUrl>#Style_5</styleUrl>
<MultiGeometry>
<Polygon id=""g918"">
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-73.5303920707175,41.5227455563004
-73.5442932536742,41.3652984767995
-73.5502596731917,41.2936207043954
-73.4781207568954,41.2107548889389
-73.7252376566967,41.1003542249946
-73.6537237755256,41.0126172825253
-73.6531514608995,40.9983924455247
-73.1044185740856,41.1610394427248
-72.906734323612,41.2700631991856
-72.5272448622889,41.2637025875984
-72.378152966058,41.2781022275496
-72.3784123498461,41.3583482711136
-72.3263548978381,41.2896412329135
-72.2814159025209,41.2811454708603
-71.866678442895,41.3227696452715
-71.8477722040922,41.3253484832964
-71.8368696812943,41.3419614666217
-71.8459956537022,41.4038545416488
-71.8027434308056,41.4158290540058
-71.7901942031214,41.6013068793249
-71.792605218292,41.6417579304637
-71.7882488621949,41.7216033953237
-71.7978316087619,42.0042748046851
-71.8023407165877,42.0179769339478
-72.0949717608141,42.0257995069483
-72.1363467150764,42.0264020644269
-72.5075717905207,42.0307660006011
-72.5712258924299,42.0301249737628
-72.5819073702202,42.0216068944432
-72.6078252730946,42.0228008077559
-72.6095266969696,42.030536850941
-72.7558938179071,42.0338475230699
-72.7675750314897,42.0021671817802
-72.817679571843,41.9971850435429
-72.8164509949267,42.033507731778
-73.0060955098662,42.0360092024926
-73.0456324711282,42.0363103821922
-73.4842302844536,42.0474280500728
-73.5171474133328,41.6656861632365
-73.5303920707175,41.5227455563004
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Document>
</kml>
";
[2] stack trace of error:
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.Collection_AddValue[T](PresentationFrameworkCollection`1 collection, CValue value)
at MS.Internal.XcpImports.Collection_AddDependencyObject[T](PresentationFrameworkCollection`1 collection, DependencyObject value)
at System.Windows.PresentationFrameworkCollection`1.AddDependencyObject(DependencyObject value)
at System.Windows.SetterBaseCollection.AddInternal(SetterBase value)
at System.Windows.PresentationFrameworkCollection`1.Add(T value)
at Reimers.Silverlight.Bing.OverlayManager.KmlStyleChanged(Object sender, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Reimers.Silverlight.Bing.OverlayManager.SetKmlStyle(DependencyObject obj, KmlStyle value)
at Reimers.Silverlight.Bing.OverlayManager.ApplyStyle(MapPolyline line, String styleUrl)
at Reimers.Silverlight.Bing.OverlayManager.GrabLines(IEnumerable`1 placemarks)
at Reimers.Silverlight.Bing.OverlayManager.ReadKml(XDocument kml)
at Reimers.Silverlight.Bing.OverlayManager.ReadKml(String kml)
at AreaMaps.MainPage..ctor()
at AreaMaps.App.Application_Startup(Object sender, StartupEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)