Esempio n. 1
0
        public void ProcessRequest(HttpContext context)
        {
            string file = context.Request.QueryString["File"];

            if (!string.IsNullOrEmpty(file))
            {
                context.Response.ContentType = "application/octet-stream";
                context.Response.TransmitFile(file);
                return;
            }
            string scriptForRoute = context.Request.QueryString["ScriptForRoute"];

            if (!string.IsNullOrEmpty(scriptForRoute))
            {
                string    gpxFile = PathFunctions.GetGpxPathFromRouteName(scriptForRoute);
                GpxParser parser  = Helper.GetGpxParser(gpxFile);
                Helper.GenerateTrackCode(parser, context.Response, false);
                return;
            }
            string routeName = context.Request.QueryString["Route"];
            string imageName = context.Request.QueryString["Image"];

            UploadedImage img    = UploadedImage.FromSession(routeName, imageName);
            string        folder = PathFunctions.GetImagePathFromRouteName(routeName);

            if (img != null)
            {
                img.SaveTo(context.Response);
            }
        }
Esempio n. 2
0
        internal void GenerateProfile(GpxParser parser, string filePath)
        {
            using (Bitmap bmp = new Bitmap(bitmapRect.Width, bitmapRect.Height, PixelFormat.Format32bppPArgb))
            {
                using (Font font = new Font("Tahoma", 10.0f))
                {
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        g.DrawRectangle(Pens.BlueViolet, graphRect);
                        TrackPoint prevPoint = null;
                        Track      t         = parser.Tracks[0];
                        double     currPos   = 0.0;
                        minH = t.MinElevation;
                        maxH = t.MaxElevation;
                        maxW = t.Distance3D;
                        PointF startPoint = GetLogicalPoint(0, minH);

                        foreach (TrackSegment seg in t.Segments)
                        {
                            foreach (TrackPoint tp in seg.ReducedPoints)
                            {
                                if (prevPoint == null)
                                {
                                    prevPoint = tp;
                                    continue;
                                }

                                currPos += tp - prevPoint;
                                PointF endPoint = GetLogicalPoint(currPos, tp.ele);
                                using (Pen p = new Pen(ColorProvider.GetColor(Math.Max(tp.ele, prevPoint.ele), minH, maxH)))
                                    g.DrawLine(p, startPoint, endPoint);
                                prevPoint  = tp;
                                startPoint = endPoint;
                            }
                        }
                        int heightRulerSpacing = Convert.ToInt32((maxH - minH) / 5);                         //suddivido in 5 segmenti
                        heightRulerSpacing = (int)(Math.Ceiling(heightRulerSpacing / 10.0d) * 10);           //arrotondo ai 10 metri

                        double currH = Math.Round(minH / heightRulerSpacing, 0) * heightRulerSpacing;
                        if (currH < minH)
                        {
                            currH += heightRulerSpacing;
                        }
                        StringFormat sf = new StringFormat();
                        sf.LineAlignment = StringAlignment.Far;
                        sf.Alignment     = StringAlignment.Far;

                        g.DrawString(GetHeightLabel(minH), font, Brushes.Red, GetLogicalPoint(0, minH), sf);

                        while (currH < maxH)
                        {
                            PointF p1 = GetLogicalPoint(0, currH);
                            PointF p2 = GetLogicalPoint(maxW, currH);
                            g.DrawLine(Pens.BlueViolet, p1, p2);
                            using (Brush b = new SolidBrush(ColorProvider.GetColor(currH, minH, maxH)))
                                g.DrawString(GetHeightLabel(currH), font, b, p1, sf);
                            currH += heightRulerSpacing;
                        }
                        using (Brush b = new SolidBrush(ColorProvider.GetColor(maxH, minH, maxH)))
                            g.DrawString(GetHeightLabel(maxH), font, b, GetLogicalPoint(0, maxH), sf);


                        sf.Alignment     = StringAlignment.Center;
                        sf.LineAlignment = StringAlignment.Near;
                        int widthRulerSpacing = Convert.ToInt32(maxW / 5);                         //suddivido in 5 segmenti Km
                        widthRulerSpacing = (int)(Math.Ceiling(widthRulerSpacing / 100.0d) * 100); //arrotondo ai 100 metri

                        double currW = widthRulerSpacing;

                        while (currW < maxW)
                        {
                            PointF p1 = GetLogicalPoint(currW, minH);
                            PointF p2 = GetLogicalPoint(currW, maxH);
                            g.DrawLine(Pens.BlueViolet, p1, p2);
                            g.DrawString(GetWidthLabel(currW), font, Brushes.BlueViolet, p1, sf);
                            currW += widthRulerSpacing;
                        }

                        g.DrawString(GetWidthLabel(currW), font, Brushes.BlueViolet, GetLogicalPoint(maxW, minH), sf);

                        g.DrawString("Distanza (Km)", font, Brushes.BlueViolet, graphRect.X + graphRect.Width / 2, graphRect.Bottom + 20, sf);
                        sf.FormatFlags |= StringFormatFlags.DirectionVertical;
                        g.DrawString("Altitudine (m)", font, Brushes.BlueViolet, graphRect.X - 70, graphRect.Top + graphRect.Height / 2, sf);
                    }
                    string path = Path.GetDirectoryName(filePath);
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    bmp.Save(filePath);
                }
            }
        }
