コード例 #1
0
    public override void LookToCoordinates(OnlineMapsVector2d coordinates)
    {
        double p1x, p1y, p2x, p2y;

        map.projection.CoordinatesToTile(coordinates.x, coordinates.y, 20, out p1x, out p1y);
        map.projection.CoordinatesToTile(longitude, latitude, 20, out p2x, out p2y);
        rotation = Quaternion.Euler(0, (float)(OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) - 90), 0);
    }
コード例 #2
0
        public Leg(OnlineMapsXML node)
        {
            List <Step> steps = new List <Step>();

            foreach (OnlineMapsXML n in node)
            {
                if (n.name == "step")
                {
                    steps.Add(new Step(n));
                }
                else if (n.name == "duration")
                {
                    duration = new TextValue <int>(n);
                }
                else if (n.name == "duration_in_traffic")
                {
                    duration_in_traffic = new TextValue <int>(n);
                }
                else if (n.name == "distance")
                {
                    distance = new TextValue <int>(n);
                }
                else if (n.name == "start_location")
                {
                    start_location = OnlineMapsXML.GetVector2dFromNode(n);
                }
                else if (n.name == "end_location")
                {
                    end_location = OnlineMapsXML.GetVector2dFromNode(n);
                }
                else if (n.name == "start_address")
                {
                    start_address = n.Value();
                }
                else if (n.name == "end_address")
                {
                    end_address = n.Value();
                }
                else if (n.name == "via_waypoint")
                {
                    via_waypoint = new ViaWaypoint(n);
                }
                else if (n.name == "arrival_time")
                {
                    arrival_time = new TextValueZone <string>(n);
                }
                else if (n.name == "departure_time")
                {
                    departure_time = new TextValueZone <string>(n);
                }
                else
                {
                    Debug.Log("Leg: " + n.name + "\n" + n.outerXml);
                }
            }

            this.steps = steps.ToArray();
        }
コード例 #3
0
ファイル: OnlineMapsVector2d.cs プロジェクト: mevlme44/Java
    public override bool Equals(object other)
    {
        if (!(other is OnlineMapsVector2d))
        {
            return(false);
        }
        OnlineMapsVector2d vector2 = (OnlineMapsVector2d)other;

        return(x.Equals(vector2.x) && y.Equals(vector2.y));
    }
コード例 #4
0
ファイル: OnlineMapsVector2d.cs プロジェクト: mevlme44/Java
 /// <summary>
 /// Linearly interpolates between two vectors.
 /// </summary>
 /// <param name="a">Vector A</param>
 /// <param name="b">Vector B</param>
 /// <param name="t">Interpolant </param>
 /// <returns></returns>
 public static OnlineMapsVector2d Lerp(OnlineMapsVector2d a, OnlineMapsVector2d b, double t)
 {
     if (t < 0)
     {
         t = 0;
     }
     else if (t > 1)
     {
         t = 1;
     }
     return(new OnlineMapsVector2d(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t));
 }
    /// <summary>
    /// Constructor. \n
    /// Use OnlineMapsDirectionStep.TryParse.
    /// </summary>
    /// <param name="node">XMLNode of route</param>
    private OnlineMapsDirectionStep(OnlineMapsXML node)
    {
        start        = node.GetLatLng("start_location");
        end          = node.GetLatLng("end_location");
        duration     = node.Find <int>("duration/value");
        instructions = node.Find <string>("html_instructions");
        GetStringInstructions();
        distance = node.Find <int>("distance/value");

        maneuver = node.Find <string>("maneuver");

        string encodedPoints = node.Find <string>("polyline/points");

        pointsD = OnlineMapsUtils.DecodePolylinePointsD(encodedPoints);
        points  = pointsD.Select(p => (Vector2)p).ToList();
    }
    /// <summary>
    /// Reverse geocodes coordinates, expressed as latitude and longitude to a 3 word address.
    /// </summary>
    /// <param name="key">A valid API key</param>
    /// <param name="coords">Coordinates</param>
    /// <param name="lang">A supported 3 word address language as an ISO 639-1 2 letter code.</param>
    /// <param name="display">Display type</param>
    /// <returns>Query instance.</returns>
    public static OnlineMapsWhat3Words Reverse(string key, OnlineMapsVector2d coords, string lang = null, Display display = Display.full)
    {
        StringBuilder url = new StringBuilder(endpoint).Append("reverse");

        url.Append("?format=json&key=").Append(key);
        url.Append("&coords=").Append(coords.y).Append(",").Append(coords.x);
        if (!string.IsNullOrEmpty(lang))
        {
            url.Append("&lang=").Append(lang);
        }
        if (display != Display.full)
        {
            url.Append("&display=").Append(display);
        }
        return(new OnlineMapsWhat3Words(url));
    }
コード例 #7
0
        /// <summary>
        /// This method is called when a user clicks on a map
        /// </summary>
        private void OnMapClick()
        {
            // Get the coordinates under cursor
            double lng, lat;

            OnlineMapsControlBase.instance.GetCoords(out lng, out lat);

            // Create a new marker under cursor
            OnlineMapsMarkerManager.CreateItem(lng, lat, "Marker " + OnlineMapsMarkerManager.CountItems);

            OnlineMaps map = OnlineMaps.instance;

            // Get the coordinate at the desired distance
            double nlng, nlat;

            OnlineMapsUtils.GetCoordinateInDistance(lng, lat, radiusKM, 90, out nlng, out nlat);

            double tx1, ty1, tx2, ty2;

            // Convert the coordinate under cursor to tile position
            map.projection.CoordinatesToTile(lng, lat, 20, out tx1, out ty1);

            // Convert remote coordinate to tile position
            map.projection.CoordinatesToTile(nlng, nlat, 20, out tx2, out ty2);

            // Calculate radius in tiles
            double r = tx2 - tx1;

            // Create a new array for points
            OnlineMapsVector2d[] points = new OnlineMapsVector2d[segments];

            // Calculate a step
            double step = 360d / segments;

            // Calculate each point of circle
            for (int i = 0; i < segments; i++)
            {
                double px = tx1 + Math.Cos(step * i * OnlineMapsUtils.Deg2Rad) * r;
                double py = ty1 + Math.Sin(step * i * OnlineMapsUtils.Deg2Rad) * r;
                map.projection.TileToCoordinates(px, py, 20, out lng, out lat);
                points[i] = new OnlineMapsVector2d(lng, lat);
            }

            // Create a new polygon to draw a circle
            OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingPoly(points, Color.red, 3));
        }
