Example #1
0
    public float GetUnscaledElevationValue(double x, double z)
    {
        double tlx, tly, brx, bry;

        map.GetCorners(out tlx, out tly, out brx, out bry);
        return(OnlineMapsElevationManagerBase.GetUnscaledElevation(x, z, tlx, tly, brx, bry));
    }
Example #2
0
        private void Update()
        {
            double lookProgress = progress + 0.001;
            double tiltProgress = progress + 0.001;

            Point position     = GetPointByProgress(progress);
            Point lookPosition = GetPointByProgress(lookProgress);
            Point tiltPosition = GetPointByProgress(tiltProgress);

            speed += accelerationCurve.Evaluate(speed / maxSpeed) * Time.deltaTime;
            if (speed > lookPosition.relativeSpeed * maxSpeed)
            {
                speed = lookPosition.relativeSpeed * maxSpeed;
            }
            double offset = Time.deltaTime * speed / 3600;

            progress += offset / totalDistance;

            double p1x, p1y, p2x, p2y;

            map.projection.CoordinatesToTile(position.longitude, position.latitude, map.zoom, out p1x, out p1y);
            map.projection.CoordinatesToTile(lookPosition.longitude, lookPosition.latitude, map.zoom, out p2x, out p2y);
            targetRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y);

            map.projection.CoordinatesToTile(tiltPosition.longitude, tiltPosition.latitude, map.zoom, out p2x, out p2y);
            float tiltRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y);

            tilt = tiltRotation - airplane.transform.rotation.eulerAngles.y;

            Vector3 p = OnlineMapsTileSetControl.instance.GetWorldPosition(position.longitude, position.latitude);

            altitude = position.relativeAltitude * maxAltitude;
            float elevation = OnlineMapsElevationManagerBase.GetUnscaledElevation(p.x, p.z);

            p.x = -1024;
            float zoom = altitudeZoomCurve.Evaluate(altitude / maxAltitude);

            p.y = Mathf.Max(altitude, elevation) * OnlineMapsElevationManagerBase.GetBestElevationYScale();
            p.z = 1024;
            airplane.transform.position = p;
            airplane.transform.rotation = Quaternion.Euler(0, Mathf.LerpAngle(airplane.transform.rotation.eulerAngles.y, targetRotation, Time.deltaTime), 0);
            float s = 1 / Mathf.Pow(2, 15 - map.floatZoom);

            transform.localScale = new Vector3(s, s, s);
            internalGO.transform.localRotation = Quaternion.Euler(tilt, 0, 0);
            map.SetPositionAndZoom(position.longitude, position.latitude, zoom);
            OnlineMapsCameraOrbit.instance.rotation = new Vector2(OnlineMapsCameraOrbit.instance.rotation.x, airplane.transform.rotation.eulerAngles.y + 90);
        }
