コード例 #1
0
        public DataActionResult GetGeography(Guid id, bool?overview)
        {
            if (!User.IsInRole("cdb.users"))
            {
                return(GetLoginError());
            }

            MapDataView model = new MapDataView();
            var         query = (from g in this.db.MissionGeography where g.Mission.Id == id select g);

            if (overview.HasValue && overview.Value)
            {
                query = query.Where(f => f.Kind == "found" || f.Kind == "base" || f.Kind == "cluLkp").OrderByDescending(f => f.Kind).Take(1);
            }

            model.Items.AddRange(query.AsEnumerable().Select(f => GeographyView.BuildGeographyView(f)));
            return(Data(model));
        }
コード例 #2
0
        public JsonDataContractResult GetGeographies(DateTime?start, DateTime?stop, bool?overview)
        {
            MapDataView   model    = new MapDataView();
            List <string> messages = new List <string>();
            var           query    = (from g in this.db.MissionGeography.Include("Mission") select g);

            if (start.HasValue)
            {
                query = query.Where(f => f.Mission.StartTime >= start.Value);
            }
            if (stop.HasValue)
            {
                query = query.Where(f => f.Mission.StopTime < stop.Value);
            }

            Guid lastMission = Guid.Empty;
            int  excluded    = 0;

            Dictionary <Mission, GeographyView> views = new Dictionary <Mission, GeographyView>();

            foreach (MissionGeography geo in query.ToList().OrderBy(f => f.Mission.StartTime).ThenBy(f => f.Mission.StateNumber).ThenBy(f => f.Mission.Id).ThenBy(f => f.Geography.STDimension()).ThenByDescending(f => f.Kind))
            {
                if (geo.Mission.Id == lastMission)
                {
                    continue;
                }

                if (!User.IsInRole("cdb.users") && (geo.Mission.MissionType.ToLowerInvariant().Contains("urban") || geo.Mission.MissionType.ToLowerInvariant().Contains("evidence")))
                {
                    excluded++;
                    lastMission = geo.Mission.Id;
                    continue;
                }

                if ((overview ?? true) && !(geo.Kind == "found" || geo.Kind == "base" || geo.Kind == "cluLkp"))
                {
                    continue;
                }

                if (geo.Geography.STDimension() == 1)
                {
                    geo.Geography = geo.Geography.STPointN(1);
                }

                GeographyView view = GeographyView.BuildGeographyView(geo);

                view.Description = string.Format("{0:yyyy-MM-dd}, #{1}<br/>{2}<br/>{3}",
                                                 geo.Mission.StartTime.Date,
                                                 geo.Mission.StateNumber,
                                                 geo.Mission.Title,
                                                 User.IsInRole("cdb.users") ? "<a target=\"_blank\" href=\"" + Url.Action("geography", new { id = geo.Mission.Id }) + "\">View Details</a>" : ""
                                                 );
                view.EventId = geo.Mission.Id;

                model.Items.Add(view);

                lastMission = geo.Mission.Id;
            }

            if (excluded > 0)
            {
                messages.Add(string.Format("{0} evidence and/or urban searches not shown to anonymous users.", excluded));
            }

            if (messages.Count > 0)
            {
                model.Messages = messages.ToArray();
            }

            return(new JsonDataContractResult(model));
        }