Esempio n. 3
0
        internal void GenerateProfile(GpxParser parser, string filePath)
        {
            using (Bitmap bmp = new Bitmap(bitmapRect.Width, bitmapRect.Height, PixelFormat.Format32bppPArgb))
            {
                using (Font font = new Font("Tahoma", 10.0f))
                {
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        g.DrawRectangle(Pens.BlueViolet, graphRect);
                        TrackPoint prevPoint = null;
                        Track t = parser.Tracks[0];
                        double currPos = 0.0;
                        minH = t.MinElevation;
                        maxH = t.MaxElevation;
                        maxW = t.Distance3D;
                        PointF startPoint = GetLogicalPoint(0, minH);

                        foreach (TrackSegment seg in t.Segments)
                        {
                            foreach (TrackPoint tp in seg.ReducedPoints)
                            {
                                if (prevPoint == null)
                                {
                                    prevPoint = tp;
                                    continue;
                                }

                                currPos += tp - prevPoint;
                                PointF endPoint = GetLogicalPoint(currPos, tp.ele);
                                using (Pen p = new Pen(ColorProvider.GetColor(Math.Max(tp.ele, prevPoint.ele), minH, maxH)))
                                    g.DrawLine(p, startPoint, endPoint);
                                prevPoint = tp;
                                startPoint = endPoint;
                            }
                        }
                        int heightRulerSpacing = Convert.ToInt32((maxH - minH) / 5); //suddivido in 5 segmenti
                        heightRulerSpacing = (int)(Math.Ceiling(heightRulerSpacing / 10.0d) * 10);//arrotondo ai 10 metri

                        double currH = Math.Round(minH / heightRulerSpacing, 0) * heightRulerSpacing;
                        if (currH < minH)
                            currH += heightRulerSpacing;
                        StringFormat sf = new StringFormat();
                        sf.LineAlignment = StringAlignment.Far;
                        sf.Alignment = StringAlignment.Far;

                        g.DrawString(GetHeightLabel(minH), font, Brushes.Red, GetLogicalPoint(0, minH), sf);

                        while (currH < maxH)
                        {
                            PointF p1 = GetLogicalPoint(0, currH);
                            PointF p2 = GetLogicalPoint(maxW, currH);
                            g.DrawLine(Pens.BlueViolet, p1, p2);
                            using (Brush b = new SolidBrush(ColorProvider.GetColor(currH, minH, maxH)))
                                g.DrawString(GetHeightLabel(currH), font, b, p1, sf);
                            currH += heightRulerSpacing;
                        }
                        using (Brush b = new SolidBrush(ColorProvider.GetColor(maxH, minH, maxH)))
                            g.DrawString(GetHeightLabel(maxH), font, b, GetLogicalPoint(0, maxH), sf);

                        sf.Alignment = StringAlignment.Center;
                        sf.LineAlignment = StringAlignment.Near;
                        int widthRulerSpacing = Convert.ToInt32(maxW / 5); //suddivido in 5 segmenti Km
                        widthRulerSpacing = (int)(Math.Ceiling(widthRulerSpacing / 100.0d) * 100);//arrotondo ai 100 metri

                        double currW = widthRulerSpacing;

                        while (currW < maxW)
                        {
                            PointF p1 = GetLogicalPoint(currW, minH);
                            PointF p2 = GetLogicalPoint(currW, maxH);
                            g.DrawLine(Pens.BlueViolet, p1, p2);
                            g.DrawString(GetWidthLabel(currW), font, Brushes.BlueViolet, p1, sf);
                            currW += widthRulerSpacing;

                        }

                        g.DrawString(GetWidthLabel(currW), font, Brushes.BlueViolet, GetLogicalPoint(maxW, minH), sf);

                        g.DrawString("Distanza (Km)", font, Brushes.BlueViolet, graphRect.X + graphRect.Width / 2, graphRect.Bottom + 20, sf);
                        sf.FormatFlags |= StringFormatFlags.DirectionVertical;
                        g.DrawString("Altitudine (m)", font, Brushes.BlueViolet, graphRect.X - 70, graphRect.Top + graphRect.Height / 2, sf);
                    }
                    string path = Path.GetDirectoryName(filePath);
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);
                    bmp.Save(filePath);
                }
            }
        }
