Beispiel #1
1
        /// <summary>
        /// Creates an instance of this class
        /// </summary>
        public MagnifierTool(MapBox parentMapBox) 
            : base("Magnifier", "A tool to magnify the portion of the map below the cursor")
        {
            _parentMapBox = parentMapBox;
            _parentMapBox.MapChanged += HandleMapChanged;
            Map = _parentMapBox.Map;

            MagnificationFactor = 1.10;

            Offset = new Size(5,5);

            _magnified = new PictureBox();
            _magnified.Size = new Size(75, 75);
            _magnified.BorderStyle = BorderStyle.FixedSingle;
            _magnified.Visible = false;

            _parentMapBox.Controls.Add(_magnified);

            Map = _parentMapBox.Map;
            _map = Map.Clone();
            _map.Size = _magnified.Size;
            _map.Zoom = _map.Size.Width*(Map.Envelope.Width/Map.Size.Width) / _magnification;
            _map.Center = _map.Center;
            _magnified.Image = _map.GetMap();

            Enabled = true;

            var ms = Assembly.GetExecutingAssembly().GetManifestResourceStream("WinFormSamples.Magnifier.cur");
            if (ms != null)
                Cursor = new Cursor(ms);
        }
Beispiel #2
0
        public static void LoadTileWebLayer(MapBox mapbox, TileWebObjectType tileType)
        {

            if (mapbox != null)
            {
                try
                {
                    switch (tileType)
                    {
                        case TileWebObjectType.GoogleMap:
                            maplayer = new TileAsyncLayer(new GoogleTileSource(GoogleMapType.GoogleMap), "TileLayer - Google");
                            break;

                        case TileWebObjectType.OpenStreetMap:
                            maplayer = new TileAsyncLayer(new OsmTileSource(), "TileLayer - OSM");
                            break;

                        case TileWebObjectType.BingMap:
                            maplayer = new TileAsyncLayer(new BingTileSource(BingRequest.UrlBing, "", BingMapType.Roads), "TileLayer - Bing");
                            break;

                        default:
                            break;
                    }

                    mapbox.Map.BackgroundLayer.Add(maplayer);
                    IMathTransform mathTransform = ProjectionHelper.Wgs84toGoogleMercator.MathTransform;
                    Envelope geom = GeometryTransform.TransformBox(new Envelope(-9.205626, -9.123736, 38.690993, 38.740837), mathTransform);
                    mapbox.Map.ZoomToBox(geom);
                    mapbox.Map.Zoom = 20000;
                    mapbox.Invalidate();
                }
                catch
                {
                    throw new Exception("The mapbox doesnot exist!");
                }
 
            }
        }
Beispiel #3
0
 public MouseWheelGrabber(MapBox redirectHandle)
 {
     this.redirectHandle = redirectHandle;
 }
Beispiel #4
0
 public SampleTool(MapBox mapBox1) : this()
 {
     MapControl = mapBox1;
     MapControl.MapChanged += (sender, args) => { HandleCancel(); };
     _cts.Token.Register(HandleCancel);
 }
Beispiel #5
0
        private void changeMode(MapBox.Tools tool)
        {
            MainMapImage.ActiveTool = tool;

            ZoomInModeToolStripButton.Checked = (tool == MapBox.Tools.ZoomIn);
            ZoomOutModeToolStripButton.Checked = (tool == MapBox.Tools.ZoomOut);
            PanToolStripButton.Checked = (tool == MapBox.Tools.Pan);
            QueryModeToolStripButton.Checked = (tool == MapBox.Tools.QueryBox);
        }
