예제 #1
0
    // Adds a circle to the map and holds a refference on this point
    public void AddCircle(double radius, Color color)
    {
        float  r = (float)radius / OnlineMapsUtils.tileSize;
        float  step = 360f / segments;
        double x, y;

        _Pin.GetPosition(out x, out y);

        OnlineMapsProjection projection = OnlineMaps.instance.projection;

        projection.CoordinatesToTile(x, y, OnlineMaps.instance.zoom, out x, out y);

        points = new List <Vector2>();
        for (int i = 0; i < segments; i++)
        {
            points.Add(new Vector2());

            double px = x + Mathf.Cos(step * i * Mathf.Deg2Rad) * r;
            double py = y + Mathf.Sin(step * i * Mathf.Deg2Rad) * r;

            projection.TileToCoordinates(px, py, OnlineMaps.instance.zoom, out px, out py);

            points[i] = new Vector2((float)px, (float)py);
        }

        _Circle = new OnlineMapsDrawingPoly(points, color, 3);

        OnlineMaps.instance.AddDrawingElement(_Circle);

        _Acting = false;
    }
예제 #2
0
        private void GroupMarkers()
        {
            List <MarkerGroup> groups = new List <MarkerGroup>();

            for (int zoom = OnlineMaps.MAXZOOM; zoom >= 3; zoom--)
            {
                List <OnlineMapsMarker> ms = markers.Select(m => m).ToList();

                for (int j = 0; j < ms.Count - 1; j++)
                {
                    OnlineMapsMarker marker = ms[j];
                    MarkerGroup      group = null;
                    double           px, py;
                    marker.GetPosition(out px, out py);
                    OnlineMaps.instance.projection.CoordinatesToTile(px, py, zoom, out px, out py);

                    int k = j + 1;

                    while (k < ms.Count)
                    {
                        OnlineMapsMarker marker2 = ms[k];

                        double p2x, p2y;
                        marker2.GetPosition(out p2x, out p2y);
                        OnlineMaps.instance.projection.CoordinatesToTile(p2x, p2y, zoom, out p2x, out p2y);

                        if (OnlineMapsUtils.Magnitude(px, py, p2x, p2y) < distance)
                        {
                            if (group == null)
                            {
                                group = new MarkerGroup(zoom, groupTexture);
                                groups.Add(group);
                                group.Add(marker);
                                if (marker.range.min == 3)
                                {
                                    marker.range.min = zoom + 1;
                                }
                            }
                            group.Add(marker2);
                            if (marker2.range.min == 3)
                            {
                                marker2.range.min = zoom + 1;
                            }
                            ms.RemoveAt(k);
                            px = group.tilePositionX;
                            py = group.tilePositionY;
                        }
                        else
                        {
                            k++;
                        }
                    }
                }
            }

            foreach (MarkerGroup g in groups)
            {
                g.Apply(font);
            }
        }
 public MarkerWrapper(OnlineMapsMarker marker)
 {
     markerRef = marker;
     marker.GetPosition(out longitude, out latitude);
     mx = longitude;
     my = latitude;
     OnlineMapsUtils.LatLongToMercat(ref mx, ref my);
 }
