/// <summary>
    /// Adds a new 3D marker on the map.
    /// </summary>
    /// <param name="markerLng">Marker longitude.</param>
    /// <param name="markerLat">Marker latitude.</param>
    /// <param name="prefab">Marker prefab.</param>
    /// <returns>Marker instance.</returns>
    public OnlineMapsMarker3D AddMarker3D(double markerLng, double markerLat, GameObject prefab)
    {
        OnlineMapsMarker3D marker;

        if (OnAddMarker3D != null)
        {
            marker = OnAddMarker3D(markerLng, markerLat, prefab);
            if (marker != null)
            {
                return(marker);
            }
        }

        Array.Resize(ref markers3D, markers3D.Length + 1);
        marker = new OnlineMapsMarker3D
        {
            prefab  = prefab,
            control = this,
            scale   = marker3DScale,
            allowDefaultMarkerEvents = allowDefaultMarkerEvents
        };
        marker.SetPosition(markerLng, markerLat);
        marker.Init(transform);
        markers3D[markers3D.Length - 1] = marker;

        if (OnMarker3DAdded != null)
        {
            OnMarker3DAdded(marker);
        }

        return(marker);
    }
示例#2
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);
            }
        }
示例#3
0
        private void OnMapClick()
        {
            control.GetCoords(out targetLng, out targetLat);

            if (targetMarker == null)
            {
                targetMarker       = OnlineMapsMarker3DManager.CreateItem(targetLng, targetLat, targetPrefab);
                targetMarker.scale = targetScale;
            }
            else
            {
                targetMarker.SetPosition(targetLng, targetLat);
            }

            double tx1, ty1, tx2, ty2;

            map.projection.CoordinatesToTile(lng, lat, map.zoom, out tx1, out ty1);
            map.projection.CoordinatesToTile(targetLng, targetLat, map.zoom, out tx2, out ty2);

            rotation = (float)OnlineMapsUtils.Angle2D(tx1, ty1, tx2, ty2) - 90;

            if (!OnlineMapsKeyManager.hasGoogleMaps)
            {
                Debug.LogWarning("Please enter Map / Key Manager / Google Maps");
                return;
            }

            OnlineMapsGoogleDirections request = new OnlineMapsGoogleDirections(OnlineMapsKeyManager.GoogleMaps(), new Vector2((float)lng, (float)lat), control.GetCoords());

            request.OnComplete += OnRequestComplete;
            request.Send();
        }
    /// <summary>
    /// Adds a new 3D marker on the map.
    /// </summary>
    /// <param name="markerLng">Marker longitude.</param>
    /// <param name="markerLat">Marker latitude.</param>
    /// <param name="prefab">Marker prefab.</param>
    /// <returns>Marker instance.</returns>
    public OnlineMapsMarker3D AddMarker3D(double markerLng, double markerLat, GameObject prefab)
    {
        OnlineMapsMarker3D marker;

        if (OnAddMarker3D != null)
        {
            marker = OnAddMarker3D(markerLng, markerLat, prefab);
            if (marker != null)
            {
                return(marker);
            }
        }

        List <OnlineMapsMarker3D> ms = markers3D.ToList();

        marker = new OnlineMapsMarker3D
        {
            prefab  = prefab,
            control = this,
            scale   = marker3DScale,
            allowDefaultMarkerEvents = allowDefaultMarkerEvents
        };
        marker.SetPosition(markerLng, markerLat);
        marker.Init(transform);
        ms.Add(marker);
        markers3D = ms.ToArray();
        return(marker);
    }
示例#5
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;
                }
            }
        }
    protected override void updateGraphicsCoordinates()
    {
        if (marker3D != null)
        {
            marker3D.SetPosition(getX(), getY());
        }

        if (marker2D != null)
        {
            marker2D.SetPosition(getX(), getY());
        }
    }
示例#7
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;
                }
            }
        }
    }
示例#8
0
        private void OnMapClick()
        {
            control.GetCoords(out targetLng, out targetLat);

            if (targetMarker == null)
            {
                targetMarker       = OnlineMapsMarker3DManager.CreateItem(targetLng, targetLat, targetPrefab);
                targetMarker.scale = targetScale;
            }
            else
            {
                targetMarker.SetPosition(targetLng, targetLat);
            }

            double tx1, ty1, tx2, ty2;

            map.projection.CoordinatesToTile(lng, lat, map.zoom, out tx1, out ty1);
            map.projection.CoordinatesToTile(targetLng, targetLat, map.zoom, out tx2, out ty2);

            rotation       = (float)OnlineMapsUtils.Angle2D(tx1, ty1, tx2, ty2) - 90;
            hasTargetPoint = true;

            if (lineRenderer == null)
            {
                GameObject go = new GameObject("LineRenderer");
                go.transform.SetParent(transform, false);
                lineRenderer          = go.AddComponent <LineRenderer>();
                lineRenderer.material = lineRendererMaterial;
#if UNITY_2017_3_OR_NEWER
                lineRenderer.positionCount = 2;
                lineRenderer.widthCurve    = AnimationCurve.Constant(0, 1, 10);
#elif UNITY_2017_1_OR_NEWER
                lineRenderer.positionCount = 2;
                lineRenderer.widthCurve    = AnimationCurve.Linear(0, 10, 1, 10);
#else
                lineRenderer.SetVertexCount(2);
                lineRenderer.SetWidth(10, 10);
#endif
            }
            else
            {
                lineRenderer.enabled = true;
            }

            Vector3 p1 = control.GetWorldPosition(lng, lat);
            lineRenderer.SetPosition(0, p1);
            lineRenderer.SetPosition(1, p1);

            lineRendererProgress = 0;
        }
示例#9
0
    private static void LoadMarkers3D(OnlineMapsXML el, OnlineMaps api)
    {
        OnlineMapsControlBase3D   control = api.GetComponent <OnlineMapsControlBase3D>();
        List <OnlineMapsMarker3D> markers = new List <OnlineMapsMarker3D>();

        foreach (OnlineMapsXML m in el)
        {
            OnlineMapsMarker3D marker = new OnlineMapsMarker3D();

            double mx = m.Get <double>("Longitude");
            double my = m.Get <double>("Latitude");

            marker.SetPosition(mx, my);

            Debug.Log(m["Range"].outerXml);
            marker.range    = m.Get <OnlineMapsRange>("Range");
            marker.label    = m.Get <string>("Label");
            marker.prefab   = GetObject(m.Get <int>("Prefab")) as GameObject;
            marker.rotation = Quaternion.Euler(m.Get <Vector3>("Rotation"));
            markers.Add(marker);
        }
        control.markers3D = markers.ToArray();
    }
示例#10
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);
        }
示例#11
0
    private void OnMarkerDrag(OnlineMapsMarker3D obj)
    {
        var position = OnlineMapsControlBase3D.instance.GetCoords();

        obj.SetPosition(position.x, position.y);
    }