예제 #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.fragment_gpx, container, false);

            mGpxData                = new GpxData();
            mRecycleView            = view.FindViewById <RecyclerView>(Resource.Id.recyclerView);
            mRecycleView.Visibility = ViewStates.Visible;

            mLayoutManager = new LinearLayoutManager(view.Context);
            mRecycleView.SetLayoutManager(mLayoutManager);
            mAdapter = new GpxAdapter(mGpxData);
            //mAdapter.ItemClick += GpxAdapter.MAdapter_ItemClick;
            mRecycleView.SetAdapter(mAdapter);

            return(view);
        }
예제 #2
0
        public ActionResult Index(HttpPostedFileBase file)
        {
            var folderPath = Server.MapPath("~/UploadedFiles/" + Session["UserId"]);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }
            ViewBag.maps = mapListService.GetMapList();
            ViewBag.key  = config.BING_KEY;
            var gpxData = new GpxData();

            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var filePath = Path.Combine(folderPath, fileName);
                    file.SaveAs(filePath);
                    GpxOperationsService gpxOperationsService = new GpxOperationsService(filePath, fileName);
                    gpxData = gpxOperationsService.GpxData;
                }
                catch (Exception e)
                {
                    gpxData = defaultGpxDataService.GetDefaultGpxData();
                    Log.Error(e.Message);
                }
            }
            else
            {
                gpxData = defaultGpxDataService.GetDefaultGpxData();
                Log.Error("File content length error");
            }

            if (gpxData.Lat.Count > 1)
            {
                TempData["Message"] = Resources.Resource.Sent;
            }
            else
            {
                TempData["Message"] = Resources.Resource.Error;
            }
            return(View(gpxData));
        }
        public GpxData GetDefaultGpxData()
        {
            GpxData gpxData = new GpxData
            {
                Lat = new List <double> {
                    51.91
                },
                Lng = new List <double> {
                    19.13
                },
                Distances = new List <double> {
                    0.0
                },
                Elevations = new List <double> {
                    0.0
                }
            };

            return(gpxData);
        }
예제 #4
0
        // GET: GpxRoutes/Details/5
        public ActionResult Details(int?id)
        {
            MapListService mapListService = new MapListService();

            ViewBag.maps = mapListService.GetMapList();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GpxRoute gpxRoute = db.GpxRoutes.Find(id);

            ViewBag.id  = gpxRoute.Id;
            ViewBag.key = config.BING_KEY;
            GpxOperationsService gpxOperationsService = new GpxOperationsService(gpxRoute.FilePath, gpxRoute.Name);
            GpxData gpxData = gpxOperationsService.GpxData;

            if (gpxRoute == null)
            {
                return(HttpNotFound());
            }
            return(View(gpxData));
        }
예제 #5
0
 public GpxAdapter(GpxData gpxData)
 {
     mGpxData = gpxData;
 }
예제 #6
0
        private void ReadGpx(string filePath, string fileName)
        {
            List <double>   lat        = new List <double>();
            List <double>   lng        = new List <double>();
            List <double>   elevations = new List <double>();
            List <DateTime> timeList   = new List <DateTime>();

            NumberFormatInfo numberFormatInfo = new CultureInfo("en-US", false).NumberFormat;

            numberFormatInfo.NumberDecimalSeparator = ".";

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(XmlSerializeGpx.Gpx), "http://www.topografix.com/GPX/1/1");

            try
            {
                FileStream          fileStream = new FileStream(filePath, FileMode.Open);
                XmlReader           reader     = XmlReader.Create(fileStream);
                XmlSerializeGpx.Gpx gpxObj     = (XmlSerializeGpx.Gpx)xmlSerializer.Deserialize(reader);
                foreach (XmlSerializeGpx.Trkpt track in gpxObj.trk.trkseg.trkpt)
                {
                    lat.Add(track.lat);
                    lng.Add(track.lon);
                    elevations.Add(track.ele);
                    timeList.Add(track.time);
                }

                GpxData = new GpxData
                {
                    Lat        = lat,
                    Lng        = lng,
                    Distances  = CalculateDistances(lat, lng),
                    Elevations = CalculateElevations(elevations),
                    Name       = fileName,
                    Distance   = CalculateDistance(lat, lng).ToString("N", numberFormatInfo),
                    Elevation  = CalculateElevation(elevations).ToString("N", numberFormatInfo),
                    Time       = CalculateTime(timeList).ToString(@"hh\:mm\:ss"),
                    SentDate   = DateTime.Now.ToString("d", CultureInfo.CreateSpecificCulture("pl"))
                };

                var userId  = int.Parse(HttpContext.Current.Session["UserId"].ToString());
                var context = new GpxContext();
                var route   = new GpxRoute
                {
                    Name      = GpxData.Name,
                    Distance  = GpxData.Distance,
                    Time      = GpxData.Time,
                    Elevation = GpxData.Elevation,
                    SentDate  = GpxData.SentDate,
                    FilePath  = filePath,
                    MapUrl    = PrepareUrl(lat, lng),
                    UserId    = userId
                };

                if (!context.GpxRoutes.Any(r => r.Name == fileName &&
                                           r.UserId == userId &&
                                           r.Elevation == GpxData.Elevation &&
                                           r.Time == GpxData.Time &&
                                           r.Distance == GpxData.Distance))
                {
                    context.GpxRoutes.Add(route);
                }
                context.SaveChanges();

                fileStream.Close();
            }
            catch (Exception e)
            {
                var defaultGpxDataService = new DefaultGpxDataService();
                GpxData = defaultGpxDataService.GetDefaultGpxData();
                Log.Error(e.Message);
            }
        }