/// <summary>
    /// Updates the map coordinates for the actions of the user.
    /// </summary>
    protected void UpdatePosition()
    {
        if (!allowUserControl || GetTouchCount() > 1)
        {
            return;
        }

        double lat, lng;
        bool   hit = GetCoordsInternal(out lng, out lat);

        Vector2 inputPosition = GetInputPosition();

        if (!mapDragStarted && (lastInputPosition - inputPosition).magnitude < startDragDistance)
        {
            return;
        }
        mapDragStarted = true;

        if (hit && lastInputPosition != inputPosition)
        {
            double offsetX = lng - lastPositionLng;
            double offsetY = lat - lastPositionLat;

            if (offsetX > 270)
            {
                offsetX -= 360;
            }
            else if (offsetX < -270)
            {
                offsetX += 360;
            }

            if (Math.Abs(offsetX) > double.Epsilon || Math.Abs(offsetY) > double.Epsilon)
            {
                double px, py;
                map.GetPosition(out px, out py);
                px -= offsetX;
                py -= offsetY;
                map.SetPosition(px, py);

                map.needRedraw = true;

                if (longPressEnumenator != null)
                {
                    StopCoroutine(longPressEnumenator);
                    longPressEnumenator = null;
                }

                if (OnMapDrag != null)
                {
                    OnMapDrag();
                }
            }

            GetCoordsInternal(out lastPositionLng, out lastPositionLat);

            lastInputPosition = inputPosition;
        }
    }
    /// <summary>
    /// Updates the map coordinates for the actions of the user.
    /// </summary>
    protected void UpdatePosition()
    {
        if (!allowUserControl)
        {
            return;
        }

        if (GetTouchCount() > 1)
        {
            return;
        }

        double lat, lng;
        bool   hit = GetCoords(out lng, out lat);

        Vector2 inputPosition = GetInputPosition();

        if (!mapDragStarted && (lastInputPosition - inputPosition).magnitude < startDragDistance)
        {
            return;
        }
        mapDragStarted = true;

        if (hit && lastInputPosition != inputPosition)
        {
            double offsetX = lng - lastPositionLng;
            double offsetY = lat - lastPositionLat;

            if (offsetX != 0 || offsetY != 0)
            {
                double px, py;
                map.GetPosition(out px, out py);
                px -= offsetX;
                py -= offsetY;
                map.SetPosition(px, py);

                map.needRedraw = true;

                if (longPressEnumenator != null)
                {
                    StopCoroutine("WaitLongPress");
                    longPressEnumenator = null;
                }

                if (OnMapDrag != null)
                {
                    OnMapDrag();
                }
            }

            GetCoords(out lastPositionLng, out lastPositionLat);

            lastInputPosition = inputPosition;
        }
    }
    /// <summary>
    /// Updates the map coordinates for the actions of the user.
    /// </summary>
    protected void UpdatePosition()
    {
        if (!allowUserControl)
        {
            return;
        }

        if (Input.touchCount > 1)
        {
            return;
        }

        double lat, lng;
        bool   hit = GetCoords(out lng, out lat);

        Vector2 mousePosition = Input.mousePosition;

        if (hit && lastMousePosition != mousePosition)
        {
            double offsetX = lng - lastPositionLng;
            double offsetY = lat - lastPositionLat;

            if (offsetX != 0 || offsetY != 0)
            {
                double px, py;
                api.GetPosition(out px, out py);
                px -= offsetX;
                py -= offsetY;
                api.SetPosition(px, py);

                api.needRedraw = true;

                if (longPressEnumenator != null)
                {
                    StopCoroutine("WaitLongPress");
                    longPressEnumenator = null;
                }

                if (OnMapDrag != null)
                {
                    OnMapDrag();
                }
            }

            GetCoords(out lastPositionLng, out lastPositionLat);

            lastMousePosition = mousePosition;
        }
    }
    private void DrawLocationGUI(ref bool dirty)
    {
        double px, py;

        api.GetPosition(out px, out py);

        EditorGUI.BeginChangeCheck();
#if UNITY_5_0P
        py = EditorGUILayout.DoubleField("Latitude", py);
        px = EditorGUILayout.DoubleField("Longitude", px);
#else
        py = EditorGUILayout.FloatField("Latitude", (float)py);
        px = EditorGUILayout.FloatField("Longitude", (float)px);
#endif

        if (EditorGUI.EndChangeCheck())
        {
            dirty = true;
            api.SetPosition(px, py);
        }

        EditorGUI.BeginChangeCheck();
        api.zoom = EditorGUILayout.IntSlider("Zoom", api.zoom, 3, 20);
        if (EditorGUI.EndChangeCheck())
        {
            dirty = true;
        }
    }
    private void Update()
    {
        float latitudeSpeed  = Input.GetAxis("Vertical") * Time.deltaTime;
        float longitudeSpeed = Input.GetAxis("Horizontal") * Time.deltaTime;

        if (Math.Abs(latitudeSpeed) < float.Epsilon && Math.Abs(longitudeSpeed) < float.Epsilon)
        {
            return;
        }

        if (map.control is OnlineMapsControlBase3D)
        {
            OnlineMapsControlBase3D control = map.control as OnlineMapsControlBase3D;
            if (control.allowCameraControl)
            {
                Vector3 v = Quaternion.Euler(0, control.cameraRotation.y, 0) * new Vector3(longitudeSpeed, 0, latitudeSpeed);
                longitudeSpeed = v.x;
                latitudeSpeed  = v.z;
            }
        }

        tileX += longitudeSpeed * speed;
        tileY -= latitudeSpeed * speed;

        double lng, lat;

        map.projection.TileToCoordinates(tileX, tileY, map.zoom, out lng, out lat);

        ignoreChangePosition = true;
        map.SetPosition(lng, lat);
        ignoreChangePosition = false;
    }
