MapWinGIS:SampleCode-C Sharp Net:Custom Zoom

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

 using System;
 using System.Collections.Generic;
 using System.Collections;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Text;
 using System.Windows.Forms;
 
 namespace MapWinGISTEST
 {
     public partial class Form1 : Form, MapWinGIS.ICallback
     {
         System.Collections.Hashtable m_Shapefiles;
         System.Collections.Hashtable m_Grids;
         
         // During initialization this sets some basic default parameters
         public Form1()
         {
             InitializeComponent();
             axMap1.SendMouseMove = true;
             axMap1.SendMouseDown = true;
 
             // Initialize hashtables so we don't get null object exceptions later
             m_Shapefiles = new System.Collections.Hashtable();
             m_Grids = new System.Collections.Hashtable();
             
         }
 
         /// <summary>
         /// This function allows the user to use a file dialog to add shapefiles to the demo project
         /// </summary>
         /// <param name="sender">Part of the windows forms architecture.  In this case the menu object.</param>
         /// <param name="e">The Parameters for the menu item click event.</param>
         private void addShapefileToolStripMenuItem_Click(object sender, EventArgs e)
         {
             bool result;
             OpenFileDialog OFD = new OpenFileDialog();
             MapWinGIS.Shapefile mwShapefile = new MapWinGIS.Shapefile();
             OFD.Filter = "Shapefiles (*.shp)|*.shp";
             if (OFD.ShowDialog() != DialogResult.OK) return;
             result = mwShapefile.Open(OFD.FileName, this);
             if (result == false)
             {
                 MessageBox.Show(mwShapefile.get_ErrorMsg(mwShapefile.LastErrorCode));
             }
             int lyr = axMap1.AddLayer(mwShapefile, true);
             m_Shapefiles.Add(lyr, mwShapefile);
         }
 
 
         /// <summary>
         /// This function prevents the default zoom behavior and allows for custom zooming behavior to be added.
         /// </summary>
         /// <param name="sender">The menu item being clicked</param>
         /// <param name="e">Parameters from the windows forms event</param>
         private void noZoomOutToolStripMenuItem_Click(object sender, EventArgs e)
         {
             axMap1.CursorMode = MapWinGIS.tkCursorMode.cmNone;
             axMap1.SendMouseDown = true;
         }
 
         /// <summary>
         /// This function intercepts the mouse down event from the activeX control
         /// </summary>
         /// <param name="sender">The map object</param>
         /// <param name="e">The mousedown event parameters</param>
         void axMap1_MouseDownEvent(object sender, AxMapWinGIS._DMapEvents_MouseDownEvent e)
         {
             if (e.button != 1) return; // return unless it was a Left Click
 
             // Prevent default zoom behavior
             if (axMap1.CursorMode != MapWinGIS.tkCursorMode.cmNone) return; 
 
             // Get the current map boundaries 
             MapWinGIS.Extents ext = axMap1.Extents as MapWinGIS.Extents; 
 
             // find 1/2 the width and height in order to center the image
             int dx = (int)((ext.xMax - ext.xMin) / 2);
             int dy = (int)((ext.yMax - ext.yMin) / 2);
             double x = 0;
             double y = 0;
 
             // Change the click location from screen coordinates to map coordinates
             axMap1.PixelToProj(e.x, e.y, ref x, ref y);
 
             // Center on the mouse click
             ext.SetBounds(x - dx, y - dy, 0, x + dx, y + dy, 0);
             axMap1.Extents = ext;
 
             // Zoom in by 10%
             axMap1.ZoomIn(.1);
         }
         
         void axMap1_MouseMoveEvent(object sender, AxMapWinGIS._DMapEvents_MouseMoveEvent e)
         {
             toolStripStatusLabel1.Text = "X: " + e.x.ToString() + ", Y: " + e.y.ToString();
         }
 
 
         #region ICallback Members
 
         void MapWinGIS.ICallback.Error(string KeyOfSender, string ErrorMsg)
         {
             MessageBox.Show(ErrorMsg, "Error");
         }
 
         void MapWinGIS.ICallback.Progress(string KeyOfSender, int Percent, string Message)
         {
             toolStripStatusLabel1.Text = Message;
             toolStripProgressBar1.Value = Percent;
             Application.DoEvents(); // Allow the interface to refresh
         }
 
         #endregion
 
     
 
        
        
 
               
     }
 }

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:SampleCode-C_Sharp_Net:Custom_Zoom"

This page has been accessed 3,597 times. This page was last modified on 18 April 2007, at 21:42.