/// <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;
        }
    }
Ejemplo n.º 2
0
    /// <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;
        }
    }
Ejemplo n.º 3
0
        private void Update()
        {
            // If the movement is not allowed to return.
            if (!allowDrag)
            {
                return;
            }

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

            // Gets map position
            double lng, lat;

            map.GetPosition(out lng, out lat);

            // Converts the geographic coordinates to the tile coordinates.
            double tx, ty;

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

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

            // Converts the tile coordinates to the geographic coordinates.
            map.projection.TileToCoordinates(tx, ty, map.zoom, out lng, out lat);

            // Set map position
            map.SetPosition(lng, lat);
        }
Ejemplo n.º 4
0
    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 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;
        }
    }
Ejemplo n.º 6
0
 public OnlineMapsBuffer(OnlineMaps api)
 {
     this.api = api;
     apiZoom  = api.zoom;
     api.GetPosition(out apiLongitude, out apiLatitude);
     newTiles = new List <OnlineMapsTile>();
 }
Ejemplo n.º 7
0
    private void OnEnable()
    {
        api = (OnlineMaps)target;

        double lng, lat;

        api.GetPosition(out lng, out lat);

        if (api._position != Vector2.zero && lng == 0 && lat == 0)
        {
            api.position  = api._position;
            api._position = Vector2.zero;
        }

        if (api.defaultMarkerTexture == null)
        {
            api.defaultMarkerTexture = GetIcon("DefaultMarker.png");
        }
        if (api.skin == null)
        {
            api.skin =
                (GUISkin)
                AssetDatabase.LoadAssetAtPath("Assets/Infinity Code/Online maps/Skin/DefaultSkin.guiskin",
                                              typeof(GUISkin));
        }

        string[] files = Directory.GetFiles("Assets", "update_available.png", SearchOption.AllDirectories);
        if (files.Length > 0)
        {
            Texture updateAvailableIcon = AssetDatabase.LoadAssetAtPath(files[0], typeof(Texture)) as Texture;
            updateAvailableContent = new GUIContent("Update Available", updateAvailableIcon, "Update available");
        }

        OnlineMapsUpdater.CheckNewVersionAvailable();
    }
    /// <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;
        }
    }
    private void Start()
    {
        map = OnlineMaps.instance;

        double lng, lat;

        map.GetPosition(out lng, out lat);
        map.projection.CoordinatesToTile(lng, lat, map.zoom, out tileX, out tileY);
        map.OnChangePosition += OnChangePosition;
    }
Ejemplo n.º 10
0
        private void Start()
        {
            map = OnlineMaps.instance;

            map.GetPosition(out lng, out lat);

            marker           = OnlineMapsMarker3DManager.CreateItem(lng, lat, prefab);
            marker.scale     = markerScale;
            marker.rotationY = rotation;
        }
Ejemplo n.º 11
0
    private void Start()
    {
        map         = GetComponent <OnlineMaps>();
        cameraOrbit = GetComponent <OnlineMapsCameraOrbit>();

        double lng, lat;

        map.GetPosition(out lng, out lat);
        map.projection.CoordinatesToTile(lng, lat, map.zoom, out tileX, out tileY);
        map.OnChangePosition += OnChangePosition;
    }
    private void OnChangePosition()
    {
        if (ignoreChangePosition)
        {
            return;
        }

        double lng, lat;

        map.GetPosition(out lng, out lat);
        map.projection.CoordinatesToTile(lng, lat, map.zoom, out tileX, out tileY);
    }
Ejemplo n.º 13
0
        private void Start()
        {
            OnlineMaps api = OnlineMaps.instance;

            Vector3 position = OnlineMapsTileSetControl.instance.GetWorldPosition(api.position);

            position.y = altitude *
                         OnlineMapsTileSetControl.instance.GetBestElevationYScale(api.topLeftPosition,
                                                                                  api.bottomRightPosition) * OnlineMapsTileSetControl.instance.elevationScale;
            gameObject.transform.position = position;

            api.GetPosition(out px, out py);
        }
