Exemplo n.º 1
0
        private void ZoomInternal(IMapNode node)
        {
            if (ZoomedNode == node)
            {
                return;
            }

            ZoomedNode = node;
            OnZoomed?.Invoke(ZoomedNode);

            Bind();
        }
Exemplo n.º 2
0
        public void OnDrag(PointerEventData eventData)
        {
            if (Input.touchCount == 1 || Input.touchCount == 0)
            {
                _movingInput = eventData.delta;
                _movingAcceleration.Enqueue(_movingInput);

                OnMoved?.Invoke(MovingDirection, CurrentState.Change);
            }
            else if (Input.touchCount == 2)
            {
                _movingInput = eventData.delta;
                _movingAcceleration.Enqueue(_movingInput);

                OnMoved?.Invoke(MovingDirection, CurrentState.Change);

                var distance = Vector2.Distance(Input.touches[0].position, Input.touches[1].position) /
                               Vector2.Distance(Input.touches[0].position - Input.touches[0].deltaPosition, Input.touches[1].position - Input.touches[1].deltaPosition);

                _zoomInput = distance - 1;

                OnZoomed?.Invoke(ZoomDelta, Vector2.Lerp(Input.touches[0].position, Input.touches[1].position, 0.5f));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the logic of Dragging/Dropping/Zooming the map.
        /// This is basically said the logic handler of the control.
        /// It is called quite a lot of times, the delta of two calls may be calculated out of the passed GameTime parameter.
        /// </summary>
        /// <param name="time">The time passed since the game started.</param>
        public void Update(GameTime time, InputArgs input)
        {
            // Clean up icon texture cache...
            var keys = _markerTextures.Keys;

            foreach (string key in keys)
            {
                if (Markers.All(m => m.TextureIdentifier != key))
                {
                    _markerTextures[key].Dispose();
                    _markerTextures.Remove(key);
                }
            }

            // drag&drop handling
            MouseState currentState = input.MouseState;

            MapVector mousePos = new MapVector()
            {
                X = currentState.X, Y = currentState.Y
            };

            if (_dragging && CanMove)
            {
                MapVector oldVector = new MapVector()
                {
                    X = _oldMouseState.X, Y = _oldMouseState.Y
                };

                MapVector offset = (oldVector - mousePos) / _map.CoordinateScale;

                MapVector centerMapVector    = _map.LatLonToMapPoint(_map.Position);
                MapVector newCenterMapVector = centerMapVector + offset;

                // real a mod b:
                // a mod b = (a % b + b) % b
                // https://de.wikipedia.org/wiki/Division_mit_Rest#Modulo
                // We do this to allow scrollen over the maps borders.
                newCenterMapVector.X = ((newCenterMapVector.X % _map.MapCoordinatesWidth) + _map.MapCoordinatesWidth) % _map.MapCoordinatesWidth;
                newCenterMapVector.Y = ((newCenterMapVector.Y % _map.MapCoordinatesHeight) + _map.MapCoordinatesHeight) % _map.MapCoordinatesHeight;


                MapPointLatLon newCenterGeoPoint = _map.MapPointToLatLon(newCenterMapVector);

                _map.Position = newCenterGeoPoint;

                OnMoved?.Invoke(this, _map.Position);
            }

            int wheel = _oldMouseState.ScrollWheelValue - currentState.ScrollWheelValue;

            bool zoom    = false;
            int  newZoom = 0;

            if (wheel < 0)
            {
                if (_map.Zoom < _map.MaxZoom)
                {
                    zoom    = true;
                    newZoom = _map.Zoom + 1;
                }
            }
            else if (wheel > 0)
            {
                if (_map.Zoom > _map.MinZoom)
                {
                    zoom    = true;
                    newZoom = _map.Zoom - 1;
                }
            }

            if (zoom && CanZoom)
            {
                switch (ZoomMode)
                {
                case ZoomingType.Center:
                    SetZoomCenter(newZoom);
                    break;

                case ZoomingType.Mouse:
                    MapVector viewPos = mousePos -
                                        _map.ViewBounds.Location;
                    SetZoomMouse(newZoom, viewPos);
                    break;
                }

                OnZoomed?.Invoke(this, _map.Zoom);
            }

            if ((_oldMouseState.LeftButton == ButtonState.Pressed) && currentState.LeftButton == ButtonState.Released)
            {
                // Mouse up
                _dragging = false;
            }
            else if ((_oldMouseState.LeftButton == ButtonState.Released) && currentState.LeftButton == ButtonState.Pressed)
            {
                // Mouse down
                _dragging = true;
            }

            if (_oldMouseState.RightButton == ButtonState.Pressed && currentState.RightButton == ButtonState.Released)
            {
                OnRightClick?.Invoke(this, _map.ViewPointToLatLon(mousePos));
            }

            _oldMouseState = currentState;
        }