コード例 #8
0
 public NameLocation(OnlineMapsXML node)
 {
     foreach (OnlineMapsXML n in node)
     {
         if (n.name == "location")
         {
             location = OnlineMapsXML.GetVector2dFromNode(n);
         }
         else if (n.name == "name")
         {
             name = n.Value();
         }
         else
         {
             Debug.Log("NameLocation: " + n.name + "\n" + n.outerXml);
         }
     }
 }
コード例 #9
0
ファイル: OnlineMapsTile.cs プロジェクト: dimatti/maps_test
 /// <summary>
 /// Checks whether the tile at the specified coordinates.
 /// </summary>
 /// <param name="tl">Coordinates of top-left corner.</param>
 /// <param name="br">Coordinates of bottom-right corner.</param>
 /// <returns>True - if the tile at the specified coordinates, False - if not.</returns>
 public bool InScreen(OnlineMapsVector2d tl, OnlineMapsVector2d br)
 {
     if (bottomRight.x < tl.x)
     {
         return(false);
     }
     if (topLeft.x > br.x)
     {
         return(false);
     }
     if (topLeft.y < br.y)
     {
         return(false);
     }
     if (bottomRight.y > tl.y)
     {
         return(false);
     }
     return(true);
 }
コード例 #10
0
 public ViaWaypoint(OnlineMapsXML node)
 {
     foreach (OnlineMapsXML n in node)
     {
         if (n.name == "location")
         {
             location = OnlineMapsXML.GetVector2dFromNode(n);
         }
         else if (n.name == "step_index")
         {
             step_index = n.Value <int>();
         }
         else if (n.name == "step_interpolation")
         {
             step_interpolation = n.Value <double>();
         }
         else
         {
             Debug.Log("ViaWaypoint: " + n.name + "\n" + n.outerXml);
         }
     }
 }
コード例 #11
0
    /// <summary>
    /// Reverse geocodes coordinates, expressed as latitude and longitude to a 3 word address.
    /// </summary>
    /// <param name="key">A valid API key</param>
    /// <param name="coords">Coordinates</param>
    /// <param name="lang">A supported 3 word address language as an ISO 639-1 2 letter code.</param>
    /// <param name="display">Display type</param>
    /// <returns>Query instance.</returns>
    public static OnlineMapsWhat3Words Reverse(string key, OnlineMapsVector2d coords, string lang = null, Display display = Display.full)
    {
        if (string.IsNullOrEmpty(key))
        {
            key = OnlineMapsKeyManager.What3Words();
        }

        StringBuilder url = new StringBuilder(endpoint).Append("reverse");

        url.Append("?format=json&key=").Append(key);
        url.Append("&coords=")
        .Append(coords.y.ToString(OnlineMapsUtils.numberFormat)).Append(",")
        .Append(coords.x.ToString(OnlineMapsUtils.numberFormat));
        if (!string.IsNullOrEmpty(lang))
        {
            url.Append("&lang=").Append(lang);
        }
        if (display != Display.full)
        {
            url.Append("&display=").Append(display);
        }
        return(new OnlineMapsWhat3Words(url));
    }
コード例 #12
0
    private void OnGeocodeComplete(OnlineMapsWWW www)
    {
        if (www.hasError)
        {
            Debug.Log(www.error);
            return;
        }

        OnlineMapsJSONItem json      = OnlineMapsJSON.Parse(www.text);
        OnlineMapsJSONItem firstItem = json["candidates/0"];

        if (firstItem == null)
        {
            return;
        }

        OnlineMapsVector2d center = firstItem["location"].Deserialize <OnlineMapsVector2d>();

        OnlineMapsJSONItem extent = firstItem["extent"];
        double             xmin   = extent.V <double>("xmin"),
                           ymin = extent.V <double>("ymin"),
                           xmax = extent.V <double>("xmax"),
                           ymax = extent.V <double>("ymax");

        Vector2[] points =
        {
            new Vector2((float)xmin, (float)ymin),
            new Vector2((float)xmax, (float)ymax),
        };

        Vector2 c;
        int     zoom;

        OnlineMapsUtils.GetCenterPointAndZoom(points, out c, out zoom);

        OnlineMaps.instance.SetPositionAndZoom(center.x, center.y, zoom);
    }
コード例 #13
0
ファイル: OnlineMapsTile.cs プロジェクト: dimatti/maps_test
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="x">Tile X</param>
    /// <param name="y">Tile Y</param>
    /// <param name="zoom">Tile zoom</param>
    /// <param name="map">Reference to the map</param>
    /// <param name="isMapTile">Should this tile be displayed on the map?</param>
    public OnlineMapsTile(int x, int y, int zoom, OnlineMaps map, bool isMapTile = true)
    {
        remainDownloadsAttempts = countDownloadsAttempts;
        int maxX = 1 << zoom;

        if (x < 0)
        {
            x += maxX;
        }
        else if (x >= maxX)
        {
            x -= maxX;
        }

        this.x    = x;
        this.y    = y;
        this.zoom = zoom;

        _map           = map;
        this.isMapTile = isMapTile;

        double tlx, tly, brx, bry;

        map.projection.TileToCoordinates(x, y, zoom, out tlx, out tly);
        map.projection.TileToCoordinates(x + 1, y + 1, zoom, out brx, out bry);
        topLeft     = new OnlineMapsVector2d(tlx, tly);
        bottomRight = new OnlineMapsVector2d(brx, bry);

        globalPosition = Vector2.Lerp(topLeft, bottomRight, 0.5f);
        key            = OnlineMapsTileManager.GetTileKey(zoom, x, y);

        if (isMapTile)
        {
            map.tileManager.Add(this);
        }
    }
