Beispiel #1
0
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            if (_mapTransform == null)
                return;

            var res = _mapTransform.UnitsPerPixel;
            float factor;
            if (e.Delta < 0)
                factor = 1.2f;
            else if (e.Delta > 0)
                factor = 1 / 1.2f;
            else
                return;

            var center = new PointF(picMap.Width * 0.5f, picMap.Height * 0.5f);
            var point = new PointF(e.X, e.Y);

            var dx = (center.X - point.X) * factor;
            var dy = (center.Y - point.Y) * factor;

            var newCenter = _mapTransform.MapToWorld(point.X + dx, point.Y + dy);

            var transform = new MapTransform(newCenter, res * factor, picMap.Width, picMap.Height);
            _mapTransform = transform;
            RenderToBuffer();

            base.OnMouseWheel(e);
        }
Beispiel #2
0
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            if (_mapTransform == null)
                return;

            var res = _mapTransform.UnitsPerPixel;
            float factor;
            if (e.Delta < 0)
                factor = 1.2f;
            else if (e.Delta > 0)
                factor = 1 / 1.2f;
            else
                return;

            var center = new PointF(picMap.Width * 0.5f, picMap.Height * 0.5f);
            var point = new PointF(e.X, e.Y);

            var dx = (center.X - point.X) * factor;
            var dy = (center.Y - point.Y) * factor;

            var newCenter = _mapTransform.MapToWorld(point.X + dx, point.Y + dy);

            var transform = new MapTransform(newCenter, res * factor, picMap.Width, picMap.Height);
            _mapTransform = transform;
            RenderToBuffer();

            base.OnMouseWheel(e);
        }
Beispiel #3
0
        private void getSampleFileFromInternetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var path    = Path.Combine(Path.GetTempPath(), "mapbox.haiti-terrain.mbtiles");
            var req     = WebRequest.Create("http://a.tiles.mapbox.com/mapbox/download/haiti-terrain.mbtiles");
            var success = true;

            try
            {
                Enabled = false;

                var tmpFile = Path.GetTempFileName();
                using (var response = req.GetResponse())
                {
                    using (var streamWriter = new BinaryWriter(File.OpenWrite(tmpFile)))
                    {
                        using (var stream = response.GetResponseStream())
                        {
                            var buffer = new byte[4 * 8192];
                            while (true)
                            {
                                if (stream != null)
                                {
                                    var read = stream.Read(buffer, 0, buffer.Length);
                                    if (read <= 0)
                                    {
                                        break;
                                    }
                                    streamWriter.Write(buffer, 0, read);
                                }
                            }
                        }
                    }
                }
                _source = null;
                File.Copy(tmpFile, path, true);
                File.Delete(tmpFile);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                success = false;
            }
            finally
            {
                if (success)
                {
                    _source = new MbTilesTileSource(new SQLiteConnectionString(path, false));
                    var scale = (float)(1.1 * Math.Max(_source.Schema.Extent.Width / picMap.Width, _source.Schema.Extent.Height / picMap.Height));
                    _mapTransform = new MapTransform(
                        new PointF((float)_source.Schema.Extent.CenterX, (float)_source.Schema.Extent.CenterY),
                        scale, picMap.Width, picMap.Height);

                    RenderToBuffer();
                }
                Enabled = true;
            }
        }
Beispiel #4
0
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            if (_mapTransform == null) return;
            if (picMap.Width == 0 || picMap.Height == 0) return;

            _buffer = new Bitmap(picMap.Width, picMap.Height);
            _mapTransform = new MapTransform(_mapTransform.Center, _mapTransform.UnitsPerPixel, picMap.Width, picMap.Height);
            RenderToBuffer();
        }
Beispiel #5
0
        private void picMap_MouseClick(object sender, MouseEventArgs e)
        {
            if (_mapTransform == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                var pt = _mapTransform.MapToWorld(e.X, e.Y);
                _mapTransform = new MapTransform(pt, _mapTransform.UnitsPerPixel, picMap.Width, picMap.Height);
                RenderToBuffer();
            }
        }
Beispiel #6
0
        protected override void OnLoad(EventArgs e)
        {
            /* http://a.tiles.mapbox.com/mapbox/download/haiti-terrain-grey.mbtiles */
            var path = Path.Combine(Path.GetTempPath(), "mapbox.haiti-terrain-grey.mbtiles");
            if (File.Exists(path))
            {
                _source = new MbTilesTileSource(new SQLiteConnectionString(path, false));
                var scale = (float)(1.1 * Math.Max(_source.Schema.Extent.Width / picMap.Width, _source.Schema.Extent.Height / picMap.Height));
                _mapTransform = new MapTransform(
                    new PointF((float)_source.Schema.Extent.CenterX, (float)_source.Schema.Extent.CenterY),
                    scale, picMap.Width, picMap.Height);

                RenderToBuffer();
            }
            base.OnLoad(e);
        }