Exemple #6
0
        private void Update()
        {
            float acc = Input.GetAxis("Vertical");

            if (Mathf.Abs(acc) > 0)
            {
                speed = Mathf.Lerp(speed, maxSpeed * Mathf.Sign(acc), Time.deltaTime * Mathf.Abs(acc));
            }
            else
            {
                speed = Mathf.Lerp(speed, 0, Time.deltaTime * 0.1f);
            }

            if (Mathf.Abs(speed) < 0.1)
            {
                return;
            }

            float r = Input.GetAxis("Horizontal");

            rotation += r * Time.deltaTime * speed;
            OnlineMapsUtils.GetCoordinateInDistance(lng, lat, speed * Time.deltaTime / 3600, rotation + 180, out lng, out lat);

            marker.rotationY = rotation;
            marker.SetPosition(lng, lat);
            if (centerOnMarker)
            {
                map.SetPosition(lng, lat);
            }
            if (rotateCamera)
            {
                OnlineMapsCameraOrbit.instance.rotation = new Vector2(OnlineMapsCameraOrbit.instance.rotation.x, rotation + 180);
            }
        }
        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);
        }
Exemple #8
0
    private void Start()
    {
        double lat = -23.5283114;
        double lng = -46.5753133;

        onlineMap.SetPosition(lng, lat);
    }
    private void DrawLocationGUI(ref bool dirty)
    {
        double px, py;

        map.GetPosition(out px, out py);

        EditorGUI.BeginChangeCheck();
        py = EditorGUILayout.DoubleField("Latitude", py);
        px = EditorGUILayout.DoubleField("Longitude", px);

        if (EditorGUI.EndChangeCheck())
        {
            dirty = true;
            map.SetPosition(px, py);
        }

        EditorGUI.BeginChangeCheck();
        float newZoom = EditorGUILayout.Slider("Zoom", map.floatZoom, OnlineMaps.MINZOOM, OnlineMaps.MAXZOOM);

        if (EditorGUI.EndChangeCheck())
        {
            map.floatZoom = newZoom;
            dirty         = true;
        }
    }
