📄 form1.cs
字号:
}
}
private void map1_OnMouseUp(MouseButtons Button, short Shift, GpsToolsNET.Position objPosition, GpsViewNET.Point objPoint)
{
// Check if we have a valid zoom
if (m_pointLast != null)
{
map1.ZoomByBoundingBox(m_pointFirst, m_pointLast);
map1.Update();
}
// Reset the points
m_pointLast = null;
m_pointFirst = null;
}
private void map1_OnMouseDown(MouseButtons Button, short Shift, GpsToolsNET.Position objPosition, GpsViewNET.Point objPoint)
{
/* // Shift == 1 is when the shift button is pressed.
if (Shift == 1)
{
// This is the first point the user clicked.
m_pointFirst = objPoint;
}
else
{
// Get a copy of the used ShapeFile.
GpsShapeNET.ShapeFile shapeFile = mapShapeFile.ShapeFile.Copy();
// Select a positon where we want search for a shape.
shapeFile.SelectByIsInside(objPosition);
// Read the shape if there is any at the given position.
GpsShapeNET.Shape shape = shapeFile.Read();
if (shape != null)
{
// Get the bounding box from the shapefile.
double dMinX, dMaxX, dMinY, dMaxY, dMinM, dMaxM, dMinZ, dMaxZ;
shape.GetBoundingBox(out dMinX, out dMaxX, out dMinY, out dMaxY, out dMinZ, out dMaxZ, out dMinM, out dMaxM);
// Get the DatumGrridTemplate form the shapefile
GpsToolsNET.Position template = shapeFile.DatumGridTemplate;
// Zoom using the bounding box coodrinates.
map1.ZoomByBoundingBox(dMinX, dMaxX, dMinY, dMaxY, template);
map1.Update();
}
}*/
//map1.OffsetX
/*this.statusBar.Text = "No data loaded."; = (map1.OffsetX - intarse((((map1.Width / 2)
- Control.MousePosition.X)
/ 2)));*/
//map1.OffsetY
int ox = (int) map1.OffsetX - ((( map1.Width / 2) - Control.MousePosition.X) / 2);
int oy = (int) map1.OffsetY - (((map1.Height / 2) - Control.MousePosition.Y) / 2);
this.statusBar.Text = string.Concat( ox.ToString() , ", " , oy.ToString() );
//map1.OffsetX = map1.OffsetX + ox;
//map1.OffsetY = map1.OffsetY + oy;
//map1.Update();
}
private void map1_OnMapPaint(GpsViewNET.Map sender, Graphics e)
{
System.Drawing.Pen pen = new System.Drawing.Pen(Color.BlueViolet);
if (m_pointFirst != null && m_pointLast != null)
{
// Get Maps position (which is centered)
GpsToolsNET.Position mapPos = map1.Position;
// Maps center in pixels seen from the origin of the bitmap
// (not from the Control)
// This value changes when Map.Zoom or Map.Rotation changes
GpsViewNET.Point mapPoint = map1.Position2Point(mapPos);
// This is the offset that differs the Control's orgio
// and the raster maps (bitmaps) origin
int offset_x = mapPoint.X - map1.Width / 2;
int offset_y = mapPoint.Y - map1.Height / 2;
// Draw a rectangle
e.FillRectangle(new System.Drawing.SolidBrush(Color.FromArgb(0, 0, 255)), m_pointFirst.X - offset_x, m_pointFirst.Y - offset_y, m_pointLast.X - m_pointFirst.X, m_pointLast.Y - m_pointFirst.Y);
}
}
private void menuItem_loadDataSet_Click(object sender, EventArgs e)
{
// Open a dialog to pick a file
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
// Create a ShapeFile
shapeFile = new GpsShapeNET.ShapeFile();
// Open the ShapeFile
shapeFile.Open(openFileDialog.FileName, GpsShapeNET.FileMode.FILE_READ);
// if the DatumGridTemplate wasn't set automatically it wasn't a complete prj-file available
if (shapeFile.DatumGridTemplate == null)
{
// Since we need a projection we have to guess what it is...
// get the bounding box
double Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, Mmin, Mmax;
shapeFile.GetBoundingBox(out Xmin, out Xmax, out Ymin, out Ymax, out Zmin, out Zmax, out Mmin, out Mmax);
string guessStr = "";
GpsToolsNET.Position nodePosition = new GpsToolsNET.Position();
// Take a guess if we should use a datum or grid.
// A datum shapefile will have its bounds in degrees...
if (Ymax <= 90 && Ymin >= -90 && Xmax <= 180 && Xmin >= -180)
{
nodePosition.Datum = GpsToolsNET.Datum.WGS_84;
guessStr = nodePosition.Datum.ToString();
}
else
{
// ...whereas a grid shapefile will have its bounds in meters..
nodePosition.Grid = GpsToolsNET.Grid.UTM_NORTH;
nodePosition.Zone = "15";
guessStr = nodePosition.Grid.ToString();
}
// set the guessed DatumGridTemplate..
shapeFile.DatumGridTemplate = nodePosition;
// display to user that we guessed!
MessageBox.Show("No projection data was found. Guessing the projection of this file as a " + guessStr);
}
// Create a MapShapeFile to draw the contents
mapShapeFile = map1.NewMapShapeFile(shapeFile);
// Set a resolution of 2 pixels - all shapes smaller than this will not be drawn.
// Nodes that are closer together than this will also not be drawn.
mapShapeFile.Resolution = 2.0;
// Create a brush with green color and transparent
GpsViewNET.Brush brush = new GpsViewNET.Brush();
brush.Blue = 255;
brush.Red = 128;
brush.Green = 128;
brush.Transparent = false;
// Set the brush to the background property of the mapshapefile
mapShapeFile.Background = brush;
// set statusbar text
this.statusBar.Text = "Data added.";
// call an update of the Map to draw it
map1.Update();
}
}
private void menuItem_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == System.Windows.Forms.Keys.Up))
{
map1.OffsetY -= 2;
map1.Update();
this.statusBar.Text = string.Concat(map1.OffsetY.ToString(), ", ", map1.OffsetX.ToString());
}
if ((e.KeyCode == System.Windows.Forms.Keys.Down))
{
map1.OffsetY += 2;
map1.Update();
this.statusBar.Text = string.Concat(map1.OffsetY.ToString(), ", ", map1.OffsetX.ToString());
}
if ((e.KeyCode == System.Windows.Forms.Keys.Left))
{
map1.OffsetX -= 2;
map1.Update();
this.statusBar.Text = string.Concat(map1.OffsetY.ToString(), ", ", map1.OffsetX.ToString());
}
if ((e.KeyCode == System.Windows.Forms.Keys.Right))
{
map1.OffsetX += 2;
map1.Update();
this.statusBar.Text = string.Concat(map1.OffsetY.ToString(), ", ", map1.OffsetX.ToString());
}
if ((e.KeyCode == System.Windows.Forms.Keys.Enter))
{
// Enter
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -