Beispiel #1
0
        public ActionResult Data(
			string datemode, string startdate, string enddate,
			string categories, string race,
			string ne_lat, string ne_lng,
			string sw_lat, string sw_lng)
        {
            IEnumerable<int?> cats = categories.Trim('-').
                Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries).
                Select(_ => (int?)int.Parse(_));

            float nelat = float.Parse(ne_lat, CultureInfo.GetCultureInfo("en-US"));
            float nelng = float.Parse(ne_lng, CultureInfo.GetCultureInfo("en-US"));
            float swlat = float.Parse(sw_lat, CultureInfo.GetCultureInfo("en-US"));
            float swlng = float.Parse(sw_lng, CultureInfo.GetCultureInfo("en-US"));

            var enddt = DateTime.MaxValue;
            var startdt = DateTime.MinValue;

            var db = new DatabaseDataContext();

            if (datemode == "day")
            {
                enddt = DateTime.Now.AddDays(1);
                startdt = DateTime.Now.AddDays(-1);
            }
            else if (datemode == "week")
            {
                enddt = DateTime.Now.AddDays(1);
                startdt = DateTime.Now.AddDays(-7);
            }
            else if (datemode == "month")
            {
                startdt =
                    DateTime.ParseExact(startdate, "MMM-yyyy", CultureInfo.GetCultureInfo("da-DK"));
                enddt =
                    DateTime.ParseExact(enddate, "MMM-yyyy", CultureInfo.GetCultureInfo("da-DK"));
            }

            var repository = new EventRepository();

            var events = from e in repository.GetGeocodedEvents(startdt, enddt)
                         where
                                 e.Lat > swlat &&
                                 e.Lat < nelat &&
                                 e.Lng > swlng &&
                                 e.Lng < nelng &&
                                 ((e.CategoryId.HasValue && cats.Contains(e.CategoryId.Value)) ||
                                 (!e.CategoryId.HasValue && cats.Contains(42)))
                         select new object[] { e.Lat.Value, e.Lng.Value, e.EventId, e.CategoryId ?? 42 };

            return this.Json(
                new
                {
                    count = events.Count(),
                    events = events,
                });
        }
Beispiel #2
0
        public ContentResult Sitemap()
        {
            string smdatetimeformat = "yyyy-MM-dd";

            var erep = new EventRepository();
            var events = (from e in erep.GetGeocodedEvents()
                            where e.IncidentTime.HasValue
                        select new {e.Title, e.EventId, e.IncidentTime}).ToList();

            XNamespace sm = "http://www.sitemaps.org/schemas/sitemap/0.9";
            XNamespace geo = "http://www.google.com/geo/schemas/sitemap/1.0";

            XDocument doc = new XDocument(
                new XElement(sm + "urlset",
                    new XAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"),
                    new XAttribute(XNamespace.Xmlns + "geo",
                        "http://www.google.com/geo/schemas/sitemap/1.0"),
                    new XElement(sm + "url",
                        new XElement(sm + "loc", "http://krimikort.ekstrabladet.dk/gearth.kmz"),
                        new XElement(sm + "lastmod", DateTime.Now.ToString(smdatetimeformat)),
                        new XElement(sm + "changefreq", "daily"),
                        new XElement(sm + "priority", "1.0"),
                        new XElement(geo + "geo",
                            new XElement(geo + "format", "kmz")
                        )
                    )
                    ,
                    events.Select(e =>
                        new XElement(sm + "url",
                            new XElement(sm + "loc", EventExtensions.AbsUrl(e.Title, e.EventId)),
                            new XElement(sm + "lastmod", e.IncidentTime.Value.ToString(smdatetimeformat)),
                            new XElement(sm + "changefreq", "monthly"),
                            new XElement(sm + "priority", "0.5")
                        )
                    )
                )
            );

            return Content(doc.ToString(), "text/xml");
        }
Beispiel #3
0
        private static geKML GetKML()
        {
            geDocument doc = new geDocument();

            doc.Name = "Ekstra Bladets Krimikort";
            doc.AuthorName = "Ekstra Bladet";
            doc.Link = "http://krimikort.ekstrabladet.dk/";

            var categories = (new CategoryRepository()).GetCategories();
            doc.StyleSelectors.AddRange(
                categories.Select(c =>
                    new geStyle(c.DisplayName)
                    {
                        IconStyle = new geIconStyle
                        {
                            Icon = new geIcon(
                                string.Format("http://krimikort.ekstrabladet.dk/Content/icons/{0}.png",
                                    ViewUtil.GetIconName(c.CategoryId))),
                        },
                    }
                ));

            var erep = new EventRepository();
            var events = (from e in erep.GetGeocodedEvents()
                select new { e.Category, e.Title, e.BodyText, e.EventId, e.Lng, e.Lat }).
                ToList();

            doc.Features.AddRange(
                events.Select(e => new gePlacemark()
                {
                    Name = e.Title,
                    ID = e.EventId.ToString(),
                    Description = e.BodyText ?? "",
                    StyleUrl = "#" + (e.Category == null ? "Andet" : e.Category.DisplayName),
                    Link = EventExtensions.AbsUrl(e.Title, e.EventId),
                    Geometry = new gePoint(
                        new geCoordinates(
                            new geAngle90(e.Lat.Value), new geAngle180(e.Lng.Value)
                            )
                        )
                })
                );

            return new geKML(doc);
        }