Exemple #10
0
    private void Update()
    {
        float latitudeSpeed  = Input.GetAxis("Vertical") * Time.deltaTime;
        float longitudeSpeed = Input.GetAxis("Horizontal") * Time.deltaTime;

        if (Math.Abs(latitudeSpeed) < float.Epsilon && Math.Abs(longitudeSpeed) < float.Epsilon)
        {
            return;
        }

        if (OnlineMapsCameraOrbit.instance != null)
        {
            Vector3 v = Quaternion.Euler(0, OnlineMapsCameraOrbit.instance.rotation.y, 0) * new Vector3(longitudeSpeed, 0, latitudeSpeed);
            longitudeSpeed = v.x;
            latitudeSpeed  = v.z;
        }

        tileX += longitudeSpeed * speed;
        tileY -= latitudeSpeed * speed;

        double lng, lat;

        map.projection.TileToCoordinates(tileX, tileY, map.zoom, out lng, out lat);

        ignoreChangePosition = true;
        map.SetPosition(lng, lat);
        ignoreChangePosition = false;
    }
Exemple #11
0
        private void Update()
        {
            if (!hasTargetPoint)
            {
                return;
            }

            double dx, dy;

            OnlineMapsUtils.DistanceBetweenPoints(lng, lat, targetLng, targetLat, out dx, out dy);

            double distance  = Math.Sqrt(dx * dx + dy * dy);
            float  cMaxSpeed = maxSpeed;

            if (distance < 0.1)
            {
                cMaxSpeed = maxSpeed * (float)(distance / 0.1);
            }

            speed = Mathf.Lerp(speed, cMaxSpeed, Time.deltaTime);

            OnlineMapsUtils.GetCoordinateInDistance(lng, lat, speed * Time.deltaTime / 3600, rotation + 180, out lng, out lat);

            OnlineMapsUtils.DistanceBetweenPoints(lng, lat, targetLng, targetLat, out dx, out dy);
            if (Math.Sqrt(dx * dx + dy * dy) < 0.001)
            {
                hasTargetPoint = false;
                speed          = 0;
            }

            marker.rotationY = rotation;
            marker.SetPosition(lng, lat);
            if (centerOnMarker)
            {
                map.SetPosition(lng, lat);
            }

            if (lineRendererProgress < 1)
            {
                lineRendererProgress += Time.deltaTime / lineRendererDuration;

                Vector3 p1 = control.GetWorldPosition(lng, lat);
                Vector3 p2 = control.GetWorldPosition(targetLng, targetLat);
                Vector3 p3 = lineRendererProgress > 0.5 ? Vector3.Lerp(p1, p2, (lineRendererProgress - 0.5f) * 2f) : p1;
                Vector3 p4 = lineRendererProgress < 0.5 ? Vector3.Lerp(p1, p2, lineRendererProgress * 2) : p2;
                lineRenderer.SetPosition(0, p4);
                lineRenderer.SetPosition(1, p3);
            }
            else
            {
                lineRendererProgress = 1;
                if (lineRenderer.enabled)
                {
                    lineRenderer.enabled = false;
                }
            }
        }
Exemple #12
0
    private void Update()
    {
        if (playerMarker != null)
        {
            Vector2 goal = Vector2.Lerp(playerMarker.position, location.position, Time.deltaTime * interpolateSpeed);
            playerMarker.SetPosition(goal.x, goal.y);
            map.needRedraw = true;

            if (trackPlayer)
            {
                if ((map.position - oldMapLocation).magnitude > mapSnapBackDistance)
                {
                    PlayerMovedMap();
                }
                else
                {
                    map.SetPosition(goal.x, goal.y);
                    oldMapLocation = map.position;
                }
            }
        }
    }
Exemple #13
0
    private void DrawLocationGUI(ref bool dirty)
    {
        Vector2 p = api.position;

        EditorGUI.BeginChangeCheck();
        p.y = EditorGUILayout.FloatField("Latitude: ", p.y);
        p.x = EditorGUILayout.FloatField("Longitude: ", p.x);
        if (EditorGUI.EndChangeCheck())
        {
            dirty = true;
            api.SetPosition(p.x, p.y);
        }
        EditorGUI.BeginChangeCheck();
        api.zoom = EditorGUILayout.IntSlider("Zoom: ", api.zoom, 3, 20);
        if (EditorGUI.EndChangeCheck())
        {
            dirty = true;
        }
    }
Exemple #14
0
 private void Start()
 {
     //locationService = GetComponentInChildren<OnlineMapsLocationService>();
     //locationService.useGPSEmulator = true;
     //locationService.disableEmulatorInPublish = false;
     //GPSMapService.Instance.onPostureUpdate.AddListener((p) => {
     //    locationService.emulatorPosition.Set((float)p.playerPosition[1], (float)p.playerPosition[0]);
     //    locationService.emulatorCompass = (float)p.playerAngle;
     //});
     maps = GetComponentInChildren <OnlineMaps>();
     GPSMapService.Instance.onPostureUpdate.AddListener((p) => {
         //locationService.emulatorPosition.Set((float)p.playerPosition[1], (float)p.playerPosition[0]);
         //locationService.emulatorCompass = (float)p.playerAngle;
         maps.SetPosition(p.playerPosition[1], p.playerPosition[0]);
         //rotationCache.Set(0, 0, (float)p.playerAngle);
         transform.localRotation = Quaternion.Euler(0, 0, (float)p.playerAngle);
     });
     maps.zoom = Zoom;
 }
Exemple #15
0
    private void DrawLocationGUI(ref bool dirty)
    {
        double px, py;

        map.GetPosition(out px, out py);

        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.BeginVertical();
        EditorGUI.BeginChangeCheck();
        py = EditorGUILayout.DoubleField("Latitude", py);
        px = EditorGUILayout.DoubleField("Longitude", px);

        if (EditorGUI.EndChangeCheck())
        {
            dirty = true;
            map.SetPosition(px, py);
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical(GUILayout.Width(16));
        GUILayout.Space(10);
        OnlineMapsEditorUtils.HelpButton("Coordinates of the center point of the map");
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.BeginHorizontal();
        float newZoom = EditorGUILayout.Slider("Zoom", map.floatZoom, OnlineMaps.MINZOOM, OnlineMaps.MAXZOOM);

        if (EditorGUI.EndChangeCheck())
        {
            map.floatZoom = newZoom;
            dirty         = true;
        }
        OnlineMapsEditorUtils.HelpButton("Current zoom of the map");
        EditorGUILayout.EndHorizontal();
    }
Exemple #16
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);
        }
Exemple #17
0
        void Update()
        {
            const float maxTilt = 50;

            OnlineMaps api = OnlineMaps.instance;
            OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance;

            if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
            {
                tilt -= Time.deltaTime * tiltSpeed * maxTilt;
            }
            else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
            {
                tilt += Time.deltaTime * tiltSpeed * maxTilt;
            }
            else if (tilt != 0)
            {
                float tiltOffset = Time.deltaTime * tiltSpeed * maxTilt;
                if (Mathf.Abs(tilt) > tiltOffset)
                {
                    tilt -= tiltOffset * Mathf.Sign(tilt);
                }
                else
                {
                    tilt = 0;
                }
            }

            tilt = Mathf.Clamp(tilt, -maxTilt, maxTilt);
            container.transform.localRotation = Quaternion.Euler(tilt, 0, 0);

            if (tilt != 0)
            {
                transform.Rotate(Vector3.up, tilt * rotateSpeed * Time.deltaTime);
            }

            double tlx, tly, brx, bry, dx, dy;

            api.GetTopLeftPosition(out tlx, out tly);
            api.GetBottomRightPosition(out brx, out bry);

            OnlineMapsUtils.DistanceBetweenPoints(tlx, tly, brx, bry, out dx, out dy);

            double mx = (brx - tlx) / dx;
            double my = (tly - bry) / dy;

            double v = (double)speed * Time.deltaTime / 3600.0;

            double ox = mx * v * Math.Cos(transform.rotation.eulerAngles.y * OnlineMapsUtils.Deg2Rad);
            double oy = my * v * Math.Sin((360 - transform.rotation.eulerAngles.y) * OnlineMapsUtils.Deg2Rad);

            px += ox;
            py += oy;

            api.SetPosition(px, py);

            Vector3 pos = transform.position;

            pos.y = altitude * control.GetBestElevationYScale(tlx, tly, brx, bry) * control.elevationScale;
            transform.position = pos;

            Camera.main.transform.position = transform.position - transform.rotation * cameraOffset;
            Camera.main.transform.LookAt(transform);
        }