コード例 #3
0
        public void AddItem(GeographyView item, string name, string kind, string description, Guid?folder)
        {
            bool visible = true;

            kind = (kind ?? "").ToLowerInvariant();
            TimeZoneInfo pacific  = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var          itemNode = Create("Placemark", name, description);

            if (documentNode.Elements(KML_NS + "Style").SingleOrDefault(f => f.Attribute("id").Value == "noLabel") == null)
            {
                var styleNode = new XElement(KML_NS + "Style");
                styleNode.SetAttributeValue("id", "noLabel");
                styleNode.Add(new XElement("LabelStyle", new XElement("scale", "0.5")));
                documentNode.Add(styleNode);
            }

            if (item is RouteView)
            {
                List <string> coords       = new List <string>();
                List <string> times        = new List <string>();
                bool          useTimestamp = true;

                itemNode.Add(new XElement(KML_NS + "styleUrl", "#" + GetLineStyle(colors[ColorIndex++ % colors.Length])));
                var lineNode = new XElement(GEXT_NS + "Track");
                itemNode.Add(lineNode);

                if (((RouteView)item).Points.All(f => f.Z.HasValue))
                {
                    // lineNode.Add(new XElement(KML_NS + "altitudeMode", "absolute"));
                }

                foreach (var pt in ((RouteView)item).Points)
                {
                    coords.Add(string.Format("{0} {1} {2}", pt.Long, pt.Lat, pt.Z));
                    if (useTimestamp && pt.Time.HasValue)
                    {
                        times.Add((pt.Time.Value - pacific.GetUtcOffset(pt.Time.Value)).ToString("s") + "Z");
                    }
                    else
                    {
                        useTimestamp = false;
                    }
                }

                if (useTimestamp)
                {
                    foreach (string time in times)
                    {
                        lineNode.Add(new XElement(KML_NS + "when", time));
                    }
                }

                foreach (string coord in coords)
                {
                    lineNode.Add(new XElement(GEXT_NS + "coord", coord));
                }
                //var lineNode = new XElement(KML_NS + "LineString");
                //lineNode.Add(new XElement(KML_NS + "extrude", 1));
                //lineNode.Add(new XElement(KML_NS + "tessellate", 1));
                //lineNode.Add(new XElement(KML_NS + "altitudeMode", "clampToGround"));
                //lineNode.Add(new XElement(KML_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(KML_NS + "Point", new XElement(KML_NS + "coordinates", string.Format("{0},{1}", wpt.Long, wpt.Lat))));
                if (item.Kind == "team")
                {
                    visible = false;
                }

                itemNode.Add(new XElement(KML_NS + "styleUrl", "#" + (knownIconTypes.Contains(kind) ? kind : "noLabel")));
            }

            itemNode.Add(new XElement(KML_NS + "visibility", visible ? 1 : 0));

            folders[folder ?? Guid.Empty].Add(itemNode);
        }
コード例 #4
0
        public ActionResult SubmitWaypoint(WaypointView wpt)
        {
            List <SubmitError> errors = new List <SubmitError>();
            Guid result = Guid.Empty;

            if (!User.IsInRole("cdb.missioneditors"))
            {
                return(GetLoginError());
            }

            MissionGeography geog = null;

            geog = (from g in this.db.MissionGeography where g.Id == wpt.Id select g).FirstOrDefault();
            if (geog == null)
            {
                geog = new MissionGeography {
                    Mission = (from m in this.db.Missions where m.Id == wpt.EventId select m).First()
                };
                this.db.MissionGeography.Add(geog);
            }

            //try
            //{
            if (geog.Kind != wpt.Kind)
            {
                geog.Kind = wpt.Kind;
            }
            if (geog.InstanceId != wpt.InstanceId)
            {
                geog.InstanceId = wpt.InstanceId;
            }

            SqlGeography defaultCoord = GeographyServices.GetDefaultLocation();

            wpt.Lat  = Math.Abs(wpt.Lat) * Math.Sign(defaultCoord.Lat.Value);
            wpt.Long = Math.Abs(wpt.Long) * Math.Sign(defaultCoord.Long.Value);

            SqlGeography geography = wpt.AsSqlGeography();

            if (string.Format("{0}", geog.Geography) != string.Format("{0}", geography))
            {
                geog.Geography = geography;
            }
            if (geog.Description != wpt.Description)
            {
                geog.Description = wpt.Description;
            }
            if (geog.Time != wpt.Time)
            {
                geog.Time = wpt.Time;
            }

            if (errors.Count == 0)
            {
                this.db.SaveChanges();
            }

            //}
            //catch (RuleViolationsException ex)
            //{
            //  //this.CollectRuleViolations(ex, fields);
            //  foreach (RuleViolation v in ex.Errors)
            //  {
            //    errors.Add(new SubmitError { Error = v.ErrorMessage, Property = v.PropertyName, Id = new[] { v.EntityKey } });
            //  }
            //}

            return(Data(new SubmitResult <GeographyView>
            {
                Errors = errors.ToArray(),
                Result = (errors.Count > 0) ?
                         (GeographyView)null :
                         GeographyView.BuildGeographyView(geog)
                         //new WaypointView
                         //{
                         //    Id = newView.Id,
                         //    MissionId = newView.Mission.Id,
                         //    Kind = newView.Kind,
                         //    Desc = newView.Description,
                         //    Lat = GeographyServices.FormatCoordinate(newView.Geography.Lat.Value, this.UserSettings.CoordinateDisplay),
                         //    Long = GeographyServices.FormatCoordinate(newView.Geography.Long.Value, this.UserSettings.CoordinateDisplay),
                         //    Instance = newView.InstanceId,
                         //    Time = newView.Geography.M.IsNull ? (DateTime?)null : DateTime.FromOADate(newView.Geography.M.Value)
                         //}
            }));
        }
