Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(Request["u"]) && !string.IsNullOrEmpty(Request["json"]))
            {
                string jsonString = Request["json"];

                Affine.Data.json.MapRoute mapRoute = serializer.Deserialize <Affine.Data.json.MapRoute>(jsonString);

                long userKey = Convert.ToInt64(Request["u"]);
                Affine.Data.MapRoute route = new MapRoute()
                {
                    Name          = mapRoute.Name,
                    City          = mapRoute.City,
                    Region        = mapRoute.Region,
                    Rating        = mapRoute.Rating,
                    PortalKey     = 0,              // TODO: send this in
                    UserKey       = userKey,
                    RouteDistance = mapRoute.RouteDistance,
                    LatMax        = mapRoute.LatMax,
                    LatMin        = mapRoute.LatMin,
                    LngMax        = mapRoute.LngMax,
                    LngMin        = mapRoute.LngMin,
                    CreationDate  = DateTime.Now
                };
                Affine.Data.MapRoutePoint[] points = mapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint()
                {
                    Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route
                }).ToArray <Affine.Data.MapRoutePoint>();
                route.MapRoutePoints.Concat(points);
                aqufitEntities entities = new aqufitEntities();
                entities.AddToMapRoutes(route);
                long     id                  = entities.SaveChanges();
                MapRoute passback            = entities.MapRoutes.Where(m => m.UserKey == userKey).OrderByDescending(m => m.Id).FirstOrDefault();
                Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute()
                {
                    Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance
                };
                string json = serializer.Serialize(mr);
                Response.Write(json);
            }
            else
            {
                Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute()
                {
                    Id = -1
                };
                Response.Write(serializer.Serialize(route));
            }
        }
        catch (Exception)
        {
            Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute()
            {
                Id = -1
            };
            Response.Write(serializer.Serialize(route));
        }
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(Request["u"]) && !string.IsNullOrEmpty(Request["json"]))
            {
                string jsonString = Request["json"];

                Affine.Data.json.MapRoute mapRoute = serializer.Deserialize<Affine.Data.json.MapRoute>(jsonString);

                long userKey = Convert.ToInt64(Request["u"]);
                Affine.Data.MapRoute route = new MapRoute()
                {
                    Name = mapRoute.Name,
                    City = mapRoute.City,
                    Region = mapRoute.Region,
                    Rating = mapRoute.Rating,
                    PortalKey = 0,                  // TODO: send this in
                    UserKey = userKey,
                    RouteDistance = mapRoute.RouteDistance,
                    LatMax = mapRoute.LatMax,
                    LatMin = mapRoute.LatMin,
                    LngMax = mapRoute.LngMax,
                    LngMin = mapRoute.LngMin,
                    CreationDate = DateTime.Now
                };
                Affine.Data.MapRoutePoint[] points = mapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route }).ToArray<Affine.Data.MapRoutePoint>();
                route.MapRoutePoints.Concat(points);
                aqufitEntities entities = new aqufitEntities();
                entities.AddToMapRoutes(route);
                long id = entities.SaveChanges();
                MapRoute passback = entities.MapRoutes.Where(m => m.UserKey == userKey ).OrderByDescending( m => m.Id).FirstOrDefault();
                Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute() { Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance };
                string json = serializer.Serialize(mr);
                Response.Write(json);
            }
            else
            {
                Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute() { Id = -1 };
                Response.Write(serializer.Serialize(route));
            }
        }
        catch (Exception)
        {
            Affine.Data.json.MapRoute route = new Affine.Data.json.MapRoute() { Id = -1 };
            Response.Write(serializer.Serialize(route));
        }
    }
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            switch (hiddenAjaxAction.Value)
            {
                case "saveRoute":
                    aqufitEntities entities = new aqufitEntities();
                    Affine.Data.MapRoute route = new MapRoute()
                    {
                        Name = atiGMapRoute.RouteTitle,
                        PortalKey = this.PortalId,                  // TODO: send this in
                        UserSetting = entities.UserSettings.First( u => u.Id == UserSettings.Id ),
                        RouteDistance = atiGMapRoute.RouteDistance,
                        CreationDate = DateTime.Now,
                        WorkoutTypeId = atiGMapRoute.WorkoutTypeKey
                    };

                    entities.AddToMapRoutes(route);
                    double zoom = atiGMapRoute.FitZoom;
                    double w = atiGMapRoute.MapWidth/200.0;
                    double h = atiGMapRoute.MapHeight/100.0;
                    double r = w > h ? w : h;
                    zoom = r > 0 ? zoom - Math.Sqrt(r) : zoom + Math.Sqrt(r);
                    route.ThumbZoom = (short)Math.Floor(zoom);

                    Affine.Data.MapRoutePoint[] points = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route }).ToArray<Affine.Data.MapRoutePoint>();
                    route.MapRoutePoints.Concat(points);
                    double minLat = double.MaxValue;
                    double minLng = double.MaxValue;
                    double maxLat = double.MinValue;
                    double maxLng = double.MinValue;
                    foreach( Affine.Data.MapRoutePoint p in points )
                    {
                        if (p.Lat < minLat)
                        {
                            minLat = p.Lat;
                        }
                        if (p.Lng < minLng)
                        {
                            minLng = p.Lng;
                        }
                        if (p.Lat > maxLat)
                        {
                            maxLat = p.Lat;
                        }
                        if (p.Lng > maxLng)
                        {
                            maxLng = p.Lng;
                        }
                    }
                    route.LatMax = maxLat;
                    route.LatMin = minLat;
                    route.LngMax = maxLng;
                    route.LngMin = minLng;
                    // Cull points until there are 100 or less points to make the encoded polyline fit the 512 bytes
                    int len = 100;
                    IList<Affine.Data.MapRoutePoint> pointCopy = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint() { Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order }).ToList<Affine.Data.MapRoutePoint>();
                    pointCopy = CullPoints(pointCopy, len);
                    route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                    while (route.PolyLineEncoding.Length > 512)
                    {
                        len = len/2;
                        pointCopy = CullPoints(pointCopy, len);
                        route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                    }
                    entities.SaveChanges();
                    MapRoute passback = entities.MapRoutes.Where(m => m.UserSetting.Id == this.UserSettings.Id && m.PortalKey == this.PortalId ).OrderByDescending( m => m.Id).FirstOrDefault();
                    // routes creater needs the route to show up in their route list now.
                    User2MapRouteFav fav = new User2MapRouteFav()
                    {
                        MapRoute = passback,
                        UserSettingsKey = UserSettings.Id
                    };
                    entities.AddToUser2MapRouteFav(fav);
                    entities.SaveChanges();

                    Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute() { Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance };
                    RadAjaxManager1.ResponseScripts.Add(" setSelectedMap(" + passback.Id + ", '" + passback.Name + "', " + passback.RouteDistance + ", ''); ");
                    break;
            }
            // save and close  RadAjaxManager1.ResponseScripts.Add();  /
        }
