-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathMainWindow.cs
More file actions
96 lines (81 loc) · 2.95 KB
/
MainWindow.cs
File metadata and controls
96 lines (81 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using NetTopologySuite;
//using Gtk;
namespace TestGtk
{
public partial class MainWindow : Gtk.Window
{
private SharpMap.Map myMap;
public MainWindow()
: base(Gtk.WindowType.Toplevel)
{
try
{
GeoAPI.GeometryServiceProvider.Instance = new NtsGeometryServices();
Build();
Size mapSize = new Size(800, 500);
myMap = new SharpMap.Map(mapSize);
SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
style.Outline = new Pen(Color.Green, 1);
style.EnableOutline = true;
SharpMap.Layers.VectorLayer layWorld = new SharpMap.Layers.VectorLayer("States");
layWorld.DataSource =
new SharpMap.Data.Providers.ShapeFile(
@"data" + System.IO.Path.DirectorySeparatorChar + @"states.shp", true);
layWorld.Style = style;
myMap.Layers.Add(layWorld);
myMap.MaximumZoom = 360;
myMap.BackColor = Color.LightBlue;
myMap.Center = new GeoAPI.Geometries.Coordinate(0, 0);
myMap.Zoom = 360;
Bitmap img = (Bitmap)myMap.GetMap();
image3.Pixbuf = ImageToPixbuf(img);
}
catch (Exception ex)
{
label1.Text = ex.Message;
}
}
protected void OnDeleteEvent(object sender, Gtk.DeleteEventArgs a)
{
Gtk.Application.Quit();
a.RetVal = true;
}
private static Gdk.Pixbuf ImageToPixbuf(System.Drawing.Image image)
{
using (MemoryStream stream = new MemoryStream())
{
image.Save("test.png", ImageFormat.Png);
image.Save(stream, ImageFormat.Png);
stream.Position = 0;
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(stream);
return pixbuf;
}
}
protected virtual void EventBoxButtonPress(object o, Gtk.ButtonPressEventArgs args)
{
double dX = args.Event.X;
double dY = args.Event.Y;
System.Drawing.PointF oPointF = new System.Drawing.PointF((float)dX, (float)dY);
label1.Text = dX.ToString() + " , " + dY.ToString();
myMap.Center = myMap.ImageToWorld(oPointF);
if (radPan.Active)
{
myMap.Zoom *= 1;
}
else if (radZoomIn.Active)
{
myMap.Zoom *= 0.5;
}
else
{
myMap.Zoom *= 1.5;
}
Bitmap img = (Bitmap)myMap.GetMap();
image3.Pixbuf = ImageToPixbuf(img);
}
}
}