Exemplo n.º 1
0
        //shows an airport
        private void showAirport(Airport airport, Panel panelMap, int zoom, Point margin)
        {
            Point pos = GraphicsHelpers.WorldToTilePos(airport.Profile.Coordinates, zoom);

            Point p = new Point(pos.X * ImageSize - margin.X * ImageSize, pos.Y * ImageSize - margin.Y * ImageSize);

            if (p.X < panelMap.Width)
            {
                panelMap.Children.Add(createPin(p, airport));
            }
        }
Exemplo n.º 2
0
        //shows a route
        private void showRoute(Route route, Panel panelMap, int zoom, Point margin, Boolean isStopoverRoute = false, Airline airline = null)
        {
            if (route.HasStopovers)
            {
                foreach (Route leg in route.Stopovers.SelectMany(s => s.Legs))
                {
                    showRoute(leg, panelMap, zoom, margin, true, route.Airline);
                }
            }
            else
            {
                Point pos = GraphicsHelpers.WorldToTilePos(route.Destination1.Profile.Coordinates, zoom);

                Point p = new Point(pos.X * ImageSize - margin.X * ImageSize, pos.Y * ImageSize - margin.Y * ImageSize);

                if (p.X < panelMap.Width)
                {
                    panelMap.Children.Add(createPin(p, route.Destination1));
                }

                pos = GraphicsHelpers.WorldToTilePos(route.Destination2.Profile.Coordinates, zoom);

                p = new Point(pos.X * ImageSize - margin.X * ImageSize, pos.Y * ImageSize - margin.Y * ImageSize);

                if (p.X < panelMap.Width)
                {
                    panelMap.Children.Add(createPin(p, route.Destination2));
                }

                if (airline == null)
                {
                    airline = route.Airline;
                }

                createRouteLine(route.Destination1, route.Destination2, panelMap, zoom, margin, airline, isStopoverRoute);
            }
        }
Exemplo n.º 3
0
        //creates the map for coordinates
        private void showMap(GeoCoordinate coordinates, Boolean isAirport)
        {
            this.Zoom = 3;


            Canvas c = new Canvas();

            c.Width  = this.Width;
            c.Height = this.Height;


            StringReader stringReader = new StringReader(GeneralHelpers.BigMapXaml);
            XmlReader    xmlReader    = XmlReader.Create(stringReader);

            Canvas panelMap = (Canvas)XamlReader.Load(xmlReader);


            Point pos = GraphicsHelpers.WorldToTilePos(coordinates, this.Zoom);

            Point p = new Point(pos.X * ImageSize, pos.Y * ImageSize);


            double tMapSize = Math.Sqrt(panelMap.Children.Count) * ImageSize;

            double x = p.X - this.Width / 2;
            double y = p.Y - this.Height / 2;

            if (x < 0)
            {
                x = 0;
            }
            if (y < 0)
            {
                y = 0;
            }
            if (x + this.Width > tMapSize)
            {
                x = tMapSize - this.Width;
            }
            if (y + this.Height > tMapSize)
            {
                y = tMapSize - this.Height;
            }

            //panelMap.ClipToBounds = true;

            panelMap.Width  = this.Width;
            panelMap.Height = this.Height;

            if (isAirport)
            {
                panelMap.Children.Add(createPin(p, Airports.GetAirport(coordinates)));
            }
            else
            {
                panelMap.Children.Add(createPin(p));
            }


            panelMap.Clip = new RectangleGeometry(new Rect(x, y, this.Width, this.Height));
            // panelMap.ClipToBounds = false;

            Canvas.SetLeft(panelMap, -x);
            Canvas.SetTop(panelMap, -y);
            c.Children.Add(panelMap);
            c.ClipToBounds = true;

            this.Content = c;
        }
