Exemple #1
0
        public static Bitmap ToStaticMapImage(List <Ubicacion> model, dynamic viewBag)
        {
            //if (model == null || model.Count == 0) return new Bitmap(1, 1);
            string url = Ubicacion.ToStaticMap(model, viewBag);

            try
            {
                using (WebClient request = new WebClient())
                {
                    byte[] data  = request.DownloadData(url);
                    Bitmap image = null;
                    using (Stream stream = new MemoryStream(data))
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        image = Bitmap.FromStream(stream) as Bitmap;
                    }
                    return(image);
                }
            }
            catch
            {
                return(new Bitmap(viewBag.MapWidth, viewBag.MapHeight));
            }
        }
Exemple #2
0
        public static List <Ubicacion> Recorrido(List <AgenteUbicacion> list, double routedDistance)
        {
            List <Ubicacion> model = new List <Ubicacion>();

            for (int i = list.Count - 1; i > 0; i--)
            {
                var actual   = list[i];
                var anterior = list[i - 1];

                if (actual.Latitud == anterior.Latitud && actual.Longitud == anterior.Longitud)
                {
                    if (actual.FechaHasta == null)
                    {
                        anterior.FechaHasta = actual.Fecha;
                    }
                    else
                    {
                        anterior.FechaHasta = actual.FechaHasta;
                    }

                    list.Remove(actual);
                }
                else
                {
                    var distance = Ubicacion.Distance(actual.Longitud ?? 0, actual.Latitud ?? 0, anterior.Longitud ?? 0, anterior.Latitud ?? 0);

                    if (distance < routedDistance)//0.050)
                    {
                        if (actual.FechaHasta == null)
                        {
                            anterior.FechaHasta = actual.Fecha;
                        }
                        else
                        {
                            anterior.FechaHasta = actual.FechaHasta;
                        }

                        list.Remove(actual);
                    }
                }
            }

            foreach (var item in list)
            {
                string titulo = String.Empty;
                string tiempo = String.Empty;

                if (item.FechaHasta == null || item.Fecha.ToString("HH:mm") == item.FechaHasta.Value.ToString("HH:mm"))
                {
                    titulo = item.Fecha.ToString("HH:mm");
                }
                else
                {
                    titulo = String.Format("{0} - {1}", item.Fecha.ToString("HH:mm"), item.FechaHasta.Value.ToString("HH:mm"));

                    var dif = item.FechaHasta.Value - item.Fecha;

                    if (dif.Hours > 0)
                    {
                        tiempo = String.Format("{0} H.", dif.Hours);
                    }

                    if (dif.Minutes > 0)
                    {
                        if (!String.IsNullOrEmpty(tiempo))
                        {
                            tiempo += ", ";
                        }

                        tiempo += String.Format("{0} Min.", dif.Minutes);
                    }

                    if (!String.IsNullOrEmpty(tiempo))
                    {
                        titulo = String.Format("{0} ({1})", titulo, tiempo);
                    }
                }

                model.Add(new Ubicacion()
                {
                    Titulo   = titulo,
                    Latitud  = item.Latitud,
                    Longitud = item.Longitud
                });
            }

            SetMarkers(model);

            return(model);
        }