Ejemplo n.º 14
0
        private void Start()
        {
            map     = OnlineMaps.instance;
            control = OnlineMapsTileSetControl.instance;

            control.OnMapClick += OnMapClick;

            map.GetPosition(out lng, out lat);

            marker           = OnlineMapsMarker3DManager.CreateItem(lng, lat, prefab);
            marker.scale     = markerScale;
            marker.rotationY = rotation;
        }
    public OnlineMapsBuffer(OnlineMaps map)
    {
        this.map = map;

        lastState = new StateProps
        {
            floatZoom = map.floatZoom,
            width     = map.width,
            height    = map.height
        };

        map.GetPosition(out lastState.longitude, out lastState.latitude);
        map.GetCorners(out lastState.leftLongitude, out lastState.topLatitude, out lastState.rightLongitude, out lastState.bottomLatitude);
        renderState = lastState;

        newTiles = new List <OnlineMapsTile>();
    }
Ejemplo n.º 16
0
        private void Start()
        {
            map              = OnlineMaps.instance;
            control          = OnlineMapsTileSetControl.instance;
            elevationManager = OnlineMapsElevationManagerBase.instance;

            double tlx, tly, brx, bry;

            map.GetCorners(out tlx, out tly, out brx, out bry);

            Vector3 position = control.GetWorldPosition(map.position);

            position.y = altitude;
            if (elevationManager != null)
            {
                position.y *= OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry) * elevationManager.scale;
            }

            gameObject.transform.position = position;
            map.GetPosition(out px, out py);
        }
Ejemplo n.º 17
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();
    }
Ejemplo n.º 18
0
    private void OnEnable()
    {
        api = (OnlineMaps) target;

        double lng, lat;
        api.GetPosition(out lng, out lat);

        if (api._position != Vector2.zero && lng == 0 && lat == 0)
        {
            api.position = api._position;
            api._position = Vector2.zero;
        }

        if (api.defaultMarkerTexture == null) api.defaultMarkerTexture = GetIcon("DefaultMarker.png");
        if (api.skin == null)
        {
            api.skin =
                (GUISkin)
                    AssetDatabase.LoadAssetAtPath("Assets/Infinity Code/Online maps/Skin/DefaultSkin.guiskin",
                        typeof (GUISkin));
        }

        string[] files = Directory.GetFiles("Assets", "update_available.png", SearchOption.AllDirectories);
        if (files.Length > 0)
        {
            Texture updateAvailableIcon = AssetDatabase.LoadAssetAtPath(files[0], typeof (Texture)) as Texture;
            updateAvailableContent = new GUIContent("Update Available", updateAvailableIcon, "Update available");
        }

        OnlineMapsUpdater.CheckNewVersionAvailable();
    }