Esempio n. 4
0
    public static GpxParser GetGpxParser(string gpxPath)
    {
        gpxPath = gpxPath.ToLower().Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
        GpxParser parser = HttpContext.Current.Cache[gpxPath] as GpxParser;
        if (parser == null)
        {
            if (!File.Exists(gpxPath))
                return null;
            parser = new GpxParser();
            parser.Parse(gpxPath);

            HttpContext.Current.Cache.Add(
                gpxPath,
                parser,
                new CacheDependency(new string[] { gpxPath, HttpContext.Current.Server.MapPath("Map.aspx") }),
                Cache.NoAbsoluteExpiration,
                Cache.NoSlidingExpiration,
                CacheItemPriority.Normal,
                null);
        }
        return parser;
    }
Esempio n. 5
0
    public static void GenerateTrackCode(GpxParser parser, HttpResponse response, bool addScriptTags)
    {
        if (addScriptTags)
            response.Write("<script type=\"text/javascript\">\r\n");
        response.Write("function addTracks(){\r\n");

        if (parser != null)
        {
            foreach (Track trk in parser.Tracks)
            {
                response.Write(string.Format(@"
                track = [];
                track['name'] = '{0}';
                track['desc'] = '{1}';
                track['clickable'] = true;
                track['width'] = 3;
                track['opacity'] = 0.9;
                track['outline_color'] = '#000000';
                track['outline_width'] = 0;
                track['fill_color'] = '#E60000';
                track['fill_opacity'] = 0;

                trkSeg = [];
                ",
                   trk.Name,
                   trk.Description));

                foreach (TrackSegment seg in trk.Segments)
                {
                    TrackPoint[] reducedPoints = seg.ReducedPoints;
                    for (int i = 0; i < reducedPoints.Length - 1; i++)
                    {
                        TrackPoint p1 = reducedPoints[i];
                        TrackPoint p2 = reducedPoints[i + 1];

                        string color = ColorProvider.GetColorString(p1.ele, parser.MinElevation, parser.MaxElevation);
                        //devo usare InvariantCulture per avere il punto come separatore dei decimali
                        response.Write(string.Format(
                            "trkSeg.push({{ color:'{0}', 'p1': {{ 'lat':{1}, 'lon': {2} }}, 'p2': {{ 'lat':{3}, 'lon': {4} }} }});\r\n",
                            color,
                            p1.lat.ToString(System.Globalization.CultureInfo.InvariantCulture),
                            p1.lon.ToString(System.Globalization.CultureInfo.InvariantCulture),
                            p2.lat.ToString(System.Globalization.CultureInfo.InvariantCulture),
                            p2.lon.ToString(System.Globalization.CultureInfo.InvariantCulture)
                            ));

                    }
                }

                response.Write("GV_Draw_Track(trkSeg);");
            }
        }
        response.Write("}\r\n");
        if (addScriptTags)
            response.Write("</script>\r\n");
    }
Esempio n. 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string routeName = Request.QueryString["Route"];

            if (!IsPostBack)
            {
                Route r = DBHelper.GetRoute(routeName);
                if (r != null)
                {
                    string gpxFile = PathFunctions.GetGpxPathFromRouteName(routeName);

                    parser = Helper.GetGpxParser(gpxFile);
                    if (parser != null)
                        parser.LoadPhothos();
                    Title = r.Title;
                }
            }
            bool editMode = Request.QueryString["EditMode"] == "true";
            GenerateCustomOptions(editMode);
            ChooseRoute.Visible = editMode;
            if (editMode && FileUploadGpx.HasFile)
            {
                try
                {
                    GpxParser p = new GpxParser();
                    p.Parse(FileUploadGpx.FileContent);
                    if (p.Tracks.Count == 0)
                        return;

                    parser = p;
                }
                catch
                {
                }

            }

            if (parser == null)
                parser = GpxParser.FromSession(routeName);
            else
                parser.ToSession(routeName);
        }
        finally
        {
           // MapContainer.Visible = parser != null;
        }
    }