コード例 #14
0
    protected void DrawLineToBuffer(Color32[] buffer, Vector2 bufferPosition, int bufferWidth, int bufferHeight, float zoom, IEnumerable points, Color32 color, float width, bool closed, bool invertY)
    {
        if (color.a == 0)
        {
            return;
        }

        int   izoom     = (int)zoom;
        float zoomScale = 1 - (zoom - izoom) / 2;

        double sx, sy;

        map.projection.CoordinatesToTile(tlx, tly, izoom, out sx, out sy);

        int max = 1 << izoom;

        int w = Mathf.RoundToInt(width);

        double ppx1 = 0;

        float bx1 = bufferPosition.x;
        float bx2 = bx1 + zoomScale * bufferWidth / OnlineMapsUtils.tileSize;
        float by1 = bufferPosition.y;
        float by2 = by1 + zoomScale * bufferHeight / OnlineMapsUtils.tileSize;

        int    valueType   = -1; // 0 - Vector2, 1 - float, 2 - double, 3 - OnlineMapsVector2d
        object firstValue  = null;
        object secondValue = null;
        object v1          = null;
        object v2          = null;
        object v3          = null;
        int    i           = 0;

        lock (points)
        {
            foreach (object p in points)
            {
                if (valueType == -1)
                {
                    firstValue = p;
                    if (p is Vector2)
                    {
                        valueType = 0;
                    }
                    else if (p is float)
                    {
                        valueType = 1;
                    }
                    else if (p is double)
                    {
                        valueType = 2;
                    }
                    else if (p is OnlineMapsVector2d)
                    {
                        valueType = 3;
                    }
                }

                object v4 = v3;
                v3 = v2;
                v2 = v1;
                v1 = p;

                if (i == 1)
                {
                    secondValue = p;
                }

                double p1tx = 0, p1ty = 0, p2tx = 0, p2ty = 0;
                bool   drawPart = false;

                if (valueType == 0)
                {
                    if (i > 0)
                    {
                        Vector2 p1 = (Vector2)v2;
                        Vector2 p2 = (Vector2)v1;

                        map.projection.CoordinatesToTile(p1.x, p1.y, izoom, out p1tx, out p1ty);
                        map.projection.CoordinatesToTile(p2.x, p2.y, izoom, out p2tx, out p2ty);
                        drawPart = true;
                    }
                }
                else if (valueType == 3)
                {
                    if (i > 0)
                    {
                        OnlineMapsVector2d p1 = (OnlineMapsVector2d)v2;
                        OnlineMapsVector2d p2 = (OnlineMapsVector2d)v1;

                        map.projection.CoordinatesToTile(p1.x, p1.y, izoom, out p1tx, out p1ty);
                        map.projection.CoordinatesToTile(p2.x, p2.y, izoom, out p2tx, out p2ty);
                        drawPart = true;
                    }
                }
                else if (i > 2 && i % 2 == 1)
                {
                    if (valueType == 1)
                    {
                        map.projection.CoordinatesToTile((float)v4, (float)v3, izoom, out p1tx, out p1ty);
                        map.projection.CoordinatesToTile((float)v2, (float)v1, izoom, out p2tx, out p2ty);
                    }
                    else if (valueType == 2)
                    {
                        map.projection.CoordinatesToTile((double)v4, (double)v3, izoom, out p1tx, out p1ty);
                        map.projection.CoordinatesToTile((double)v2, (double)v1, izoom, out p2tx, out p2ty);
                    }
                    drawPart = true;
                }

                if (drawPart)
                {
                    if ((p1tx < bx1 && p2tx < bx1) || (p1tx > bx2 && p2tx > bx2))
                    {
                    }
                    else if ((p1ty < by1 && p2ty < by1) || (p1ty > by2 && p2ty > by2))
                    {
                    }
                    else
                    {
                        DrawLinePartToBuffer(buffer, bufferPosition, bufferWidth, bufferHeight, color, sx, sy, p1tx, p1ty, p2tx, p2ty, i, max, ref ppx1, w, invertY, zoomScale);
                    }
                }

                i++;
            }
        }

        if (closed && i > 0)
        {
            double p1tx = 0, p1ty = 0, p2tx = 0, p2ty = 0;

            if (valueType == 0)
            {
                Vector2 p1 = (Vector2)firstValue;
                Vector2 p2 = (Vector2)v1;

                map.projection.CoordinatesToTile(p1.x, p1.y, izoom, out p1tx, out p1ty);
                map.projection.CoordinatesToTile(p2.x, p2.y, izoom, out p2tx, out p2ty);
            }
            else if (valueType == 3)
            {
                OnlineMapsVector2d p1 = (OnlineMapsVector2d)firstValue;
                OnlineMapsVector2d p2 = (OnlineMapsVector2d)v1;

                map.projection.CoordinatesToTile(p1.x, p1.y, izoom, out p1tx, out p1ty);
                map.projection.CoordinatesToTile(p2.x, p2.y, izoom, out p2tx, out p2ty);
            }
            else if (valueType == 1)
            {
                map.projection.CoordinatesToTile((float)firstValue, (float)secondValue, izoom, out p1tx, out p1ty);
                map.projection.CoordinatesToTile((float)v2, (float)v1, izoom, out p2tx, out p2ty);
            }
            else if (valueType == 2)
            {
                map.projection.CoordinatesToTile((double)firstValue, (double)secondValue, izoom, out p1tx, out p1ty);
                map.projection.CoordinatesToTile((double)v2, (double)v1, izoom, out p2tx, out p2ty);
            }

            if ((p1tx < bx1 && p2tx < bx1) || (p1tx > bx2 && p2tx > bx2))
            {
            }
            else if ((p1ty < by1 && p2ty < by1) || (p1ty > by2 && p2ty > by2))
            {
            }
            else
            {
                DrawLinePartToBuffer(buffer, bufferPosition, bufferWidth, bufferHeight, color, sx, sy, p1tx, p1ty, p2tx, p2ty, i, max, ref ppx1, w, invertY, zoomScale);
            }
        }
    }
