public override Vector2 GetCoords(Vector2 position)
    {
        if (!RectTransformUtility.RectangleContainsScreenPoint(image.rectTransform, position, worldCamera))
        {
            return(Vector2.zero);
        }

        Vector2 point;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(image.rectTransform, position, worldCamera, out point);

        Rect rect = image.GetPixelAdjustedRect();

        Vector2 size = (rect.max - point);

        size.x = size.x / rect.size.x;
        size.y = size.y / rect.size.y;

        Vector2 r = new Vector2((size.x - .5f), (size.y - .5f));

        int countX = api.width / OnlineMapsUtils.tileSize;
        int countY = api.height / OnlineMapsUtils.tileSize;

        double px, py;

        api.GetPosition(out px, out py);
        OnlineMapsUtils.LatLongToTiled(px, py, api.zoom, out px, out py);

        px -= countX * r.x;
        py += countY * r.y;

        OnlineMapsUtils.TileToLatLong(px, py, api.zoom, out px, out py);
        return(new Vector2((float)px, (float)py));
    }
    private Vector2 GetCoords2D(Vector2 position)
    {
        RaycastHit2D hit = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(position), Mathf.Infinity);

        if (hit.collider == null || hit.collider.gameObject != gameObject)
        {
            return(Vector2.zero);
        }
        if (cl2D == null)
        {
            return(Vector2.zero);
        }

        Vector3 size = (cl2D.bounds.max - new Vector3(hit.point.x, hit.point.y));

        size.x = size.x / cl2D.bounds.size.x;
        size.y = size.y / cl2D.bounds.size.y;

        Vector2 r = new Vector3((size.x - .5f), (size.y - .5f));

        int countX = api.width / OnlineMapsUtils.tileSize;
        int countY = api.height / OnlineMapsUtils.tileSize;

        Vector2 p = OnlineMapsUtils.LatLongToTilef(api.position, api.zoom);

        p.x -= countX * r.x;
        p.y += countY * r.y;

        return(OnlineMapsUtils.TileToLatLong(p, api.zoom));
    }
    public override bool GetCoords(out double lng, out double lat, Vector2 position)
    {
        RaycastHit hit;

        lng = lat = 0;
        if (!Physics.Raycast(Camera.main.ScreenPointToRay(position), out hit))
        {
            return(false);
        }

        if (hit.collider.gameObject != gameObject)
        {
            return(false);
        }

        Vector3 size = (cl.bounds.max - hit.point);

        size.x = size.x / cl.bounds.size.x;
        size.y = size.y / cl.bounds.size.y;

        Vector2 r = new Vector3((size.x - .5f), (size.y - .5f));

        int countX = api.width / OnlineMapsUtils.tileSize;
        int countY = api.height / OnlineMapsUtils.tileSize;

        double px, py;

        api.GetPosition(out px, out py);
        OnlineMapsUtils.LatLongToTiled(px, py, api.zoom, out px, out py);
        px -= countX * r.x;
        py += countY * r.y;

        OnlineMapsUtils.TileToLatLong(px, py, api.zoom, out lng, out lat);
        return(true);
    }
    private Vector2 GetCoords3D(Vector2 position)
    {
        RaycastHit hit;

        if (!Physics.Raycast(Camera.main.ScreenPointToRay(position), out hit))
        {
            return(Vector2.zero);
        }

        if (hit.collider.gameObject != gameObject)
        {
            return(Vector2.zero);
        }

        Vector3 size = (cl.bounds.max - hit.point);

        size.x = size.x / cl.bounds.size.x;
        size.y = size.y / cl.bounds.size.y;

        Vector2 r = new Vector3((size.x - .5f), (size.y - .5f));

        int countX = api.width / OnlineMapsUtils.tileSize;
        int countY = api.height / OnlineMapsUtils.tileSize;

        double px, py;

        api.GetPosition(out px, out py);
        OnlineMapsUtils.LatLongToTiled(px, py, api.zoom, out px, out py);
        px -= countX * r.x;
        py += countY * r.y;

        OnlineMapsUtils.TileToLatLong(px, py, api.zoom, out px, out py);
        return(new Vector2((float)px, (float)py));
    }
    public override bool GetCoords(out double lng, out double lat, Vector2 position)
    {
        Rect   rect = screenRect;
        int    countX = api.texture.width / OnlineMapsUtils.tileSize;
        int    countY = api.texture.height / OnlineMapsUtils.tileSize;
        double px, py;

        api.GetPosition(out px, out py);
        OnlineMapsUtils.LatLongToTiled(px, py, api.zoom, out px, out py);
        double rx = (rect.center.x - position.x) / rect.width * 2;
        double ry = (rect.center.y - position.y) / rect.height * 2;

        px -= countX / 2f * rx;
        py += countY / 2f * ry;
        OnlineMapsUtils.TileToLatLong(px, py, api.zoom, out lng, out lat);
        return(true);
    }
    public override Vector2 GetCoords(Vector2 position)
    {
        Rect   rect = screenRect;
        int    countX = api.texture.width / OnlineMapsUtils.tileSize;
        int    countY = api.texture.height / OnlineMapsUtils.tileSize;
        double px, py;

        api.GetPosition(out px, out py);
        OnlineMapsUtils.LatLongToTiled(px, py, api.zoom, out px, out py);
        float rx = (rect.center.x - position.x) / rect.width * 2;
        float ry = (rect.center.y - position.y) / rect.height * 2;

        px -= countX / 2f * rx;
        py += countY / 2f * ry;
        OnlineMapsUtils.TileToLatLong(px, py, api.zoom, out px, out py);
        return(new Vector2((float)px, (float)py));
    }
    private void LoadNewBuildings()
    {
        Vector2 tl = OnlineMapsUtils.TileToLatLong(topLeft, api.zoom);
        Vector2 br = OnlineMapsUtils.TileToLatLong(bottomRight, api.zoom);

        string requestData = String.Format("node({0},{1},{2},{3});way(bn)[{4}];(._;>;);out;", br.y, tl.x, tl.y, br.x, "'building'");

        if (OnPrepareRequest != null)
        {
            requestData = OnPrepareRequest(requestData, tl, br);
        }

        OnlineMapsOSMAPIQuery.Find(requestData).OnComplete += OnBuildingRequestComplete;
        if (OnRequestSent != null)
        {
            OnRequestSent();
        }
    }