예제 #4
0
            /// <summary>
            /// This method is called to draw each marker
            /// </summary>
            /// <param name="marker">Marker</param>
            /// <param name="tlx">Left longitude of the map</param>
            /// <param name="tly">Top latitude of the map</param>
            /// <param name="brx">Right longitude of the map</param>
            /// <param name="bry">Bottom latitiude of the map</param>
            private void DrawMarker(OnlineMapsMarker marker, double tlx, double tly, double brx, double bry)
            {
                // Get coordinates of the marker
                double px, py;

                marker.GetPosition(out px, out py);

                // Get instance of marker from custom data
                GameObject markerInstance = marker["instance"] as GameObject;

                // If marker outside the map
                if (px < tlx || px > brx || py < bry || py > tly)
                {
                    // If there is an instance, destroy it
                    if (markerInstance != null)
                    {
                        OnlineMapsUtils.Destroy(markerInstance);
                        marker["instance"] = null;
                    }

                    return;
                }

                // If there is no instance, create it and put the reference to custom data
                if (markerInstance == null)
                {
                    marker["instance"] = markerInstance = Instantiate(instance.prefab);
                    (markerInstance.transform as RectTransform).SetParent(instance.container);
                    markerInstance.transform.localScale = Vector3.one;
                }

                // Convert geographic coordinates to screen position
                Vector2 screenPosition = control.GetScreenPosition(px, py);

                // Get rect transform of the instance
                RectTransform markerRectTransform = markerInstance.transform as RectTransform;

                // Add half height to align the marker to the bottom
                screenPosition.y += markerRectTransform.rect.height / 2;

                // Convert screen space to local space in the canvas
                Vector2 point;

                RectTransformUtility.ScreenPointToLocalPointInRectangle(markerRectTransform.parent as RectTransform, screenPosition, instance.worldCamera, out point);

                // Set position of the marker instance
                markerRectTransform.localPosition = point;
            }
예제 #5
0
    private Rect GetMarkerRect(OnlineMapsMarker marker)
    {
        const int s = OnlineMapsUtils.tileSize;

        double mx, my;

        marker.GetPosition(out mx, out my);

        double tx, ty;

        api.projection.CoordinatesToTile(mx, my, bufferZoom, out tx, out ty);
        tx -= bufferPosition.x;
        ty -= bufferPosition.y;
        OnlineMapsVector2i ip = marker.GetAlignedPosition(new OnlineMapsVector2i((int)(tx * s), (int)(ty * s)));

        return(new Rect(ip.x, ip.y, marker.width, marker.height));
    }
