示例#1
0
        /// <summary>
        /// Adds a point.
        /// </summary>
        /// <returns>The point.</returns>
        /// <param name="coordinate">Coordinate.</param>
        /// <param name="sizePixels">Size pixels.</param>
        /// <param name="color"></param>
        public void AddPoint(GeoCoordinate coordinate, float sizePixels, int color)
        {
            // update envelope.
            if (_envelope == null)
            { // create initial envelope.
                _envelope = new GeoCoordinateBox(coordinate, coordinate);
            }
            // also include the current point.
            _envelope.ExpandWith(coordinate);

            double[] projectedCoordinates = _projection.ToPixel(coordinate);
            uint     pointId = _scene.AddPoint(projectedCoordinates[0], projectedCoordinates[1]);

            _scene.AddStylePoint(pointId, 0, float.MinValue, float.MaxValue, color, sizePixels);
            this.RaiseLayerChanged();
        }
示例#2
0
        /// <summary>
        /// Adds a new OsmSharpRoute.
        /// </summary>
        /// <param name="route">Stream.</param>
        /// <param name="argb">Stream.</param>
        /// <param name="width"></param>
        public void AddRoute(Route route, int argb, double width)
        {
            if (route != null &&
                route.Segments != null &&
                route.Segments.Length > 0)
            { // there are entries.
                // get x/y.
                var x = new double[route.Segments.Length];
                var y = new double[route.Segments.Length];
                for (int idx = 0; idx < route.Segments.Length; idx++)
                {
                    x[idx] = _projection.LongitudeToX(
                        route.Segments[idx].Longitude);
                    y[idx] = _projection.LatitudeToY(
                        route.Segments[idx].Latitude);

                    // update envelope.
                    if (_envelope == null)
                    { // create initial envelope.
                        _envelope = new GeoCoordinateBox(
                            new GeoCoordinate(route.Segments[idx].Latitude, route.Segments[idx].Longitude),
                            new GeoCoordinate(route.Segments[idx].Latitude, route.Segments[idx].Longitude));
                    }
                    // also include the current point.
                    _envelope.ExpandWith(new GeoCoordinate(route.Segments[idx].Latitude, route.Segments[idx].Longitude));
                }

                // set the default color if none is given.
                var color    = SimpleColor.FromArgb(argb);
                var pointsId = _scene.AddPoints(x, y);
                if (pointsId.HasValue)
                {
                    _scene.AddStyleLine(pointsId.Value, 0, float.MinValue, float.MaxValue,
                                        color.Value, (float)width, Renderer.Primitives.LineJoin.Round, null);
                }
            }

            this.RaiseLayerChanged();
        }
示例#3
0
        /// <summary>
        /// Adds the given node.
        /// </summary>
        /// <param name="node"></param>
        public override void AddNode(Node node)
        {
            if (!_preIndexMode)
            {
                if (_nodesToCache != null &&
                    _nodesToCache.Contains(node.Id.Value))
                { // cache this node?
                    _dataCache.AddNode(node);
                }

                if (_preIndex != null && _preIndex.Contains(node.Id.Value))
                { // only save the coordinates for relevant nodes.
                  // save the node-coordinates.
                  // add the relevant nodes.

                    if (_box == null || _box.Contains(new GeoCoordinate((float)node.Latitude.Value, (float)node.Longitude.Value)))
                    { // the coordinate is acceptable.
                        _coordinates[node.Id.Value] = new GeoCoordinateSimple()
                        {
                            Latitude  = (float)node.Latitude.Value,
                            Longitude = (float)node.Longitude.Value
                        };
                        if (_coordinates.Count == _preIndex.Count)
                        {
                            _preIndex.Clear();
                            _preIndex = null;
                        }

                        if (_bounds == null)
                        { // create bounds.
                            _bounds = new GeoCoordinateBox(
                                new GeoCoordinate(node.Latitude.Value, node.Longitude.Value),
                                new GeoCoordinate(node.Latitude.Value, node.Longitude.Value));
                        }
                        else
                        { // expand bounds.
                            _bounds.ExpandWith(
                                new GeoCoordinate(node.Latitude.Value, node.Longitude.Value));
                        }

                        // add the node as a possible restriction.
                        if (_interpreter.IsRestriction(OsmGeoType.Node, node.Tags))
                        { // tests quickly if a given node is possibly a restriction.
                            List <Vehicle> vehicles = _interpreter.CalculateRestrictions(node);
                            if (vehicles != null &&
                                vehicles.Count > 0)
                            {                                                               // add all the restrictions.
                                uint   vertexId    = this.AddRoadNode(node.Id.Value).Value; // will always exists, has just been added to coordinates.
                                uint[] restriction = new uint[] { vertexId };
                                if (vehicles.Contains(null))
                                { // restriction is valid for all vehicles.
                                    _dynamicGraph.AddRestriction(restriction);
                                }
                                else
                                { // restriction is restricted to some vehicles only.
                                    foreach (Vehicle vehicle in vehicles)
                                    {
                                        _dynamicGraph.AddRestriction(vehicle, restriction);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }