private void Update()
        {
            // If the movement is not allowed to return.
            if (!allowDrag)
            {
                return;
            }

            // Gets rotationRate
            Vector3 rate = Input.gyro.rotationRate;

            // Gets map tile position
            double tx, ty;

            map.GetTilePosition(out tx, out ty);

            // Move tile coordinates
            tx += rate.x * speed;
            ty += rate.y * speed;

            // Converts the tile coordinates to the geographic coordinates.
            double lng, lat;

            map.projection.TileToCoordinates(tx, ty, map.zoom, out lng, out lat);

            // Set map position
            map.SetPosition(lng, lat);
        }
    /// <summary>
    /// Changes the zoom keeping a specified point on same place.
    /// </summary>
    /// <param name="zoomOffset">Positive - zoom in, Negative - zoom out</param>
    /// <param name="screenPosition">Screen position</param>
    /// <returns>True - if zoom changed, False - if zoom not changed</returns>
    public bool ZoomOnPoint(float zoomOffset, Vector2 screenPosition)
    {
        float newZoom = Mathf.Clamp(map.floatZoom + zoomOffset, 3, OnlineMaps.MAXZOOM);

        if (Math.Abs(newZoom - map.floatZoom) < float.Epsilon)
        {
            return(false);
        }

        double mx, my;
        bool   hit = GetCoords(screenPosition, out mx, out my);

        if (!hit)
        {
            return(false);
        }

        map.dispatchEvents = false;

        int zoom = map.zoom;

        double tx, ty, tmx1, tmy1, tmx2, tmy2;

        map.GetTilePosition(out tx, out ty);
        map.projection.CoordinatesToTile(mx, my, zoom, out tmx1, out tmy1);

        double ox = tx - tmx1;
        double oy = ty - tmy1;

        map.floatZoom = newZoom;

        GetCoords(screenPosition, out mx, out my);
        map.projection.CoordinatesToTile(mx, my, zoom, out tmx2, out tmy2);

        double ox2 = tx - tmx2;
        double oy2 = ty - tmy2;

        tx -= ox - ox2;
        ty -= oy - oy2;

        map.projection.TileToCoordinates(tx, ty, zoom, out tx, out ty);
        map.SetPosition(tx, ty);

        map.dispatchEvents = true;
        map.DispatchEvent(OnlineMapsEvents.changedPosition, OnlineMapsEvents.changedZoom);

        if (OnMapZoom != null)
        {
            OnMapZoom();
        }
        return(true);
    }
Exemple #3
0
        private void Start()
        {
            // Set a reference to the map and control
            map     = OnlineMaps.instance;
            control = OnlineMapsTileSetControl.instance;

            // Disable the movement and zoom of the map with the mouse
            control.allowUserControl = false;
            control.allowZoom        = false;

            // Subscribe to change zoom event
            map.OnChangeZoom += OnChangeZoom;

            // Store tile position of the center of the map
            map.GetTilePosition(out tx, out ty);

            // Initial update the map
            UpdateMap();
        }
        private void PreloadBorders()
        {
            int zoom = map.zoom - zoomOffset;

            if (zoom < 3)
            {
                zoom = 3;
            }

            double tx, ty;

            map.GetTilePosition(out tx, out ty, zoom);

            int itx = Mathf.RoundToInt((float)(tx - countX / 2f));
            int ity = Mathf.RoundToInt((float)(ty - countY / 2f));

            foreach (OnlineMapsTile tile in extraTiles)
            {
                tile.Unblock(this);
            }
            extraTiles.Clear();

            int max = 1 << zoom;
            OnlineMapsTileManager tileManager = map.tileManager;

            for (int x = -1; x < countX + 1; x++)
            {
                int tileX = itx + x;
                if (tileX >= max)
                {
                    tileX -= max;
                }

                int tileY = ity - 1;
                if (tileY >= max)
                {
                    tileY -= max;
                }

                OnlineMapsTile tile = tileManager.GetTile(zoom, tileX, tileY);
                if (tile == null)
                {
                    OnlineMapsTile parentTile = tileManager.GetTile(zoom - 1, tileX / 2, tileY / 2);
                    tile        = new OnlineMapsRasterTile(tileX, tileY, zoom, map);
                    tile.parent = parentTile;
                }

                tile.Block(this);
                extraTiles.Add(tile);

                tileY = ity + countY;
                if (tileY >= max)
                {
                    tileY -= max;
                }

                tile = tileManager.GetTile(zoom, tileX, tileY);
                if (tile == null)
                {
                    OnlineMapsTile parentTile = tileManager.GetTile(zoom - 1, tileX / 2, tileY / 2);
                    tile        = new OnlineMapsRasterTile(tileX, tileY, zoom, map);
                    tile.parent = parentTile;
                }

                tile.Block(this);
                extraTiles.Add(tile);
            }

            for (int y = 0; y < countY; y++)
            {
                int tileY = ity + y;
                if (tileY >= max)
                {
                    tileY -= max;
                }

                int tileX = itx - 1;
                if (tileX >= max)
                {
                    tileX -= max;
                }

                OnlineMapsTile tile = tileManager.GetTile(zoom, tileX, tileY);
                if (tile == null)
                {
                    OnlineMapsTile parentTile = tileManager.GetTile(zoom - 1, tileX / 2, tileY / 2);
                    tile        = new OnlineMapsRasterTile(tileX, tileY, zoom, map);
                    tile.parent = parentTile;
                }

                tile.Block(this);
                extraTiles.Add(tile);

                tileX = itx + countX;
                if (tileX >= max)
                {
                    tileX -= max;
                }

                tile = tileManager.GetTile(zoom, tileX, tileY);
                if (tile == null)
                {
                    OnlineMapsTile parentTile = tileManager.GetTile(zoom - 1, tileX / 2, tileY / 2);
                    tile        = new OnlineMapsRasterTile(tileX, tileY, zoom, map);
                    tile.parent = parentTile;
                }

                tile.Block(this);
                extraTiles.Add(tile);
            }
        }
Exemple #5
0
        private void FixedUpdate()
        {
            if (isInteract && control.GetTouchCount() == 0)
            {
                isInteract = false;
            }

            // If there is interaction with the map.
            if (isInteract)
            {
                // Calculates speeds.
                double tx, ty;
                map.GetTilePosition(out tx, out ty, 20);

                double cSpeedX = tx - ptx;
                double cSpeedY = ty - pty;
                float  cSpeedZ = map.floatZoom - pz;

                int halfMax = 1 << 19;
                int max     = 1 << 20;
                if (cSpeedX > halfMax)
                {
                    cSpeedX -= max;
                }
                else if (cSpeedX < -halfMax)
                {
                    cSpeedX += max;
                }

                while (speedX.Count >= maxSamples)
                {
                    speedX.RemoveAt(0);
                }
                while (speedY.Count >= maxSamples)
                {
                    speedY.RemoveAt(0);
                }
                while (speedZ.Count >= maxSamples)
                {
                    speedZ.RemoveAt(0);
                }

                speedX.Add(cSpeedX);
                speedY.Add(cSpeedY);
                speedZ.Add(cSpeedZ);

                ptx = tx;
                pty = ty;
                pz  = map.floatZoom;
            }
            // If no interaction with the map.
            else if (rsX * rsX + rsY * rsY > 0.001 || rsZ > 0.001)
            {
                // Continue to move the map with the current speed.
                double tx, ty;
                map.GetTilePosition(out tx, out ty, 20);

                tx += rsX;
                ty += rsY;

                int max = 1 << 20;
                if (tx >= max)
                {
                    tx -= max;
                }
                else if (tx < 0)
                {
                    tx += max;
                }

                map.SetTilePosition(tx, ty, 20);
                //control.ZoomOnPoint(rsZ, lastScreenPoint);
                map.floatZoom += rsZ;

                // Reduces the current speed.
                rsX *= friction;
                rsY *= friction;
                rsZ *= friction;
            }
        }
Exemple #6
0
        private void FixedUpdate()
        {
            if (isSmoothZoomProceed || waitZeroTouches)
            {
                return;
            }

            // If there is interaction with the map.
            if (isInteract)
            {
                // Calculates speeds.
                double tx, ty;
                map.GetTilePosition(out tx, out ty);
                double cSpeedX = tx - ptx;
                double cSpeedY = ty - pty;

                int halfMax = 1 << (map.zoom - 1);
                int max     = 1 << map.zoom;
                if (cSpeedX > halfMax)
                {
                    cSpeedX -= max;
                }
                else if (cSpeedX < -halfMax)
                {
                    cSpeedX += max;
                }

                while (speedX.Count >= maxSamples)
                {
                    speedX.RemoveAt(0);
                }
                while (speedY.Count >= maxSamples)
                {
                    speedY.RemoveAt(0);
                }

                speedX.Add(cSpeedX);
                speedY.Add(cSpeedY);

                ptx = tx;
                pty = ty;
            }
            // If no interaction with the map.
            else if (rsX * rsX + rsY * rsY > 0.001)
            {
                // Continue to move the map with the current speed.
                double tx, ty;
                map.GetTilePosition(out tx, out ty);
                tx += rsX;
                ty += rsY;

                int max = 1 << map.zoom;
                if (tx >= max)
                {
                    tx -= max;
                }
                else if (tx < 0)
                {
                    tx += max;
                }

                map.SetTilePosition(tx, ty);

                // Reduces the current speed.
                rsX *= friction;
                rsY *= friction;
            }
        }
Exemple #7
0
 /// <summary>
 /// This method is called when the zoom changes (in this case, using a script or inspector)
 /// </summary>
 private void OnChangeZoom()
 {
     // Store tile position of the center of the map
     map.GetTilePosition(out tx, out ty);
 }