コード例 #15
0
    private static double[] GetBufferPoints(Vector2 bufferPosition, float zoom, IEnumerable points, out double minX, out double maxX, out double minY, out double maxY)
    {
        int   izoom          = (int)zoom;
        float zoomScale      = 1 - (zoom - izoom) / 2;
        float scaledTileSize = OnlineMapsUtils.tileSize / zoomScale;

        double[] bufferPoints = null;

        int countPoints = points.Cast <object>().Count();

        minX = double.MaxValue;
        maxX = double.MinValue;
        minY = double.MaxValue;
        maxY = double.MinValue;

        int    valueType = -1; // 0 - Vector2, 1 - float, 2 - double, 3 - OnlineMapsVector2d
        object v1        = null;

        int i = 0;

        foreach (object p in points)
        {
            if (valueType == -1)
            {
                if (p is Vector2)
                {
                    valueType    = 0;
                    bufferPoints = new double[countPoints * 2];
                }
                else if (p is float)
                {
                    valueType    = 1;
                    bufferPoints = new double[countPoints];
                }
                else if (p is double)
                {
                    valueType    = 2;
                    bufferPoints = new double[countPoints];
                }
                else if (p is OnlineMapsVector2d)
                {
                    valueType    = 3;
                    bufferPoints = new double[countPoints * 2];
                }
            }

            object v2 = v1;
            v1 = p;

            if (valueType == 0 || valueType == 3)
            {
                double px, py;
                if (valueType == 0)
                {
                    Vector2 point = (Vector2)p;
                    px = point.x;
                    py = point.y;
                }
                else
                {
                    OnlineMapsVector2d point = (OnlineMapsVector2d)p;
                    px = point.x;
                    py = point.y;
                }
                double tx, ty;
                map.projection.CoordinatesToTile(px, py, izoom, out tx, out ty);
                tx = (tx - bufferPosition.x) * scaledTileSize;
                ty = (ty - bufferPosition.y) * scaledTileSize;

                if (tx < minX)
                {
                    minX = tx;
                }
                if (tx > maxX)
                {
                    maxX = tx;
                }
                if (ty < minY)
                {
                    minY = ty;
                }
                if (ty > maxY)
                {
                    maxY = ty;
                }

                bufferPoints[i * 2]     = tx;
                bufferPoints[i * 2 + 1] = ty;
            }
            else if (i % 2 == 1)
            {
                double tx = 0, ty = 0;
                if (valueType == 1)
                {
                    map.projection.CoordinatesToTile((float)v2, (float)v1, izoom, out tx, out ty);
                }
                else if (valueType == 2)
                {
                    map.projection.CoordinatesToTile((double)v2, (double)v1, izoom, out tx, out ty);
                }
                tx = (tx - bufferPosition.x) * scaledTileSize;
                ty = (ty - bufferPosition.y) * scaledTileSize;

                if (tx < minX)
                {
                    minX = tx;
                }
                if (tx > maxX)
                {
                    maxX = tx;
                }
                if (ty < minY)
                {
                    minY = ty;
                }
                if (ty > maxY)
                {
                    maxY = ty;
                }

                bufferPoints[i - 1] = tx;
                bufferPoints[i]     = ty;
            }

            i++;
        }
        return(bufferPoints);
    }
コード例 #16
0
ファイル: OnlineMapsVector2d.cs プロジェクト: mevlme44/Java
 /// <summary>
 /// Returns the squared length of vector
 /// </summary>
 /// <param name="a">Vector</param>
 /// <returns>Squared length of vector</returns>
 public static double SqrMagnitude(OnlineMapsVector2d a)
 {
     return(a.x * a.x + a.y * a.y);
 }