Example #3
0
    /// <summary>
    /// Updates marker instance.
    /// </summary>
    /// <param name="map">Reference to the map</param>
    /// <param name="control">Reference to the control</param>
    /// <param name="bounds">Bounds of the map mesh</param>
    /// <param name="tlx">Longitude of top-left corner of the map</param>
    /// <param name="tly">Latitude of top-left corner of the map</param>
    /// <param name="brx">Longitude of bottom-right corner of the map</param>
    /// <param name="bry">Latitude of bottom-right corner of the map</param>
    /// <param name="zoom">Zoom of the map</param>
    /// <param name="ttlx">Tile X of top-left corner of the map</param>
    /// <param name="ttly">Tile Y of top-left corner of the map</param>
    /// <param name="tbrx">Tile X of bottom-right corner of the map</param>
    /// <param name="tbry">Tile Y of bottom-right corner of the map</param>
    /// <param name="bestYScale">Best y scale for current map view</param>
    public void Update(OnlineMaps map, OnlineMapsControlBase3D control, Bounds bounds, double tlx, double tly, double brx, double bry, int zoom, double ttlx, double ttly, double tbrx, double tbry, float bestYScale)
    {
        if (!enabled)
        {
            return;
        }
        if (instance == null)
        {
            Init(map.transform);
        }

        if (!range.InRange(zoom))
        {
            visible = false;
        }
        else if (OnCheckMapBoundaries != null)
        {
            visible = OnCheckMapBoundaries();
        }
        else if (checkMapBoundaries)
        {
            if (latitude > tly || latitude < bry)
            {
                visible = false;
            }
            else if (tlx < brx && (longitude < tlx || longitude > brx))
            {
                visible = false;
            }
            else if (tlx > brx && longitude < tlx && longitude > brx)
            {
                visible = false;
            }
            else
            {
                visible = true;
            }
        }
        else
        {
            visible = true;
        }

        if (!visible)
        {
            return;
        }

        if (_prefab != prefab)
        {
            Reinit(tlx, tly, brx, bry, zoom);
        }

        double mx, my;

        map.projection.CoordinatesToTile(longitude, latitude, zoom, out mx, out my);

        int maxX = 1 << zoom;

        double sx  = tbrx - ttlx;
        double mpx = mx - ttlx;

        if (sx < 0)
        {
            sx += maxX;
        }

        if (checkMapBoundaries)
        {
            if (mpx < 0)
            {
                mpx += maxX;
            }
            else if (mpx > maxX)
            {
                mpx -= maxX;
            }
        }
        else
        {
            double dx1 = Math.Abs(mpx - ttlx);
            double dx2 = Math.Abs(mpx - tbrx);
            double dx3 = Math.Abs(mpx - tbrx + maxX);
            if (dx1 > dx2 && dx1 > dx3)
            {
                mpx += maxX;
            }
        }

        double px = mpx / sx;
        double pz = (ttly - my) / (ttly - tbry);

        _relativePosition = new Vector3((float)px, 0, (float)pz);

        OnlineMapsTileSetControl tsControl = control as OnlineMapsTileSetControl;

        if (tsControl != null)
        {
            px = -tsControl.sizeInScene.x / 2 - (px - 0.5) * tsControl.sizeInScene.x;
            pz = tsControl.sizeInScene.y / 2 + (pz - 0.5) * tsControl.sizeInScene.y;
        }
        else
        {
            Vector3 center = bounds.center;
            Vector3 size   = bounds.size;
            px = center.x - (px - 0.5) * size.x / map.transform.lossyScale.x - map.transform.position.x;
            pz = center.z + (pz - 0.5) * size.z / map.transform.lossyScale.z - map.transform.position.z;
        }

        Vector3 oldPosition = instance.transform.localPosition;
        float   y           = 0;

        if (altitude.HasValue)
        {
            float yScale = OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry);
            y = altitude.Value;
            if (altitudeType == OnlineMapsAltitudeType.relative && tsControl != null)
            {
                y += OnlineMapsElevationManagerBase.GetUnscaledElevation(px, pz, tlx, tly, brx, bry);
            }
            y *= yScale;

            if (tsControl != null)
            {
                if (OnlineMapsElevationManagerBase.instance.bottomMode == OnlineMapsElevationBottomMode.minValue)
                {
                    y -= OnlineMapsElevationManagerBase.instance.minValue * bestYScale;
                }
                y *= OnlineMapsElevationManagerBase.instance.scale;
            }
        }
        else if (tsControl != null)
        {
            y = OnlineMapsElevationManagerBase.GetElevation(px, pz, bestYScale, tlx, tly, brx, bry);
        }

        Vector3 newPosition = new Vector3((float)px, y, (float)pz);

        if (sizeType == SizeType.meters)
        {
            double dx, dy;
            OnlineMapsUtils.DistanceBetweenPoints(tlx, tly, brx, bry, out dx, out dy);
            dx = tsControl.sizeInScene.x / dx / 1000;
            dy = tsControl.sizeInScene.y / dy / 1000;

            double d  = (dx + dy) / 2 * scale;
            float  fd = (float)d;

            instance.transform.localScale = new Vector3(fd, fd, fd);
        }

        if (oldPosition != newPosition)
        {
            instance.transform.localPosition = newPosition;
        }
    }
Example #4
0
 public float GetUnscaledElevationValue(double x, double z, double tlx, double tly, double brx, double bry)
 {
     return(OnlineMapsElevationManagerBase.GetUnscaledElevation(x, z, tlx, tly, brx, bry));
 }