Beispiel #7
0
        protected override void OnLoad(EventArgs e)
        {
            /* http://a.tiles.mapbox.com/mapbox/download/haiti-terrain-grey.mbtiles */
            var path = Path.Combine(Path.GetTempPath(), "mapbox.haiti-terrain-grey.mbtiles");
            if (File.Exists(path))
            {
                _source = new MbTilesTileSource(new SQLiteConnectionString(path, false));
                var scale = (float)(1.1 * Math.Max(_source.Schema.Extent.Width / picMap.Width, _source.Schema.Extent.Height / picMap.Height));
                _mapTransform = new MapTransform(
                    new PointF((float)_source.Schema.Extent.CenterX, (float)_source.Schema.Extent.CenterY),
                    scale, picMap.Width, picMap.Height);

                RenderToBuffer();
            }
            base.OnLoad(e);
        }
Beispiel #8
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofn = new OpenFileDialog())
            {
                ofn.Filter          = @"MbTiles file|*.mbtiles";
                ofn.FilterIndex     = 0;
                ofn.Multiselect     = false;
                ofn.CheckFileExists = true;
                if (ofn.ShowDialog() == DialogResult.OK)
                {
                    _source = new MbTilesTileSource(new SQLiteConnectionString(ofn.FileName, false));
                    var extent = _source.Schema.Extent;
                    var scale  = (float)(1.1 * Math.Max(extent.Width / picMap.Width, extent.Height / picMap.Height));
                    _mapTransform = new MapTransform(
                        new PointF((float)extent.CenterX, (float)extent.CenterY),
                        scale, picMap.Width, picMap.Height);

                    RenderToBuffer();
                }
            }
        }
Beispiel #9
0
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            if (_mapTransform == null) return;
            if (picMap.Width == 0 || picMap.Height == 0) return;

            _buffer = new Bitmap(picMap.Width, picMap.Height);
            _mapTransform = new MapTransform(_mapTransform.Center, _mapTransform.UnitsPerPixel, picMap.Width, picMap.Height);
            RenderToBuffer();
        }
Beispiel #10
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofn = new OpenFileDialog())
            {
                ofn.Filter = @"MbTiles file|*.mbtiles";
                ofn.FilterIndex = 0;
                ofn.Multiselect = false;
                ofn.CheckFileExists = true;
                if (ofn.ShowDialog() == DialogResult.OK)
                {
                    _source = new MbTilesTileSource(new SQLiteConnectionString(ofn.FileName, false));
                    var extent = _source.Extent;
                    var scale = (float)(1.1 * Math.Max(extent.Width / picMap.Width, extent.Height / picMap.Height));
                    _mapTransform = new MapTransform(
                        new PointF((float)extent.CenterX, (float)extent.CenterY),
                        scale, picMap.Width, picMap.Height);

                    RenderToBuffer();
                }
            }
        }
Beispiel #11
0
        private void getSampleFileFromInternetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var path = Path.Combine(Path.GetTempPath(), "mapbox.haiti-terrain.mbtiles");
            var req = WebRequest.Create("http://a.tiles.mapbox.com/mapbox/download/haiti-terrain.mbtiles");
            var success = true;
            try
            {
                Enabled = false;

                var tmpFile = Path.GetTempFileName();
                using (var response = req.GetResponse())
                {
                    using (var streamWriter = new BinaryWriter(File.OpenWrite(tmpFile)))
                    {
                        using (var stream = response.GetResponseStream())
                        {
                            var buffer = new byte[4 * 8192];
                            while (true)
                            {
                                var read = stream.Read(buffer, 0, buffer.Length);
                                if (read <= 0) break;
                                streamWriter.Write(buffer, 0, read);
                            }
                        }
                    }
                }
                _source = null;
                File.Copy(tmpFile, path, true);
                File.Delete(tmpFile);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                success = false;
            }
            finally
            {
                if (success)
                {
                    _source = new MbTilesTileSource(new SQLiteConnectionString(path, false));
                    var scale = (float)(1.1 * Math.Max(_source.Schema.Extent.Width / picMap.Width, _source.Schema.Extent.Height / picMap.Height));
                    _mapTransform = new MapTransform(
                        new PointF((float)_source.Schema.Extent.CenterX, (float)_source.Schema.Extent.CenterY),
                        scale, picMap.Width, picMap.Height);

                    RenderToBuffer();
                }
                Enabled = true;
            }
        }
Beispiel #12
0
 private void picMap_MouseClick(object sender, MouseEventArgs e)
 {
     if (_mapTransform == null) return;
     
     if (e.Button == MouseButtons.Left)
     {
         var pt = _mapTransform.MapToWorld(e.X, e.Y);
         _mapTransform = new MapTransform(pt, _mapTransform.UnitsPerPixel, picMap.Width, picMap.Height);
         RenderToBuffer();
     }
 }