コード例 #17
0
    protected List <Vector2> GetLocalPoints(IEnumerable points, bool closed = false, bool optimize = true)
    {
        double sx, sy;

        int   zoom     = map.zoom;
        float zoomCoof = map.zoomCoof;

        OnlineMapsProjection projection = map.projection;

        projection.CoordinatesToTile(tlx, tly, zoom, out sx, out sy);

        int max     = 1 << zoom;
        int halfMax = max / 2;

        if (localPoints == null)
        {
            localPoints = new List <Vector2>();
        }
        else
        {
            localPoints.Clear();
        }

        double ppx    = 0;
        double scaleX = OnlineMapsUtils.tileSize * OnlineMapsControlBaseDynamicMesh.instance.sizeInScene.x / map.buffer.renderState.width / zoomCoof;
        double scaleY = OnlineMapsUtils.tileSize * OnlineMapsControlBaseDynamicMesh.instance.sizeInScene.y / map.buffer.renderState.height / zoomCoof;

        double prx = 0, pry = 0;

        object v1 = null;
        int    i = -1;
        int    valueType = -1; // 0 - Vector2, 1 - float, 2 - double, 3 - OnlineMapsVector2d
        bool   isOptimized = false;
        double px = 0, py = 0;

        IEnumerator enumerator = points.GetEnumerator();

        while (enumerator.MoveNext())
        {
            i++;

            object p = enumerator.Current;
            if (valueType == -1)
            {
                if (p is Vector2)
                {
                    valueType = 0;
                }
                else if (p is float)
                {
                    valueType = 1;
                }
                else if (p is double)
                {
                    valueType = 2;
                }
                else if (p is OnlineMapsVector2d)
                {
                    valueType = 3;
                }
            }

            object v2 = v1;
            v1 = p;

            bool useValue = false;

            if (valueType == 0)
            {
                Vector2 point = (Vector2)p;
                projection.CoordinatesToTile(point.x, point.y, zoom, out px, out py);
                useValue = true;
            }
            else if (valueType == 3)
            {
                OnlineMapsVector2d point = (OnlineMapsVector2d)p;
                projection.CoordinatesToTile(point.x, point.y, zoom, out px, out py);
                useValue = true;
            }
            else if (i % 2 == 1)
            {
                if (valueType == 1)
                {
                    projection.CoordinatesToTile((float)v2, (float)v1, zoom, out px, out py);
                }
                else if (valueType == 2)
                {
                    projection.CoordinatesToTile((double)v2, (double)v1, zoom, out px, out py);
                }
                useValue = true;
            }

            if (!useValue)
            {
                continue;
            }

            isOptimized = false;

            if (optimize && i > 0)
            {
                if ((prx - px) * (prx - px) + (pry - py) * (pry - py) < 0.001)
                {
                    isOptimized = true;
                    continue;
                }
            }

            prx = px;
            pry = py;

            px -= sx;
            py -= sy;

            if (i == 0)
            {
                double ox = px - map.width / OnlineMapsUtils.tileSize / 2;
                if (ox < -halfMax)
                {
                    px += max;
                }
                else if (ox > halfMax)
                {
                    px -= max;
                }
            }
            else
            {
                double ox    = px - ppx;
                int    maxIt = 3;
                while (maxIt-- > 0)
                {
                    if (ox < -halfMax)
                    {
                        px += max;
                        ox += max;
                    }
                    else if (ox > halfMax)
                    {
                        px -= max;
                        ox -= max;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            ppx = px;

            double rx1 = px * scaleX;
            double ry1 = py * scaleY;

            Vector2 np = new Vector2((float)rx1, (float)ry1);
            localPoints.Add(np);
        }

        if (isOptimized)
        {
            px -= sx;
            py -= sy;

            if (i == 0)
            {
                double ox = px - map.width / OnlineMapsUtils.tileSize / 2;
                if (ox < -halfMax)
                {
                    px += max;
                }
                else if (ox > halfMax)
                {
                    px -= max;
                }
            }
            else
            {
                double ox    = px - ppx;
                int    maxIt = 3;
                while (maxIt-- > 0)
                {
                    if (ox < -halfMax)
                    {
                        px += max;
                        ox += max;
                    }
                    else if (ox > halfMax)
                    {
                        px -= max;
                        ox -= max;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            double rx1 = px * scaleX;
            double ry1 = py * scaleY;

            Vector2 np = new Vector2((float)rx1, (float)ry1);
            localPoints.Add(np);
        }

        if (closed)
        {
            localPoints.Add(localPoints[0]);
        }

        return(localPoints);
    }
コード例 #18
0
 /// <summary>
 /// Creates a new rectangle.
 /// </summary>
 /// <param name="position">The position of the rectangle. Geographic coordinates.</param>
 /// <param name="size">The size of the rectangle. Geographic coordinates.</param>
 /// <param name="borderColor">Border color.</param>
 /// <param name="borderWidth">Border width.</param>
 /// <param name="backgroundColor">Background color.</param>
 public OnlineMapsDrawingRect(OnlineMapsVector2d position, OnlineMapsVector2d size, Color borderColor, float borderWidth, Color backgroundColor)
     : this(position, size, borderColor, borderWidth)
 {
     _backgroundColor = backgroundColor;
 }
コード例 #19
0
        public Step(OnlineMapsXML node)
        {
            List <Step> steps = new List <Step>();

            foreach (OnlineMapsXML n in node)
            {
                if (n.name == "travel_mode")
                {
                    travel_mode = n.Value();
                }
                else if (n.name == "start_location")
                {
                    start_location = OnlineMapsXML.GetVector2dFromNode(n);
                }
                else if (n.name == "end_location")
                {
                    end_location = OnlineMapsXML.GetVector2dFromNode(n);
                }
                else if (n.name == "polyline")
                {
                    polylineD = OnlineMapsUtils.DecodePolylinePointsD(n["points"].Value()).ToArray();
                    polyline  = polylineD.Select(p => (Vector2)p).ToArray();
                }
                else if (n.name == "duration")
                {
                    duration = new TextValue <int>(n);
                }
                else if (n.name == "distance")
                {
                    distance = new TextValue <int>(n);
                }
                else if (n.name == "step")
                {
                    steps.Add(new Step(n));
                }
                else if (n.name == "html_instructions")
                {
                    html_instructions = n.Value();
                    if (string.IsNullOrEmpty(html_instructions))
                    {
                        return;
                    }
                    string_instructions = OnlineMapsDirectionStep.StrReplace(html_instructions,
                                                                             new[] { "&lt;", "&gt;", "&nbsp;", "&amp;", "&amp;nbsp;" },
                                                                             new[] { "<", ">", " ", "&", " " });
                    string_instructions = Regex.Replace(string_instructions, "<div.*?>", "\n");
                    string_instructions = Regex.Replace(string_instructions, "<.*?>", string.Empty);
                }
                else if (n.name == "maneuver")
                {
                    maneuver = n.Value();
                }
                else if (n.name == "transit_details")
                {
                    transit_details = new TransitDetails(n);
                }
                else
                {
                    Debug.Log("Step: " + n.name + "\n" + n.outerXml);
                }
            }

            this.steps = steps.ToArray();
        }
コード例 #20
0
        private void Update()
        {
            if (pointIndex == -1)
            {
                return;
            }

            // Start point
            OnlineMapsVector2d p1 = points[pointIndex];

            // End point
            OnlineMapsVector2d p2 = points[pointIndex + 1];

            double p1x, p1y, p2x, p2y;

            map.projection.CoordinatesToTile(p1.x, p1.y, map.zoom, out p1x, out p1y);
            map.projection.CoordinatesToTile(p2.x, p2.y, map.zoom, out p2x, out p2y);

            // Total step distance
            double dx, dy;

            OnlineMapsUtils.DistanceBetweenPoints(p1.x, p1.y, p2.x, p2.y, out dx, out dy);
            double stepDistance = Math.Sqrt(dx * dx + dy * dy);

            // Total step time
            double totalTime = stepDistance / speed * 3600;

            // Current step progress
            progress += Time.deltaTime / totalTime;

            OnlineMapsVector2d position;

            if (progress < 1)
            {
                position = OnlineMapsVector2d.Lerp(p1, p2, progress);
                marker.SetPosition(position.x, position.y);

                // Orient marker
                targetRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) - 90;
            }
            else
            {
                position = p2;
                marker.SetPosition(position.x, position.y);
                pointIndex++;
                progress = 0;
                if (pointIndex >= points.Length - 1)
                {
                    Debug.Log("Finish");
                    pointIndex = -1;
                }
                else
                {
                    OnlineMapsVector2d p3 = points[pointIndex + 1];
                    map.projection.CoordinatesToTile(p2.x, p2.y, map.zoom, out p1x, out p1y);
                    map.projection.CoordinatesToTile(p3.x, p3.y, map.zoom, out p2x, out p2y);

                    targetRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) - 90;
                }
            }

            marker.rotationY = Mathf.LerpAngle(marker.rotationY, targetRotation, Time.deltaTime * 10);
            marker.GetPosition(out lng, out lat);
            map.SetPosition(lng, lat);
        }
コード例 #21
0
 /// <summary>
 /// Creates a new rectangle.
 /// </summary>
 /// <param name="position">The position of the rectangle. Geographic coordinates.</param>
 /// <param name="size">The size of the rectangle. Geographic coordinates.</param>
 /// <param name="borderColor">Border color.</param>
 /// <param name="borderWidth">Border width.</param>
 public OnlineMapsDrawingRect(OnlineMapsVector2d position, OnlineMapsVector2d size, Color borderColor, float borderWidth)
     : this(position, size, borderColor)
 {
     _borderWidth = borderWidth;
 }
コード例 #22
0
    protected List <Vector2> GetLocalPoints(IEnumerable points, bool closed = false, bool optimize = true)
    {
        double               sx, sy;
        OnlineMaps           map        = api;
        int                  apiZoom    = map.buffer.apiZoom;
        OnlineMapsProjection projection = map.projection;

        projection.CoordinatesToTile(tlx, tly, apiZoom, out sx, out sy);

        int maxX = 1 << apiZoom;

        if (localPoints == null)
        {
            localPoints = new List <Vector2>();
        }
        else
        {
            localPoints.Clear();
        }

        double ppx    = 0;
        double scaleX = OnlineMapsUtils.tileSize * map.tilesetSize.x / map.tilesetWidth;
        double scaleY = OnlineMapsUtils.tileSize * map.tilesetSize.y / map.tilesetHeight;

        double prx = 0, pry = 0;

        object v1 = null;
        int    i = -1;
        int    valueType = -1; // 0 - Vector2, 1 - float, 2 - double, 3 - OnlineMapsVector2d
        bool   isOptimized = false;
        double px = 0, py = 0;

        IEnumerator enumerator = points.GetEnumerator();

        while (enumerator.MoveNext())
        {
            i++;

            object p = enumerator.Current;
            if (valueType == -1)
            {
                if (p is Vector2)
                {
                    valueType = 0;
                }
                else if (p is float)
                {
                    valueType = 1;
                }
                else if (p is double)
                {
                    valueType = 2;
                }
                else if (p is OnlineMapsVector2d)
                {
                    valueType = 3;
                }
            }

            object v2 = v1;
            v1 = p;

            bool useValue = false;

            if (valueType == 0)
            {
                Vector2 point = (Vector2)p;
                projection.CoordinatesToTile(point.x, point.y, apiZoom, out px, out py);
                useValue = true;
            }
            else if (valueType == 3)
            {
                OnlineMapsVector2d point = (OnlineMapsVector2d)p;
                projection.CoordinatesToTile(point.x, point.y, apiZoom, out px, out py);
                useValue = true;
            }
            else if (i % 2 == 1)
            {
                if (valueType == 1)
                {
                    projection.CoordinatesToTile((float)v2, (float)v1, apiZoom, out px, out py);
                }
                else if (valueType == 2)
                {
                    projection.CoordinatesToTile((double)v2, (double)v1, apiZoom, out px, out py);
                }
                useValue = true;
            }

            if (!useValue)
            {
                continue;
            }

            isOptimized = false;

            if (optimize && i > 0)
            {
                if ((prx - px) * (prx - px) + (pry - py) * (pry - py) < 0.001)
                {
                    isOptimized = true;
                    continue;
                }
            }

            prx = px;
            pry = py;

            px -= sx;
            py -= sy;

            if (i == 0)
            {
                if (px < maxX * -0.25)
                {
                    px += maxX;
                }
                else if (px > maxX * 0.75)
                {
                    px -= maxX;
                }
            }
            else
            {
                double gpx = px + maxX;
                double lpx = px - maxX;

                if (Math.Abs(ppx - gpx) < Math.Abs(ppx - px))
                {
                    px = gpx;
                }
                else if (Math.Abs(ppx - lpx) < Math.Abs(ppx - px))
                {
                    px = lpx;
                }
            }

            ppx = px;

            double rx1 = px * scaleX;
            double ry1 = py * scaleY;

            Vector2 np = new Vector2((float)rx1, (float)ry1);
            localPoints.Add(np);
        }

        if (isOptimized)
        {
            px -= sx;
            py -= sy;

            if (i == 0)
            {
                if (px < maxX * -0.25)
                {
                    px += maxX;
                }
                else if (px > maxX * 0.75)
                {
                    px -= maxX;
                }
            }
            else
            {
                double gpx = px + maxX;
                double lpx = px - maxX;

                if (Math.Abs(ppx - gpx) < Math.Abs(ppx - px))
                {
                    px = gpx;
                }
                else if (Math.Abs(ppx - lpx) < Math.Abs(ppx - px))
                {
                    px = lpx;
                }
            }

            double rx1 = px * scaleX;
            double ry1 = py * scaleY;

            Vector2 np = new Vector2((float)rx1, (float)ry1);
            localPoints.Add(np);
        }

        if (closed)
        {
            localPoints.Add(localPoints[0]);
        }

        return(localPoints);
    }
    public override bool HitTest(Vector2 positionLngLat, int zoom)
    {
        if (points == null)
        {
            return(false);
        }

        double cx, cy;
        OnlineMapsProjection projection = api.projection;

        projection.CoordinatesToTile(positionLngLat.x, positionLngLat.y, zoom, out cx, out cy);

        int valueType = -1; // 0 - Vector2, 1 - float, 2 - double, 3 - OnlineMapsVector2d

        object v1 = null;
        object v2 = null;
        object v3 = null;
        int    i  = 0;

        float w    = hitTestWidth.HasValue ? hitTestWidth.Value : width;
        float sqrW = w * w;

        foreach (object p in points)
        {
            if (valueType == -1)
            {
                if (p is Vector2)
                {
                    valueType = 0;
                }
                else if (p is float)
                {
                    valueType = 1;
                }
                else if (p is double)
                {
                    valueType = 2;
                }
                else if (p is OnlineMapsVector2d)
                {
                    valueType = 3;
                }
            }

            object v4 = v3;
            v3 = v2;
            v2 = v1;
            v1 = p;

            double p1tx = 0, p1ty = 0, p2tx = 0, p2ty = 0;
            bool   drawPart = false;

            if (valueType == 0)
            {
                if (i > 0)
                {
                    Vector2 p1 = (Vector2)v2;
                    Vector2 p2 = (Vector2)v1;

                    projection.CoordinatesToTile(p1.x, p1.y, zoom, out p1tx, out p1ty);
                    projection.CoordinatesToTile(p2.x, p2.y, zoom, out p2tx, out p2ty);
                    drawPart = true;
                }
            }
            else if (valueType == 3)
            {
                if (i > 0)
                {
                    OnlineMapsVector2d p1 = (OnlineMapsVector2d)v2;
                    OnlineMapsVector2d p2 = (OnlineMapsVector2d)v1;

                    projection.CoordinatesToTile(p1.x, p1.y, zoom, out p1tx, out p1ty);
                    projection.CoordinatesToTile(p2.x, p2.y, zoom, out p2tx, out p2ty);
                    drawPart = true;
                }
            }
            else if (i > 2 && i % 2 == 1)
            {
                if (valueType == 1)
                {
                    projection.CoordinatesToTile((float)v4, (float)v3, zoom, out p1tx, out p1ty);
                    projection.CoordinatesToTile((float)v2, (float)v1, zoom, out p2tx, out p2ty);
                }
                else if (valueType == 2)
                {
                    projection.CoordinatesToTile((double)v4, (double)v3, zoom, out p1tx, out p1ty);
                    projection.CoordinatesToTile((double)v2, (double)v1, zoom, out p2tx, out p2ty);
                }
                drawPart = true;
            }

            if (drawPart)
            {
                double nx, ny;
                OnlineMapsUtils.NearestPointStrict(cx, cy, p1tx, p1ty, p2tx, p2ty, out nx, out ny);
                double dx = (cx - nx) * OnlineMapsUtils.tileSize;
                double dy = (cy - ny) * OnlineMapsUtils.tileSize;
                double d  = dx * dx + dy * dy;
                if (d < sqrW)
                {
                    return(true);
                }
            }

            i++;
        }

        return(false);
    }
コード例 #24
0
        public override void Append(StringBuilder builder)
        {
            base.Append(builder);

            builder.Append("&coordinates=");
            for (int i = 0; i < coordinates.Length; i++)
            {
                if (i > 0)
                {
                    builder.Append("|");
                }
                OnlineMapsVector2d c = coordinates[i];
                builder.Append(c.x).Append(",").Append(c.y);
            }

            builder.Append("&profile=").Append(OnlineMapsReflectionHelper.GetEnumDescription(profile));
            if (preference.HasValue)
            {
                builder.Append("&preference=").Append(preference);
            }
            if (units.HasValue)
            {
                builder.Append("&units=").Append(units);
            }
            if (!string.IsNullOrEmpty(language))
            {
                builder.Append("&language=").Append(language);
            }
            if (geometry.HasValue)
            {
                builder.Append("&geometry=").Append(geometry.Value);
            }
            if (geometry_format.HasValue)
            {
                builder.Append("&geometry_format=").Append(geometry_format.Value);
            }
            if (geometry_simplify.HasValue)
            {
                builder.Append("&geometry_simplify=").Append(geometry_simplify.Value);
            }
            if (instructions.HasValue)
            {
                builder.Append("&instructions=").Append(instructions.Value);
            }
            if (instructions_format.HasValue)
            {
                builder.Append("&instructions_format=").Append(instructions_format.Value);
            }
            if (elevation.HasValue)
            {
                builder.Append("&elevation=").Append(elevation.Value);
            }

            if (extra_info != null)
            {
                builder.Append("&extra_info=");
                for (int i = 0; i < extra_info.Length; i++)
                {
                    if (i > 0)
                    {
                        builder.Append("|");
                    }
                    builder.Append(extra_info[i]);
                }
            }

            if (!string.IsNullOrEmpty(options))
            {
                builder.Append("&options=").Append(options);
            }
        }
コード例 #25
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="location">Coordinates of the centerpoint</param>
 /// <param name="radius">Radius in meters</param>
 public Circle(OnlineMapsVector2d location, float radius)
 {
     this.location = location;
     this.radius   = radius;
 }
コード例 #26
0
 /// <summary>
 /// Converts coordinates to a location address.
 /// </summary>
 /// <param name="key">Open Route Service API key</param>
 /// <param name="location">Coordinate to be inquired.</param>
 public GeocodingParams(string key, OnlineMapsVector2d location)
 {
     this.key      = key;
     this.location = location;
 }
コード例 #27
0
        private void Update()
        {
            if (pointIndex == -1)
            {
                return;
            }

            // Start point
            OnlineMapsVector2d p1 = points[pointIndex];

            // End point
            OnlineMapsVector2d p2 = points[pointIndex + 1];

            // Total step distance
            double dx, dy;

            OnlineMapsUtils.DistanceBetweenPoints(p1.x, p1.y, p2.x, p2.y, out dx, out dy);
            double stepDistance = Math.Sqrt(dx * dx + dy * dy);

            // Total step time
            double totalTime = stepDistance / speed * 3600;

            // Current step progress
            progress += Time.deltaTime / totalTime;

            OnlineMapsVector2d position;

            if (progress < 1)
            {
                position = OnlineMapsVector2d.Lerp(p1, p2, progress);
                marker.SetPosition(position.x, position.y);

                // Orient marker
                if (orientMarkerOnNextPoint)
                {
                    marker.rotation = 1.25f - OnlineMapsUtils.Angle2D((Vector2)p1, (Vector2)p2) / 360f;
                }
            }
            else
            {
                position = p2;
                marker.SetPosition(position.x, position.y);
                pointIndex++;
                progress = 0;
                if (pointIndex >= points.Length - 1)
                {
                    Debug.Log("Finish");
                    pointIndex = -1;
                }
                else
                {
                    // Orient marker
                    if (orientMarkerOnNextPoint)
                    {
                        marker.rotation = 1.25f - OnlineMapsUtils.Angle2D(p2, points[pointIndex + 1]) / 360;
                    }
                }
            }

            if (lookToMarker)
            {
                OnlineMaps.instance.SetPosition(position.x, position.y);
            }
            OnlineMaps.instance.Redraw();
        }
コード例 #28
0
 /// <summary>
 /// Turns the marker in the direction specified coordinates
 /// </summary>
 /// <param name="coordinates">The coordinates</param>
 public virtual void LookToCoordinates(OnlineMapsVector2d coordinates)
 {
 }
コード例 #29
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="lng">Longitude of the centerpoint</param>
 /// <param name="lat">Latitude of the centerpoint</param>
 /// <param name="radius">Radius in meters</param>
 public Circle(double lng, double lat, float radius)
 {
     location    = new OnlineMapsVector2d(lng, lat);
     this.radius = radius;
 }
コード例 #30
0
        /// <summary>
        /// Get boundaries of drawing elements
        /// </summary>
        /// <param name="lx">Left longitude</param>
        /// <param name="ty">Top latitude</param>
        /// <param name="rx">Right longitude</param>
        /// <param name="by">Bottom latitude</param>
        private void GetBounds(out double lx, out double ty, out double rx, out double by)
        {
            // Initialize boundaries
            lx = double.MaxValue;
            ty = double.MinValue;
            rx = double.MinValue;
            by = double.MaxValue;

            // Iterate each drawing element
            foreach (var el in OnlineMapsDrawingElementManager.instance)
            {
                // If it is a rectangle, update the boundaries using corners
                if (el is OnlineMapsDrawingRect)
                {
                    OnlineMapsDrawingRect rect = el as OnlineMapsDrawingRect;
                    Encapsulate(ref lx, ref ty, ref rx, ref by, rect.x, rect.y);
                    Encapsulate(ref lx, ref ty, ref rx, ref by, rect.x + rect.width, rect.y + rect.height);
                    continue;
                }

                // Get the points of drawing element
                IEnumerable points;
                if (el is OnlineMapsDrawingLine)
                {
                    points = (el as OnlineMapsDrawingLine).points;
                }
                else if (el is OnlineMapsDrawingPoly)
                {
                    points = (el as OnlineMapsDrawingPoly).points;
                }
                else
                {
                    continue;
                }

                int    valueType = -1; // 0 - Vector2, 1 - float, 2 - double, 3 - OnlineMapsVector2d
                object v1        = null;
                int    i         = -1;
                double ppx       = 0;

                // Iterate each point
                foreach (object p in points)
                {
                    i++;

                    // If the type of the value is unknown, check by value
                    if (valueType == -1)
                    {
                        if (p is Vector2)
                        {
                            valueType = 0;
                        }
                        else if (p is float)
                        {
                            valueType = 1;
                        }
                        else if (p is double)
                        {
                            valueType = 2;
                        }
                        else if (p is OnlineMapsVector2d)
                        {
                            valueType = 3;
                        }
                    }

                    object v2 = v1;
                    v1 = p;

                    double px = 0;
                    double py = 0;

                    if (valueType == 0)
                    {
                        if (i == 0)
                        {
                            Vector2 p1 = (Vector2)v1;
                            ppx = p1.x;
                            Encapsulate(ref lx, ref ty, ref rx, ref by, p1.x, p1.y);
                            continue;
                        }

                        Vector2 v = (Vector2)v1;
                        px = v.x;
                        py = v.y;
                    }
                    else if (valueType == 3)
                    {
                        if (i == 0)
                        {
                            OnlineMapsVector2d p1 = (OnlineMapsVector2d)v1;
                            ppx = p1.x;
                            Encapsulate(ref lx, ref ty, ref rx, ref by, p1.x, p1.y);
                            continue;
                        }

                        Vector2 v = (OnlineMapsVector2d)v1;
                        px = v.x;
                        py = v.y;
                    }
                    else if (i % 2 == 1)
                    {
                        if (i == 1)
                        {
                            if (valueType == 1)
                            {
                                ppx = (float)v2;
                                Encapsulate(ref lx, ref ty, ref rx, ref by, ppx, (float)v1);
                            }
                            else
                            {
                                ppx = (double)v2;
                                Encapsulate(ref lx, ref ty, ref rx, ref by, ppx, (double)v1);
                            }

                            continue;
                        }

                        if (valueType == 1)
                        {
                            px = (float)v2;
                            py = (float)v1;
                        }
                        else
                        {
                            px = (double)v2;
                            py = (double)v1;
                        }
                    }

                    while (true)
                    {
                        double ox = px - ppx;

                        if (ox > 180)
                        {
                            px -= 360;
                        }
                        else if (ox < -180)
                        {
                            px += 360;
                        }
                        else
                        {
                            break;
                        }
                    }

                    Encapsulate(ref lx, ref ty, ref rx, ref by, px, py);

                    ppx = px;
                }
            }
        }