Esempio n. 4
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            switch (hiddenAjaxAction.Value)
            {
            case "saveRoute":
                aqufitEntities       entities = new aqufitEntities();
                Affine.Data.MapRoute route    = new MapRoute()
                {
                    Name          = atiGMapRoute.RouteTitle,
                    PortalKey     = this.PortalId,                  // TODO: send this in
                    UserSetting   = entities.UserSettings.First(u => u.Id == UserSettings.Id),
                    RouteDistance = atiGMapRoute.RouteDistance,
                    CreationDate  = DateTime.Now,
                    WorkoutTypeId = atiGMapRoute.WorkoutTypeKey
                };

                entities.AddToMapRoutes(route);
                double zoom = atiGMapRoute.FitZoom;
                double w    = atiGMapRoute.MapWidth / 200.0;
                double h    = atiGMapRoute.MapHeight / 100.0;
                double r    = w > h ? w : h;
                zoom            = r > 0 ? zoom - Math.Sqrt(r) : zoom + Math.Sqrt(r);
                route.ThumbZoom = (short)Math.Floor(zoom);

                Affine.Data.MapRoutePoint[] points = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint()
                {
                    Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order, MapRoute = route
                }).ToArray <Affine.Data.MapRoutePoint>();
                route.MapRoutePoints.Concat(points);
                double minLat = double.MaxValue;
                double minLng = double.MaxValue;
                double maxLat = double.MinValue;
                double maxLng = double.MinValue;
                foreach (Affine.Data.MapRoutePoint p in points)
                {
                    if (p.Lat < minLat)
                    {
                        minLat = p.Lat;
                    }
                    if (p.Lng < minLng)
                    {
                        minLng = p.Lng;
                    }
                    if (p.Lat > maxLat)
                    {
                        maxLat = p.Lat;
                    }
                    if (p.Lng > maxLng)
                    {
                        maxLng = p.Lng;
                    }
                }
                route.LatMax = maxLat;
                route.LatMin = minLat;
                route.LngMax = maxLng;
                route.LngMin = minLng;
                // Cull points until there are 100 or less points to make the encoded polyline fit the 512 bytes
                int len = 100;
                IList <Affine.Data.MapRoutePoint> pointCopy = atiGMapRoute.MapRoutePoints.Select(mp => new Affine.Data.MapRoutePoint()
                {
                    Lat = mp.Lat, Lng = mp.Lng, Order = mp.Order
                }).ToList <Affine.Data.MapRoutePoint>();
                pointCopy = CullPoints(pointCopy, len);
                route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                while (route.PolyLineEncoding.Length > 512)
                {
                    len       = len / 2;
                    pointCopy = CullPoints(pointCopy, len);
                    route.PolyLineEncoding = Affine.Utils.PolylineEncoder.createEncodings(pointCopy, 17, 1)["encodedPoints"].ToString();
                }
                entities.SaveChanges();
                MapRoute passback = entities.MapRoutes.Where(m => m.UserSetting.Id == this.UserSettings.Id && m.PortalKey == this.PortalId).OrderByDescending(m => m.Id).FirstOrDefault();
                // routes creater needs the route to show up in their route list now.
                User2MapRouteFav fav = new User2MapRouteFav()
                {
                    MapRoute        = passback,
                    UserSettingsKey = UserSettings.Id
                };
                entities.AddToUser2MapRouteFav(fav);
                entities.SaveChanges();

                Affine.Data.json.MapRoute mr = new Affine.Data.json.MapRoute()
                {
                    Id = passback.Id, Name = passback.Name, RouteDistance = passback.RouteDistance
                };
                RadAjaxManager1.ResponseScripts.Add(" setSelectedMap(" + passback.Id + ", '" + passback.Name + "', " + passback.RouteDistance + ", ''); ");
                break;
            }
            // save and close  RadAjaxManager1.ResponseScripts.Add();  /
        }