Beispiel #1
0
        public MapLayer(Game game, LayerServiceConfig config) : base(game, config)
        {
            Transform = Matrix.Transformation(Vector3.Zero, Quaternion.Identity, Vector3.One, Vector3.Zero, Quaternion.Identity, Vector3.Zero);

            sb = Game.GetService <SpriteBatch>();

            RegisterMapSources();
            CurrentMapSource = MapSources[0];

            //Game.InputDevice.MouseMove += InputDeviceOnMouseMove;

            InitShaderAndBuffer();
        }
Beispiel #2
0
        public override void Update(GameTime gameTime)
        {
            var rs = Game.GraphicsDevice;

            Vector3    scale, translation;
            Quaternion rotation;

            Transform.Decompose(out scale, out rotation, out translation);

            Offset = new Vector2(translation.X, translation.Y);
            Zoom   = scale.X * 1280;

            //rs.DebugStrings.Add("Offset :" + Offset);
            //rs.DebugStrings.Add("Zoom :" + Zoom);


            var oldProj = CurrentMapSource.Projection;

            CurrentMapSource.Update(gameTime);

            CurrentMapSource = MapSources[(int)Config.MapSource];

            if (!oldProj.Equals(CurrentMapSource.Projection))
            {
                if (OnProjectionChanged != null)
                {
                    OnProjectionChanged.Invoke(this);
                }
            }


            var ms = Game.InputDevice.GlobalMouseOffset;

            int wheelDelta = Game.InputDevice.TotalMouseScroll - oldMouseScroll;

            if (wheelDelta > 0)
            {
                ZoomMap(new Vector2(ms.X, ms.Y), 1.1f);
            }
            else if (wheelDelta < 0)
            {
                ZoomMap(new Vector2(ms.X, ms.Y), 0.9f);
            }


            oldMouseScroll = Game.InputDevice.TotalMouseScroll;

            int vw = rs.DisplayBounds.Width;
            int vh = rs.DisplayBounds.Height;

            CenterPositionScreen   = new Vector2(vw / 2, vh / 2);
            CenterPositionMercator = (CenterPositionScreen - Offset) / Zoom;

            if (CurrentMapSource is YandexMap)
            {
                //CenterPositionWorld = MercatorProjectionYandex.Instance.TileToWorldPos((double)CenterPositionMercator.X * 256.0, (double)CenterPositionMercator.Y * 256.0, 0);
            }
            else
            {
                CenterPositionWorld = GeoHelper.TileToWorldPos(CenterPositionMercator.X, CenterPositionMercator.Y, 0);
            }

            DragToCenterPositionWorld();


            float currentLevel = Zoom / CurrentMapSource.TileSize;

            Level = (float)Math.Log(currentLevel, 2);

            base.Update(gameTime);
        }