コード例 #5
0
 public void AddItem(GeographyView item, string name, string description, Guid?folder)
 {
     AddItem(item, name, null, description, folder);
 }
コード例 #6
0
 public void AddItem(GeographyView item, string name, Guid?folder)
 {
     AddItem(item, name, item.Description, folder);
 }
コード例 #7
0
ファイル: KmlBuilder.cs プロジェクト: mattkur/KCSARA-Database
        public void AddItem(GeographyView item, string name, string kind, string description, Guid? folder)
        {
            bool visible = true;
            kind = (kind ?? "").ToLowerInvariant();
            TimeZoneInfo pacific = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var itemNode = Create("Placemark", name, description);

            if (documentNode.Elements(KML_NS + "Style").SingleOrDefault(f => f.Attribute("id").Value == "noLabel") == null)
            {
                var styleNode = new XElement(KML_NS + "Style");
                styleNode.SetAttributeValue("id", "noLabel");
                styleNode.Add(new XElement("LabelStyle", new XElement("scale", "0.5")));
                documentNode.Add(styleNode);
            }

            if (item is RouteView)
            {
                List<string> coords = new List<string>();
                List<string> times = new List<string>();
                bool useTimestamp = true;

                itemNode.Add(new XElement(KML_NS + "styleUrl", "#" + GetLineStyle(colors[ColorIndex++ % colors.Length])));
                var lineNode = new XElement(GEXT_NS + "Track");
                itemNode.Add(lineNode);

                if (((RouteView)item).Points.All(f => f.Z.HasValue))
                {
                    // lineNode.Add(new XElement(KML_NS + "altitudeMode", "absolute"));
                }

                foreach (var pt in ((RouteView)item).Points)
                {
                    coords.Add(string.Format("{0} {1} {2}", pt.Long, pt.Lat, pt.Z));
                    if (useTimestamp && pt.Time.HasValue)
                    {
                        times.Add((pt.Time.Value - pacific.GetUtcOffset(pt.Time.Value)).ToString("s") + "Z");
                    }
                    else
                    {
                        useTimestamp = false;
                    }
                }

                if (useTimestamp)
                {
                    foreach (string time in times)
                    {
                        lineNode.Add(new XElement(KML_NS + "when", time));
                    }
                }

                foreach (string coord in coords)
                {
                    lineNode.Add(new XElement(GEXT_NS + "coord", coord));
                }
                //var lineNode = new XElement(KML_NS + "LineString");
                //lineNode.Add(new XElement(KML_NS + "extrude", 1));
                //lineNode.Add(new XElement(KML_NS + "tessellate", 1));
                //lineNode.Add(new XElement(KML_NS + "altitudeMode", "clampToGround"));
                //lineNode.Add(new XElement(KML_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(KML_NS + "Point", new XElement(KML_NS + "coordinates", string.Format("{0},{1}", wpt.Long, wpt.Lat))));
                if (item.Kind == "team")
                {
                    visible = false;
                }

                itemNode.Add(new XElement(KML_NS + "styleUrl", "#" + (knownIconTypes.Contains(kind) ? kind : "noLabel")));
            }

            itemNode.Add(new XElement(KML_NS + "visibility", visible ? 1 : 0));

            folders[folder ?? Guid.Empty].Add(itemNode);
        }
コード例 #8
0
ファイル: KmlBuilder.cs プロジェクト: mattkur/KCSARA-Database
 public void AddItem(GeographyView item, string name, string description, Guid? folder)
 {
     AddItem(item, name, null, description, folder);
 }
コード例 #9
0
ファイル: KmlBuilder.cs プロジェクト: mattkur/KCSARA-Database
 public void AddItem(GeographyView item, string name, Guid? folder)
 {
     AddItem(item, name, item.Description, folder);
 }