Beispiel #6
0
        protected virtual void TrySetActiveTool(System.Windows.Forms.ToolStripButton btn, MapBox.Tools associtatedTool)
        {
            var isChecked = btn.Checked;

            Debug.WriteLine("Trying to {0} active tool '{1}' by {2}.", isChecked ? "set" : "unset", associtatedTool, btn.Name);
            //if (Logger.IsDebugEnabled)
            //  Logger.DebugFormat("Trying to {0} active tool '{1}' by ", isChecked ? "set" : "unset", associtatedTool, btn.Name);

            if (isChecked && MapControl.ActiveTool == associtatedTool)
            {
                Debug.WriteLine(" ... not needed");
                return;
            }

            if (!isChecked && MapControl.ActiveTool == associtatedTool)
            {
                MapControl.ActiveTool = MapBox.Tools.None;
                Debug.WriteLine(" ... done");
                return;
            }

            if (isChecked && MapControl.ActiveTool != associtatedTool)
            {
                MapControl.ActiveTool = associtatedTool;
                Debug.WriteLine(" ... finally done");
            }
        }
 private void mapImage_ActiveToolChanged(MapBox.Tools tool)
 {
     UpdatePropertyGrid();
 }
Beispiel #8
0
        public Form3()
        {
            InitializeComponent();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form3));
            this.components = new System.ComponentModel.Container();

            this.mapBox1           = new SharpMap.Forms.MapBox();
            this.mapZoomToolStrip1 = new SharpMap.Forms.ToolBar.MapZoomToolStrip(this.components);
            this.toolsbIdentity    = new System.Windows.Forms.ToolStripButton();
            this.mapZoomToolStrip1.SuspendLayout();

            //
            // mapBox1
            //
            this.mapBox1.ActiveTool         = SharpMap.Forms.MapBox.Tools.None;
            this.mapBox1.BackColor          = System.Drawing.Color.White;
            this.mapBox1.Cursor             = System.Windows.Forms.Cursors.Default;
            this.mapBox1.Dock               = System.Windows.Forms.DockStyle.Fill;
            this.mapBox1.FineZoomFactor     = 10D;
            this.mapBox1.Location           = new System.Drawing.Point(0, 0);
            this.mapBox1.MapQueryMode       = SharpMap.Forms.MapBox.MapQueryType.LayerByIndex;
            this.mapBox1.Name               = "mapBox1";
            this.mapBox1.QueryGrowFactor    = 5F;
            this.mapBox1.QueryLayerIndex    = 0;
            this.mapBox1.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(210)))), ((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244)))));
            this.mapBox1.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244)))));
            this.mapBox1.ShowProgressUpdate = false;
            this.mapBox1.Size               = new System.Drawing.Size(580, 407);
            this.mapBox1.TabIndex           = 0;
            this.mapBox1.Text               = "mapBox1";
            this.mapBox1.WheelZoomMagnitude = -2D;
            this.mapBox1.MapQueried        += new SharpMap.Forms.MapBox.MapQueryHandler(this.mapBox1_MapQueried);
            //
            // mapZoomToolStrip1
            //
            this.mapZoomToolStrip1.Enabled = false;
            this.mapZoomToolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
                this.toolsbIdentity
            });
            this.mapZoomToolStrip1.Location   = new System.Drawing.Point(0, 0);
            this.mapZoomToolStrip1.MapControl = this.mapBox1;
            this.mapZoomToolStrip1.Name       = "mapZoomToolStrip1";
            this.mapZoomToolStrip1.Size       = new System.Drawing.Size(580, 25);
            this.mapZoomToolStrip1.TabIndex   = 2;
            this.mapZoomToolStrip1.Text       = "mapZoomToolStrip1";
            //
            // toolsbIdentity
            //
            this.toolsbIdentity.DisplayStyle          = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolsbIdentity.Image                 = ((System.Drawing.Image)(resources.GetObject("identify")));
            this.toolsbIdentity.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolsbIdentity.Name   = "toolsbIdentity";
            this.toolsbIdentity.Size   = new System.Drawing.Size(23, 22);
            this.toolsbIdentity.Text   = "查询";
            this.toolsbIdentity.Click += new System.EventHandler(this.toolsbIdentity_Click);

            this.Controls.Add(this.mapZoomToolStrip1);
            this.Controls.Add(this.mapBox1);

            this.mapZoomToolStrip1.ResumeLayout(false);
            this.mapZoomToolStrip1.PerformLayout();

            this.mapBox1.Map.Layers.Clear();

            SharpMap.Layers.VectorLayer vlayer = new SharpMap.Layers.VectorLayer("states");
            string start = Application.StartupPath;
            string path  = @"D:\workspace\Code\2016\ExcelReader\ExcelReader\bin\Debug\tmp.shp";

            vlayer.DataSource          = new SharpMap.Data.Providers.ShapeFile(path);
            vlayer.Style.Fill          = new SolidBrush(Color.GreenYellow);
            vlayer.Style.Outline       = System.Drawing.Pens.Gray;
            vlayer.Style.EnableOutline = true;
            mapBox1.Map.Layers.Add(vlayer);


            SharpMap.Layers.LabelLayer labelLayer = new LabelLayer("label");
            labelLayer.DataSource               = vlayer.DataSource;
            labelLayer.Enabled                  = true;
            labelLayer.LabelColumn              = "mapNo";
            labelLayer.Style                    = new SharpMap.Styles.LabelStyle();
            labelLayer.Style.ForeColor          = Color.Black;
            labelLayer.Style.Font               = new System.Drawing.Font(FontFamily.GenericSerif, 13);
            labelLayer.Style.Offset             = new PointF(3, 3);
            labelLayer.Style.Halo               = new Pen(Color.Yellow, 2);
            labelLayer.TextRenderingHint        = System.Drawing.Text.TextRenderingHint.AntiAlias;
            labelLayer.SmoothingMode            = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            labelLayer.LabelFilter              = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
            labelLayer.Style.CollisionDetection = true;
            labelLayer.MaxVisible               = 200000;
            mapBox1.Map.Layers.Add(labelLayer);


            mapBox1.Map.ZoomToExtents();
            mapBox1.Refresh();
        }
