Exemplo n.º 1
0
        public void AddCustomRoute(List<GeoCoordinate> route, Color? color, int width)
        {
            Color route_color;
            if (color != null && color.HasValue)
            {
                route_color = color.Value;
            }
            else
            {
                route_color = this.RandomColor();
            }

            ElementLine line = new ElementLine(
                new ShapePolyLineF<GeoCoordinate, GeoCoordinateBox, GeoCoordinateLine>(
                    Tools.Math.Geo.Factory.PrimitiveGeoFactory.Instance,
                    route.ToArray<GeoCoordinate>()),
                    route_color.ToArgb(),
                    width, true);
            line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            this.AddElement(line);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a line to this layer.
 /// </summary>
 /// <param name="dot"></param>
 /// <returns></returns>
 public ElementLine AddLine(ElementLine line, GeoCoordinate dot, bool create_dot)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a line to this layer.
        /// </summary>
        /// <param name="dot"></param>
        /// <returns></returns>
        public ElementLine AddLine(ElementLine line, GeoCoordinate dot, bool create_dot)
        {
            lock (_elements)
            {
                // remove the old line.
                _elements.Remove(line);
            }

            // add new dot.
            if (create_dot)
            {
                this.AddDot(dot);
            }

            // create polyline.
            List<GeoCoordinate> coordinates = new List<GeoCoordinate>();
            coordinates.AddRange(line.Line.Points);
            coordinates.Add(dot);

            ShapePolyLineF<GeoCoordinate, GeoCoordinateBox, GeoCoordinateLine> polyline
                = new ShapePolyLineF<GeoCoordinate, GeoCoordinateBox, GeoCoordinateLine>(
                    PrimitiveGeoFactory.Instance,
                    coordinates.ToArray());

            // create the line element.
            ElementLine element = new ElementLine(
                polyline,
                Color.Black.ToArgb(),
                0.0002f,
                true);

            lock (_elements)
            {
                _elements.Add(element);
            }

            return element;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a line to this layer.
        /// </summary>
        /// <param name="dot"></param>
        /// <returns></returns>
        public ElementLine AddLine(
            GeoCoordinate dot1,
            GeoCoordinate dot2, 
            bool create_dot,
            double width,
            bool width_fixed,
            int color)
        {
            // add new dot.
            if (create_dot)
            {
                this.AddDot(dot1);
                this.AddDot(dot2);
            }

            // create polyline.
            List<GeoCoordinate> coordinates = new List<GeoCoordinate>();
            coordinates.Add(dot1);
            coordinates.Add(dot2);
            ShapePolyLineF<GeoCoordinate, GeoCoordinateBox, GeoCoordinateLine> line
                = new ShapePolyLineF<GeoCoordinate, GeoCoordinateBox, GeoCoordinateLine>(
                    PrimitiveGeoFactory.Instance,
                    coordinates.ToArray());

            // create the line element.
            ElementLine element = new ElementLine(
                line,
                color,
                width,
                width_fixed);
            //ElementLine element = new ElementLine(
            //    line,
            //    Color.FromArgb(230,Color.Blue).ToArgb(),
            //    0.0002f,
            //    true);

            lock (_elements)
            {
                _elements.Add(element);
            }

            return element;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns all the elements in this layer.
        /// </summary>
        /// <returns></returns>
        public IList<IElement> GetElements(
            GeoCoordinateBox box,
            double zoom_factor)
        {
            // get objects from source.
            IList<OsmGeo> objects = _source.Get(box, null);

            // convert objects to elements using interpreter.
            List<IElement> elements = new List<IElement>();
            Interpreter.Interpreter interpreter = new OsmSharp.Osm.Interpreter.Interpreter();
            foreach (OsmGeo geo in objects)
            {
                if (geo is OsmGeo)
                {
                    if (geo is Node)
                    {
                        Node n = geo as Node;

                        if (n.Tags.ContainsKey("type"))
                        {
                            //ElementDot dot = new ElementDot(
                            //    Color.Red.ToArgb(),
                            //    0.0002f,
                            //    new OsmSharp.Tools.Math.Shapes.ShapeDotF<GeoCoordinate, GeoCoordinateBox>(
                            //        n.Coordinate));
                            //elements.Add(dot);
                        }
                    }
                    else if (geo is Way)
                    {
                        Way w = geo as Way;
                        ElementLine line;
                        if (w.Tags.ContainsKey("metadata_name"))
                        {
                            Color transparent_color = Color.FromArgb(230,_default);
                            line = new ElementLine(
                                new ShapePolyLineF<GeoCoordinate, GeoCoordinateBox, GeoCoordinateLine>(
                                    PrimitiveGeoFactory.Instance,
                                    w.GetCoordinates().ToArray<GeoCoordinate>()),
                                transparent_color.ToArgb(),
                                4f,
                                true);
                            elements.Add(line);
                        }
                    }
                }
            }

            // return result.
            return elements;
        }
Exemplo n.º 6
0
        private GeoCoordinateBox DoForRoute(List<GeoCoordinate> route, double distance_arrow, Color route_color, int width, int min_zoom, int max_zoom)
        {
            double distance = 0;

            GeoCoordinate previous_point = route[0];

            List<GeoCoordinate> points = new List<GeoCoordinate>();
            points.Add(previous_point);
            for (int idx = 1; idx < route.Count; idx++)
            {
                GeoCoordinate current_point = route[idx];
                points.Add(current_point);

                // calculate distance.
                distance = distance + previous_point.DistanceReal(
                        current_point).Value;

                if (distance > distance_arrow)
                {
                    ElementLine line = new ElementLine(
                        new ShapePolyLineF<GeoCoordinate, GeoCoordinateBox, GeoCoordinateLine>(
                            Tools.Math.Geo.Factory.PrimitiveGeoFactory.Instance,
                            points.ToArray<GeoCoordinate>()),
                            route_color.ToArgb(),
                            width, true);
                    line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                    line.MinZoom = min_zoom;
                    line.MaxZoom = max_zoom;
                    this.AddElement(line);

                    GeoCoordinate last_point = points[points.Count - 1];
                    points.Clear();
                    points.Add(last_point);
                    distance = 0;
                }

                previous_point = current_point;
            }
            if (points.Count > 0)
            {
                ElementLine line = new ElementLine(
                    new ShapePolyLineF<GeoCoordinate, GeoCoordinateBox, GeoCoordinateLine>(
                        Tools.Math.Geo.Factory.PrimitiveGeoFactory.Instance,
                        points.ToArray<GeoCoordinate>()),
                        route_color.ToArgb(),
                        width, true);
                line.MinZoom = min_zoom;
                line.MaxZoom = max_zoom;
                line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                this.AddElement(line);
            }
            return new GeoCoordinateBox(route);
        }