Beispiel #8
0
    public override bool GetCoords(out double lng, out double lat, Vector2 position)
    {
        RaycastHit hit;

        lng = lat = 0;
        if (!Physics.Raycast(activeCamera.ScreenPointToRay(position), out hit))
        {
            return(false);
        }

        if (hit.collider.gameObject != gameObject)
        {
            return(false);
        }

        Renderer     render       = hit.collider.GetComponent <Renderer>();
        MeshCollider meshCollider = hit.collider as MeshCollider;

        if (render == null || render.sharedMaterial == null || render.sharedMaterial.mainTexture == null || meshCollider == null)
        {
            return(false);
        }

        Vector2 r = hit.textureCoord;

        r.x = r.x - 0.5f;
        r.y = r.y - 0.5f;

        int countX = api.width / OnlineMapsUtils.tileSize;
        int countY = api.height / OnlineMapsUtils.tileSize;

        double px, py;

        api.GetPosition(out px, out py);
        OnlineMapsUtils.LatLongToTiled(px, py, api.zoom, out px, out py);

        px += countX * r.x;
        py -= countY * r.y;
        OnlineMapsUtils.TileToLatLong(px, py, api.zoom, out lng, out lat);
        return(true);
    }
Beispiel #9
0
    public void SetMarkersToBuffer(IEnumerable <OnlineMapsMarker> markers)
    {
        if (OnlineMapsControlBase.instance is OnlineMapsControlBase3D)
        {
            if (((OnlineMapsControlBase3D)OnlineMapsControlBase.instance).marker2DMode ==
                OnlineMapsMarker2DMode.billboard)
            {
                return;
            }
        }

        const int s        = OnlineMapsUtils.tileSize;
        int       countX   = api.width / s + 2;
        int       countY   = api.height / s + 2;
        Vector2   startPos = OnlineMapsUtils.TileToLatLong(bufferPosition.x, bufferPosition.y, bufferZoom);
        Vector2   endPos   = OnlineMapsUtils.TileToLatLong(bufferPosition.x + countX, bufferPosition.y + countY + 1,
                                                           bufferZoom);

        if (endPos.x < startPos.x)
        {
            endPos.x += 360;
        }

        IEnumerable <OnlineMapsMarker> usedMarkers = markers.Where(m => m.enabled && m.range.InRange(bufferZoom));

        if (OnSortMarker != null)
        {
            usedMarkers = OnSortMarker(usedMarkers);
        }
        else
        {
            usedMarkers = usedMarkers.OrderByDescending(m => m.position.y);
        }

        foreach (OnlineMapsMarker marker in usedMarkers)
        {
            SetMarkerToBuffer(marker, startPos, endPos);
        }
    }
Beispiel #10
0
    public OnlineMapsTile(int x, int y, int zoom, OnlineMaps api, bool isMapTile = true)
    {
        int maxX = 2 << (zoom - 1);

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

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

        OnlineMapsTile.api = api;
        this.isMapTile     = isMapTile;

        provider = api.provider;
        type     = api.type;
        labels   = api.labels;
        language = api.language;

        topLeft        = OnlineMapsUtils.TileToLatLong(x, y, zoom);
        bottomRight    = OnlineMapsUtils.TileToLatLong(x + 1, y + 1, zoom);
        globalPosition = Vector2.Lerp(topLeft, bottomRight, 0.5f);

        trafficURL = String.Format("https://mts0.google.com/vt?pb=!1m4!1m3!1i{0}!2i{1}!3i{2}!2m3!1e0!2sm!3i301114286!2m6!1e2!2straffic!4m2!1soffset_polylines!2s0!5i1!2m12!1e2!2spsm!4m2!1sgid!2sl0t0vMkIqfb3hBb090479A!4m2!1ssp!2s1!5i1!8m2!13m1!14b1!3m25!2sru-RU!3sUS!5e18!12m1!1e50!12m3!1e37!2m1!1ssmartmaps!12m5!1e14!2m1!1ssolid!2m1!1soffset_polylines!12m4!1e52!2m2!1sentity_class!2s0S!12m4!1e26!2m2!1sstyles!2zcy5lOmx8cC52Om9mZixzLnQ6MXxwLnY6b2ZmLHMudDozfHAudjpvZmY!4e0", zoom, x, y);

        if (isMapTile)
        {
            tiles.Add(this);
        }
    }