Exemplo n.º 4
0
        //shows the map for a list of airport with specific coordinates in focus
        private void showMap(List <Airport> airports, int zoom, GeoCoordinate focused)
        {
            double px, py;

            if (focused != null)
            {
                Point pos = GraphicsHelpers.WorldToTilePos(focused, zoom);

                px = Math.Max(1, pos.X);
                py = Math.Max(1, pos.Y);
            }
            else
            {
                px = 1;
                py = 1;
            }

            Canvas panelMap = new Canvas();

            Canvas panelMainMap = new Canvas();

            panelMainMap.Width = 2 * ImageSize;

            for (int x = 0; x < 2; x++)
            {
                for (int y = 0; y < 2; y++)
                {
                    string name = string.Format(@"{0}\{1}\{2}.png", zoom, x - 1 + (int)px, y - 1 + (int)py);

                    Image imgMap = new Image();
                    imgMap.Width  = ImageSize;
                    imgMap.Height = ImageSize;
                    imgMap.Source = new BitmapImage(new Uri(AppSettings.getDataPath() + "\\graphics\\maps\\" + name, UriKind.RelativeOrAbsolute));
                    RenderOptions.SetBitmapScalingMode(imgMap, BitmapScalingMode.HighQuality);

                    Canvas.SetTop(imgMap, y * ImageSize);
                    Canvas.SetLeft(imgMap, x * ImageSize);

                    panelMainMap.Children.Add(imgMap);
                }
            }
            ScaleTransform transform = new ScaleTransform();

            transform.ScaleX             = 1.5;
            transform.ScaleY             = 1.5;
            panelMainMap.RenderTransform = transform;

            StackPanel sidePanel = createAirportSizeSidePanel();

            Canvas.SetTop(sidePanel, 0);
            Canvas.SetLeft(sidePanel, this.MapSize);

            panelMap.Children.Add(panelMainMap);
            panelMap.Children.Add(sidePanel);


            foreach (Airport airport in airports)
            {
                showAirport(airport, panelMainMap, zoom, new Point((int)px - 1, (int)py - 1));
            }

            this.Content = panelMap;
        }
Exemplo n.º 5
0
        //creates the line between two airports
        private void createRouteLine(Airport a1, Airport a2, Panel panelMap, int zoom, Point margin, Airline airline, Boolean isStopoverRoute = false)
        {
            DoubleCollection dottedDash = new DoubleCollection();

            dottedDash.Add(2);
            dottedDash.Add(2);

            int d = 50;

            double distance = MathHelpers.GetDistance(a1, a2);

            GeoCoordinate c1 = a1.Profile.Coordinates;

            int i = 0;

            System.Windows.Shapes.Path flightPath = new System.Windows.Shapes.Path();
            flightPath.Stroke          = new AirlineBrushConverter().Convert(airline) as SolidColorBrush;
            flightPath.StrokeThickness = 1;
            flightPath.Fill            = new AirlineBrushConverter().Convert(airline) as SolidColorBrush;

            GeometryGroup flightGeometryGroup = new GeometryGroup();


            while (i < distance)
            {
                GeoCoordinate c3 = MathHelpers.GetRoutePoint(c1, a2.Profile.Coordinates, d);

                Point pos1 = GraphicsHelpers.WorldToTilePos(c1, zoom);
                Point pos2 = GraphicsHelpers.WorldToTilePos(c3, zoom);

                /*
                 * Line line = new Line();
                 *
                 * if (isStopoverRoute)
                 *  line.StrokeDashArray = dottedDash;
                 * /*
                 * line.Stroke = new AirlineBrushConverter().Convert(airline) as SolidColorBrush;
                 * line.X1 = Math.Min(panelMap.Width, pos1.X * ImageSize - margin.X * ImageSize);
                 * line.X2 = Math.Min(panelMap.Width, pos2.X * ImageSize - margin.X * ImageSize);
                 * line.Y1 = pos1.Y * ImageSize - margin.Y * ImageSize;
                 * line.Y2 = pos2.Y * ImageSize - margin.Y * ImageSize;
                 *
                 * if (Math.Abs(line.X1 - line.X2) > ImageSize)
                 *  line.X2 = (line.X1 - line.X2) < 0 ? 0 : ImageSize * Math.Pow(2,zoom);
                 */
                double x1 = Math.Min(panelMap.Width, pos1.X * ImageSize - margin.X * ImageSize);
                double x2 = Math.Min(panelMap.Width, pos2.X * ImageSize - margin.X * ImageSize);
                double y1 = pos1.Y * ImageSize - margin.Y * ImageSize;
                double y2 = pos2.Y * ImageSize - margin.Y * ImageSize;

                if (Math.Abs(x1 - x2) > ImageSize)
                {
                    x2 = (x1 - x2) < 0 ? 0 : ImageSize *Math.Pow(2, zoom);
                }


                LineGeometry flightGeometry = new LineGeometry();
                flightGeometry.StartPoint = new Point(x1, y1);
                flightGeometry.EndPoint   = new Point(x2, y2);

                flightGeometryGroup.Children.Add(flightGeometry);

                //panelMap.Children.Add(line);

                i += Math.Min(d, (int)(distance - i) + 1);

                c1 = c3;
            }
            flightPath.Data = flightGeometryGroup;
            panelMap.Children.Add(flightPath);
        }