예제 #6
0
    private void SetMarkerToBuffer(OnlineMapsMarker marker, OnlineMapsVector2i bufferPosition, int bufferZoom, OnlineMapsVector2i frontBufferPosition, double sx, double sy, double ex, double ey)
    {
        const int s = OnlineMapsUtils.tileSize;

        double mx, my;

        marker.GetPosition(out mx, out my);

        int maxX = 1 << bufferZoom;

        bool isEntireWorld       = map.buffer.renderState.width == maxX * s;
        bool isBiggestThatBuffer = map.buffer.renderState.width + 512 == maxX * s;

        if (isEntireWorld || isBiggestThatBuffer)
        {
        }
        else if (!(((mx > sx && mx < ex) || (mx + 360 > sx && mx + 360 < ex) || (mx - 360 > sx && mx - 360 < ex)) &&
                   my < sy && my > ey))
        {
            return;
        }

#if !UNITY_WEBGL
        int maxCount = 20;
        while (marker.locked && maxCount > 0)
        {
            OnlineMapsUtils.ThreadSleep(1);
            maxCount--;
        }
#endif

        marker.locked = true;

        double px, py;
        map.projection.CoordinatesToTile(mx, my, bufferZoom, out px, out py);
        px -= bufferPosition.x;
        py -= bufferPosition.y;

        if (isEntireWorld)
        {
            double tx, ty;
            map.projection.CoordinatesToTile(map.buffer.renderState.longitude, map.buffer.renderState.latitude, bufferZoom, out tx, out ty);
            tx -= map.buffer.renderState.width / s / 2;

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

        float zoomCoof = map.buffer.renderState.zoomCoof;

        px *= s;
        py *= s;

        int ipx = (int)((px - frontBufferPosition.x) / zoomCoof);
        int ipy = (int)((py - frontBufferPosition.y) / zoomCoof);

        OnlineMapsVector2i ip = marker.GetAlignedPosition(ipx, ipy);

        Color32[] markerColors = marker.colors;
        if (markerColors == null || markerColors.Length == 0)
        {
            return;
        }

        int markerWidth  = marker.width;
        int markerHeight = marker.height;

        OnlineMapsBuffer buffer = map.buffer;

        for (int y = 0; y < marker.height; y++)
        {
            if (ip.y + y < 0 || ip.y + y >= map.height)
            {
                continue;
            }

            int cy = (markerHeight - y - 1) * markerWidth;

            for (int x = 0; x < marker.width; x++)
            {
                if (ip.x + x < 0 || ip.x + x >= map.buffer.renderState.width)
                {
                    continue;
                }

                try
                {
                    buffer.SetColorToBuffer(markerColors[cy + x], ip, y, x);
                }
                catch
                {
                }
            }
        }

        if (isEntireWorld)
        {
            ip.x -= (int)(buffer.renderState.width / zoomCoof);
            for (int y = 0; y < marker.height; y++)
            {
                if (ip.y + y < 0 || ip.y + y >= map.height)
                {
                    continue;
                }

                int cy = (markerHeight - y - 1) * markerWidth;

                for (int x = 0; x < marker.width; x++)
                {
                    if (ip.x + x < 0 || ip.x + x >= map.buffer.renderState.width)
                    {
                        continue;
                    }

                    try
                    {
                        buffer.SetColorToBuffer(markerColors[cy + x], ip, y, x);
                    }
                    catch
                    {
                    }
                }
            }

            ip.x += (int)(buffer.renderState.width * 2 / zoomCoof);
            for (int y = 0; y < marker.height; y++)
            {
                if (ip.y + y < 0 || ip.y + y >= map.height)
                {
                    continue;
                }

                int cy = (markerHeight - y - 1) * markerWidth;

                for (int x = 0; x < marker.width; x++)
                {
                    if (ip.x + x < 0 || ip.x + x >= map.buffer.renderState.width)
                    {
                        continue;
                    }

                    try
                    {
                        buffer.SetColorToBuffer(markerColors[cy + x], ip, y, x);
                    }
                    catch
                    {
                    }
                }
            }
        }

        marker.locked = false;
    }
예제 #7
0
    private void SetMarkerToBuffer(OnlineMapsMarker marker, double sx, double sy, double ex, double ey)
    {
        const int s = OnlineMapsUtils.tileSize;

        double mx, my;

        marker.GetPosition(out mx, out my);

        if (!(((mx > sx && mx < ex) || (mx + 360 > sx && mx + 360 < ex) ||
               (mx - 360 > sx && mx - 360 < ex)) &&
              my < sy && my > ey))
        {
            return;
        }

#if !UNITY_WEBGL
        int maxCount = 20;
        while (marker.locked && maxCount > 0)
        {
#if !NETFX_CORE
            Thread.Sleep(1);
#else
            OnlineMapsThreadWINRT.Sleep(1);
#endif
            maxCount--;
        }
#endif

        marker.locked = true;

        double px, py;
        api.projection.CoordinatesToTile(mx, my, bufferZoom, out px, out py);
        px -= bufferPosition.x;
        py -= bufferPosition.y;

        int maxX = 1 << bufferZoom;

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

        OnlineMapsVector2i ip = marker.GetAlignedPosition((int)(px * s), (int)(py * s));

        Color32[] markerColors = marker.colors;
        if (markerColors == null || markerColors.Length == 0)
        {
            return;
        }

        int markerWidth  = marker.width;
        int markerHeight = marker.height;

        for (int y = 0; y < marker.height; y++)
        {
            if (disposed)
            {
                return;
            }
            if (ip.y + y < 0 || ip.y + y >= height)
            {
                continue;
            }

            int cy = (markerHeight - y - 1) * markerWidth;

            for (int x = 0; x < marker.width; x++)
            {
                if (ip.x + x < 0 || ip.x + x >= width)
                {
                    continue;
                }

                try
                {
                    SetColorToBuffer(markerColors[cy + x], ip, y, x);
                }
                catch
                {
                }
            }
        }

        marker.locked = false;
    }