Ejemplo n.º 19
0
    public void GenerateFrontBuffer()
    {
        try
        {
            api.GetPosition(out apiLongitude, out apiLatitude);
            apiZoom = api.zoom;
            while (true)
            {
#if !UNITY_WEBGL
                while (status != OnlineMapsBufferStatus.start && api.renderInThread)
                {
                    if (disposed)
                    {
                        return;
                    }
                    Thread.Sleep(1);
                }
#endif
                status = OnlineMapsBufferStatus.working;
                double px = 0, py = 0;

                try
                {
                    api.GetPosition(out px, out py);
                    int zoom = api.zoom;

                    bool fullRedraw = redrawType == OnlineMapsRedrawType.full;

                    if (disposed)
                    {
                        fullRedraw = true;
                        disposed   = false;
                    }
                    else if (newTiles != null && api.target == OnlineMapsTarget.texture)
                    {
                        ApplyNewTiles();
                    }

                    bool backBufferUpdated = UpdateBackBuffer(px, py, zoom, fullRedraw);

                    if (api.target == OnlineMapsTarget.texture)
                    {
                        GetFrontBufferPosition(px, py, bufferPosition, zoom, api.width, api.height);

                        if (backBufferUpdated)
                        {
                            foreach (OnlineMapsDrawingElement element in api.drawingElements)
                            {
                                element.Draw(backBuffer, bufferPosition, width, height, zoom);
                            }
                            SetMarkersToBuffer(api.markers);
                        }

                        if (!api.useSmartTexture || !generateSmartBuffer)
                        {
                            UpdateFrontBuffer(api.width, api.height);
                        }
                        else
                        {
                            UpdateSmartBuffer(api.width, api.height);
                        }
                    }
                }
                catch (Exception exception)
                {
                    Debug.Log(exception.Message + "\n" + exception.StackTrace);
                }

                status       = OnlineMapsBufferStatus.complete;
                apiLongitude = px;
                apiLatitude  = py;
                apiZoom      = api.zoom;

                if (needUnloadTiles)
                {
                    UnloadOldTiles();
                }

#if !UNITY_WEBGL
                if (api.renderInThread && !api.needGC)
                {
                    GC.Collect();
                }
                if (!api.renderInThread)
                {
                    break;
                }
#else
                break;
#endif
            }
        }
        catch
        {
        }
    }
    public void GenerateFrontBuffer()
    {
        try
        {
            lastState = new StateProps
            {
                floatZoom = map.floatZoom,
                width     = map.width,
                height    = map.height
            };

            map.GetPosition(out lastState.longitude, out lastState.latitude);
            map.GetCorners(out lastState.leftLongitude, out lastState.topLatitude, out lastState.rightLongitude, out lastState.bottomLatitude);

            while (!disposed)
            {
#if !UNITY_WEBGL
                while (status != OnlineMapsBufferStatus.start && map.renderInThread)
                {
                    if (disposed)
                    {
                        return;
                    }
                    OnlineMapsUtils.ThreadSleep(1);
                }
#endif

                status = OnlineMapsBufferStatus.working;

                renderState = new StateProps
                {
                    floatZoom = map.floatZoom,
                    width     = map.width,
                    height    = map.height
                };

                try
                {
                    map.GetPosition(out renderState.longitude, out renderState.latitude);
                    map.GetCorners(out renderState.leftLongitude, out renderState.topLatitude, out renderState.rightLongitude, out renderState.bottomLatitude);

                    if (newTiles != null && map.control.resultIsTexture)
                    {
                        ApplyNewTiles();
                    }

                    if (disposed)
                    {
                        return;
                    }

                    UpdateBackBuffer(renderState.longitude, renderState.latitude, renderState.zoom);
                    if (disposed)
                    {
                        return;
                    }

                    if (map.control.resultIsTexture)
                    {
                        GetFrontBufferPosition(renderState.longitude, renderState.latitude, bufferPosition, renderState.floatZoom, renderState.width, renderState.height);
                        UpdateFrontBuffer(renderState.width, renderState.height, renderState.floatZoom);

                        if (disposed)
                        {
                            return;
                        }

                        foreach (OnlineMapsDrawingElement element in OnlineMapsDrawingElementManager.instance)
                        {
                            if (disposed)
                            {
                                return;
                            }
                            element.Draw(frontBuffer, new Vector2(bufferPosition.x + (float)frontBufferPosition.x / OnlineMapsUtils.tileSize, bufferPosition.y + (float)frontBufferPosition.y / OnlineMapsUtils.tileSize), renderState.width, renderState.height, renderState.floatZoom);
                        }

                        if (map.control.OnDrawMarkers != null)
                        {
                            map.control.OnDrawMarkers();
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (disposed)
                    {
                        return;
                    }
                    Debug.Log(exception.Message + "\n" + exception.StackTrace);
                }

                status = OnlineMapsBufferStatus.complete;

                lastState = renderState;
#if !UNITY_WEBGL
                if (!map.renderInThread)
                {
                    break;
                }
#else
                break;
#endif
            }
        }
        catch
        {
        }
    }