usingEsri.ArcGISRuntime.Mapping;usingSharpKml.Base;usingSharpKml.Dom;usingSharpKml.Dom.GX;usingSharpKml.Engine;usingSystem;usingSystem.IO;usingXamarin.Forms;namespaceFormsMapsShared.ArcGisRendering{publicclassTractorRenderer{Esri.ArcGISRuntime.Xamarin.Forms.MapView_mapView;KmlLayer_tractorKml;stringkmlPath="/storage/emulated/0/SmartMaps/tractor.kml";publicTractorRenderer(Esri.ArcGISRuntime.Xamarin.Forms.MapViewmapView){_mapView=mapView;}publicvoidUpdateTractorPosition(IImplementimplment){//delete the file from the last updateif(File.Exists(kmlPath)){File.Delete(kmlPath);}if(implment.TractorCenter==null){return;}varquad=newLatLonQuad();quad.Coordinates=newCoordinateCollection();quad.Coordinates.Add(newSharpKml.Base.Vector(implment.GraphicC3.Latitude,implment.GraphicC3.Longitude));quad.Coordinates.Add(newSharpKml.Base.Vector(implment.GraphicC4.Latitude,implment.GraphicC4.Longitude));quad.Coordinates.Add(newSharpKml.Base.Vector(implment.GraphicC1.Latitude,implment.GraphicC1.Longitude));quad.Coordinates.Add(newSharpKml.Base.Vector(implment.GraphicC2.Latitude,implment.GraphicC2.Longitude));varfolder=newFolder();folder.Id="f0";folder.Name="Folder 0";vargndOverlay=newGroundOverlay();gndOverlay.Icon=newIcon();gndOverlay.Icon.Href=newUri("tractor.png",UriKind.Relative);gndOverlay.GXLatLonQuad=quad;folder.AddFeature(gndOverlay);// This is the root element of the fileKmlkml=newKml();kml.Feature=folder;KmlFile.Create(kml,false);Serializerserializer=newSerializer();serializer.Serialize(kml);varstream=File.Open(kmlPath,FileMode.CreateNew,FileAccess.ReadWrite);using(varwriter=newStreamWriter(stream)){writer.Write(serializer.Xml);}UrisourceUri=newUri(kmlPath);varprev=_tractorKml;_tractorKml=newKmlLayer(sourceUri);_tractorKml.LoadAsync();// Add created overlay to the MapViewif(prev!=null){_mapView.Map.Basemap.BaseLayers.Remove(prev);}_mapView.Map.Basemap.BaseLayers.Add(_tractorKml);}}}