コード例 #1
0
        public FileContentResult MissionsKML(DateTime?begin, DateTime?end)
        {
            List <GeographyView> items = ((MapDataView)GetGeographies(begin, end, false).Data).Items;

            items.Reverse();

            Dictionary <Guid, Tuple <int, int> > detailCounts = (from mg in this.db.MissionGeography group mg by mg.Mission.Id into g select new { Id = g.Key, Points = g.Count(f => !f.Kind.EndsWith("trk")), Tracks = g.Count(f => f.Kind.EndsWith("trk")) }).ToDictionary(f => f.Id, f => new Tuple <int, int>(f.Points, f.Tracks));

            KmlBuilder kml = (new KmlBuilder {
                Name = "Mission Data", Description = "Mission data from KCSARA ()"
            }).AddIconStyles(this.AbsoluteUrl(Url.Content("~/content/images/maps")));

            Guid overview = kml.CreateFolder("Overview", null);

            foreach (var item in items)
            {
                string[] lines = item.Description.Split(new[] { "<br/>" }, StringSplitOptions.RemoveEmptyEntries);
                item.Description = lines[1] + "<br/>" + lines[0].Split(',')[0];

                string dem = lines[0].Split('#')[1];
                kml.AddItem(item, dem, item.Kind, null, overview);
                int points = detailCounts[(Guid)item.EventId].Item1;
                int tracks = detailCounts[(Guid)item.EventId].Item2;
                if (points > 1 || tracks > 0)
                {
                    kml.AddLink(string.Format("{0} {1} ({2})", dem, lines[1], points + tracks), null, AbsoluteUrl(Url.Action("MissionKML", new { id = item.EventId, _auth = "basic" })), false, null);
                }
            }

            return(new FileContentResult(Encoding.UTF8.GetBytes(kml.ToString()), "application/vnd.google-earth.kml+xml")
            {
                FileDownloadName = "kcsara-missions.kml"
            });
        }
コード例 #2
0
        public FileContentResult MissionKML(Guid id)
        {
            MapDataView data = (MapDataView)GetGeography(id, false).Data;

            Mission m = (from mission in this.db.Missions where mission.Id == id select mission).FirstOrDefault();

            XNamespace ns  = "http://earth.google.com/kml/2.1";
            KmlBuilder kml = (new KmlBuilder {
                Name = string.Format("{0}: {1}", m.StateNumber, m.Title), Description = ""
            }).AddIconStyles(this.AbsoluteUrl(Url.Content("~/content/images/maps")));


            string[] colors     = "ff4500,ff42c3,904cff".Split(',');
            Guid     teamFolder = Guid.Empty;

            foreach (var item in data.Items)
            {
                Guid?folder = null;
                if (item.Kind == "team")
                {
                    if (teamFolder == Guid.Empty)
                    {
                        teamFolder = kml.CreateFolder("Team Positions", null);
                    }
                    folder = teamFolder;
                }

                string name = string.IsNullOrWhiteSpace(item.Description) ? item.Kind : item.Description;

                kml.AddItem(item, name, item.Kind, null, folder);


                //var itemNode = new XElement(ns + "Placemark");
                //itemNode.Add(new XElement(ns + "name", item.Description));
                //itemNode.Add(new XElement(ns + "description", item.Description));

                //if (item is RouteView)
                //{
                //    itemNode.Add(new XElement(ns + "styleUrl", "#_" + colors[i++ % colors.Length]));
                //    var lineNode = new XElement(ns + "LineString");
                //    lineNode.Add(new XElement(ns + "extrude", 1));
                //    lineNode.Add(new XElement(ns + "tessellate", 1));
                //    lineNode.Add(new XElement(ns + "altitudeMode", "clampToGround"));
                //    //lineNode.Add(new XElement(ns + "color", colors[i++ % colors.Length]+"ff"));
                //    lineNode.Add(new XElement(ns + "coordinates", string.Join("\n", ((RouteView)item).Points.Select(f => string.Format("{0},{1},10", f.Long, f.Lat)).ToArray())));
                //    itemNode.Add(lineNode);
                //}
                //else if (item is WaypointView)
                //{
                //    WaypointView wpt = (WaypointView)item;
                //    itemNode.Add(new XElement(ns + "Point", new XElement(ns + "coordinates", string.Format("{0},{1}", wpt.Long, wpt.Lat))));
                //    if (item.Kind == "team")
                //    {
                //        itemNode.Add(new XElement(ns + "visibility", 0));
                //    }
                //}
                //docNode.Add(itemNode);
            }



            return(new FileContentResult(System.Text.Encoding.UTF8.GetBytes(kml.ToString()), "application/vnd.google-earth.kml+xml")
            {
                FileDownloadName = m.StateNumber + ".kml"
            });
        }