Beispiel #9
0
        private void Form2_Load(object sender, EventArgs e)
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2));


            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.ZoomWindowToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.ZoomInToolStripButton     = new System.Windows.Forms.ToolStripButton();
            this.ZoomOutToolStripButton    = new System.Windows.Forms.ToolStripButton();
            this.PanToolStripButton        = new System.Windows.Forms.ToolStripButton();
            this.PreviousToolStripButton   = new System.Windows.Forms.ToolStripButton();
            this.NextToolStripButton       = new System.Windows.Forms.ToolStripButton();
            this.QueryToolStripButton      = new System.Windows.Forms.ToolStripButton();
            this.toolStrip1.SuspendLayout();

            //
            // toolStrip1
            //
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
                this.ZoomWindowToolStripButton,
                this.ZoomInToolStripButton,
                this.ZoomOutToolStripButton,
                this.PanToolStripButton,
                this.PreviousToolStripButton,
                this.NextToolStripButton,
                this.QueryToolStripButton
            });
            this.toolStrip1.Location = new System.Drawing.Point(0, 0);
            this.toolStrip1.Name     = "toolStrip1";
            this.toolStrip1.Size     = new System.Drawing.Size(735, 31);
            this.toolStrip1.TabIndex = 1;
            this.toolStrip1.Text     = "toolStrip1";
            //
            // toolStripButton1
            //
            this.ZoomWindowToolStripButton.DisplayStyle          = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.ZoomWindowToolStripButton.Image                 = ((System.Drawing.Image)(resources.GetObject("globe")));
            this.ZoomWindowToolStripButton.ImageScaling          = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.ZoomWindowToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.ZoomWindowToolStripButton.Name   = "toolStripButton1";
            this.ZoomWindowToolStripButton.Size   = new System.Drawing.Size(28, 28);
            this.ZoomWindowToolStripButton.Text   = "全图";
            this.ZoomWindowToolStripButton.Click += new EventHandler(ZoomWindowToolStripButton_Click);
            //
            // toolStripButton2
            //
            this.ZoomInToolStripButton.DisplayStyle          = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.ZoomInToolStripButton.Image                 = ((System.Drawing.Image)(resources.GetObject("zoomin")));
            this.ZoomInToolStripButton.ImageScaling          = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.ZoomInToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.ZoomInToolStripButton.Name   = "toolStripButton2";
            this.ZoomInToolStripButton.Size   = new System.Drawing.Size(26, 28);
            this.ZoomInToolStripButton.Text   = "放大";
            this.ZoomInToolStripButton.Click += new EventHandler(ZoomInToolStripButton_Click);

            //
            // toolStripButton3
            //
            this.ZoomOutToolStripButton.DisplayStyle          = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.ZoomOutToolStripButton.Image                 = ((System.Drawing.Image)(resources.GetObject("zoomout")));
            this.ZoomOutToolStripButton.ImageScaling          = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.ZoomOutToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.ZoomOutToolStripButton.Name   = "toolStripButton3";
            this.ZoomOutToolStripButton.Size   = new System.Drawing.Size(26, 28);
            this.ZoomOutToolStripButton.Text   = "缩小";
            this.ZoomOutToolStripButton.Click += new EventHandler(ZoomOutToolStripButton_Click);
            //
            // toolStripButton4
            //
            this.PanToolStripButton.DisplayStyle          = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.PanToolStripButton.Image                 = ((System.Drawing.Image)(resources.GetObject("hand")));
            this.PanToolStripButton.ImageScaling          = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.PanToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.PanToolStripButton.Name   = "toolStripButton4";
            this.PanToolStripButton.Size   = new System.Drawing.Size(28, 28);
            this.PanToolStripButton.Text   = "平移";
            this.PanToolStripButton.Click += new EventHandler(PanToolStripButton_Click);
            //
            // toolStripButton6
            //
            this.PreviousToolStripButton.DisplayStyle          = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.PreviousToolStripButton.Image                 = ((System.Drawing.Image)(resources.GetObject("previous")));
            this.PreviousToolStripButton.ImageScaling          = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.PreviousToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.PreviousToolStripButton.Name   = "toolStripButton6";
            this.PreviousToolStripButton.Size   = new System.Drawing.Size(28, 28);
            this.PreviousToolStripButton.Text   = "前一视图";
            this.PreviousToolStripButton.Click += new EventHandler(PreviousToolStripButton_Click);
            //
            // toolStripButton7
            //
            this.NextToolStripButton.DisplayStyle          = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.NextToolStripButton.Image                 = ((System.Drawing.Image)(resources.GetObject("next")));
            this.NextToolStripButton.ImageScaling          = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.NextToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.NextToolStripButton.Name   = "toolStripButton7";
            this.NextToolStripButton.Size   = new System.Drawing.Size(28, 28);
            this.NextToolStripButton.Text   = "后一视图";
            this.NextToolStripButton.Click += new EventHandler(NextToolStripButton_Click);
            //
            // toolStripButton8
            //
            this.QueryToolStripButton.DisplayStyle          = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.QueryToolStripButton.Image                 = ((System.Drawing.Image)(resources.GetObject("identify")));
            this.QueryToolStripButton.ImageScaling          = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.QueryToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.QueryToolStripButton.Name   = "toolStripButton8";
            this.QueryToolStripButton.Size   = new System.Drawing.Size(28, 28);
            this.QueryToolStripButton.Text   = "查询";
            this.QueryToolStripButton.Click += new EventHandler(QueryToolStripButton_Click);
            this.Controls.Add(this.toolStrip1);

            //
            // button2
            //
            this.button2          = new System.Windows.Forms.Button();
            this.button2.Location = new System.Drawing.Point(158, 99);
            this.button2.Name     = "button2";
            this.button2.Size     = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 0;
            this.button2.Text     = "button2";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new EventHandler(button2_Click);
            this.Controls.Add(this.button2);


            //
            // mapBox1
            //
            this.mapBox1                      = new SharpMap.Forms.MapBox();
            this.mapBox1.ActiveTool           = SharpMap.Forms.MapBox.Tools.None;
            this.mapBox1.BackColor            = System.Drawing.Color.White;
            this.mapBox1.Cursor               = System.Windows.Forms.Cursors.Default;
            this.mapBox1.Dock                 = System.Windows.Forms.DockStyle.Fill;
            this.mapBox1.FineZoomFactor       = 10D;
            this.mapBox1.Location             = new System.Drawing.Point(0, 78);
            this.mapBox1.MapQueryMode         = SharpMap.Forms.MapBox.MapQueryType.LayerByIndex;
            this.mapBox1.Name                 = "mapBox1";
            this.mapBox1.QueryGrowFactor      = 5F;
            this.mapBox1.QueryLayerIndex      = 0;
            this.mapBox1.SelectionBackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(210)))), ((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244)))));
            this.mapBox1.SelectionForeColor   = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244)))));
            this.mapBox1.ShowProgressUpdate   = false;
            this.mapBox1.Size                 = new System.Drawing.Size(527, 317);
            this.mapBox1.TabIndex             = 0;
            this.mapBox1.Text                 = "mapBox1";
            this.mapBox1.WheelZoomMagnitude   = -2D;
            this.mapBox1.MapQueried          += new SharpMap.Forms.MapBox.MapQueryHandler(mapBox1_MapQueried);
            this.mapBox1.Map.MapViewOnChange += new SharpMap.Map.MapViewChangedHandler(Map_MapViewOnChange);
            this.mapBox1.MouseDown           += new MapBox.MouseEventHandler(mapBox1_MouseDown);
            this.mapBox1.MouseUp             += new MapBox.MouseEventHandler(mapBox1_MouseUp);
            this.Controls.Add(this.mapBox1);

            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();

            this.mapBox1.Map.Layers.Clear();

            SharpMap.Layers.VectorLayer vlayer = new SharpMap.Layers.VectorLayer("states");
            string start = Application.StartupPath;
            string path  = @"E:\workspace\Code\2016\ExcelReader\ExcelReader\bin\Debug\tmp.shp";

            vlayer.DataSource          = new SharpMap.Data.Providers.ShapeFile(path);
            vlayer.Style.Fill          = new SolidBrush(Color.GreenYellow);
            vlayer.Style.Outline       = System.Drawing.Pens.Gray;
            vlayer.Style.EnableOutline = true;
            mapBox1.Map.Layers.Add(vlayer);


            SharpMap.Layers.LabelLayer labelLayer = new LabelLayer("label");
            labelLayer.DataSource               = vlayer.DataSource;
            labelLayer.Enabled                  = true;
            labelLayer.LabelColumn              = "mapNo";
            labelLayer.Style                    = new SharpMap.Styles.LabelStyle();
            labelLayer.Style.ForeColor          = Color.Black;
            labelLayer.Style.Font               = new System.Drawing.Font(FontFamily.GenericSerif, 13);
            labelLayer.Style.Offset             = new PointF(3, 3);
            labelLayer.Style.Halo               = new Pen(Color.Yellow, 2);
            labelLayer.TextRenderingHint        = System.Drawing.Text.TextRenderingHint.AntiAlias;
            labelLayer.SmoothingMode            = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            labelLayer.LabelFilter              = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
            labelLayer.Style.CollisionDetection = true;
            labelLayer.MaxVisible               = 200000;
            mapBox1.Map.Layers.Add(labelLayer);


            mapBox1.Map.ZoomToExtents();
            mapBox1.Refresh();
        }
Beispiel #10
0
 public MouseWheelGrabber(MapBox redirectHandle)
 {
     _redirectHandle = redirectHandle;
     _redirectHandle.MouseEnter += HandleMouseEnter;
     _redirectHandle.MouseLeave += HandleMouseLeave;
 }