Skip to content

Commit 1caa3e9

Browse files
committed
Ok, so here is the little sample that I created the placeholder folder for previously. Again, there is nothing too interesting functionally about this sample . It just illustrates how to use SharpMap in a desktop environment, in a platform independent way, with a visual GUI designer...without the need for any proprietary software like Windows or Visual Studio.
1 parent 3e2c7ab commit 1caa3e9

25 files changed

Lines changed: 488 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:mime-type</Name><Value>application/octet-stream</Value></Property></Properties></ItemProperties>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
// Information about this assembly is defined by the following attributes.
5+
// Change them to the values specific to your project.
6+
7+
[assembly: AssemblyTitle("TestGtk")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("")]
12+
[assembly: AssemblyCopyright("")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
18+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
19+
20+
[assembly: AssemblyVersion("1.0.*")]
21+
22+
// The following attributes are used to specify the signing key for the assembly,
23+
// if desired. See the Mono documentation for more information about signing.
24+
25+
//[assembly: AssemblyDelaySign(false)]
26+
//[assembly: AssemblyKeyFile("")]
27+

Trunk/GtkFormSamples/Main.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using Gtk;
3+
4+
namespace TestGtk
5+
{
6+
class MainClass
7+
{
8+
public static void Main (string[] args)
9+
{
10+
Application.Init ();
11+
MainWindow win = new MainWindow ();
12+
win.Show ();
13+
Application.Run ();
14+
}
15+
}
16+
}
17+

Trunk/GtkFormSamples/MainWindow.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.IO;
3+
using System.Drawing;
4+
using System.Drawing.Imaging;
5+
using Gtk;
6+
7+
public partial class MainWindow : Gtk.Window
8+
{
9+
SharpMap.Map myMap = null;
10+
11+
public MainWindow () : base(Gtk.WindowType.Toplevel)
12+
{
13+
try
14+
{
15+
Build ();
16+
17+
Size mapSize = new Size(800, 500);
18+
myMap = new SharpMap.Map(mapSize);
19+
20+
SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
21+
style.Outline = new Pen(Color.Green,1);
22+
style.EnableOutline = true;
23+
SharpMap.Layers.VectorLayer layWorld = new SharpMap.Layers.VectorLayer("States");
24+
layWorld.DataSource = new SharpMap.Data.Providers.ShapeFile(@"states.shp", true);
25+
layWorld.Style = style;
26+
27+
myMap.Layers.Add(layWorld);
28+
myMap.MaximumZoom = 360;
29+
myMap.BackColor = Color.LightBlue;
30+
myMap.Center = new SharpMap.Geometries.Point(0, 0);
31+
myMap.Zoom = 360;
32+
33+
Bitmap img = (Bitmap)myMap.GetMap();
34+
image3.Pixbuf = ImageToPixbuf(img);
35+
}
36+
catch(Exception ex)
37+
{
38+
label1.Text = ex.Message.ToString();
39+
}
40+
}
41+
42+
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
43+
{
44+
Application.Quit ();
45+
a.RetVal = true;
46+
}
47+
48+
49+
private static Gdk.Pixbuf ImageToPixbuf(System.Drawing.Image image)
50+
{
51+
using (MemoryStream stream = new MemoryStream()) {
52+
image.Save("test.png", ImageFormat.Png);
53+
image.Save(stream, ImageFormat.Png);
54+
stream.Position = 0;
55+
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(stream);
56+
return pixbuf;
57+
}
58+
}
59+
60+
protected virtual void EventBoxButtonPress (object o, Gtk.ButtonPressEventArgs args)
61+
{
62+
double dX = args.Event.X;
63+
double dY = args.Event.Y;
64+
System.Drawing.PointF oPointF = new System.Drawing.PointF((float)dX,(float)dY);
65+
66+
label1.Text = dX.ToString() + " , " + dY.ToString();
67+
68+
myMap.Center = myMap.ImageToWorld(oPointF);
69+
70+
if (radPan.Active)
71+
{
72+
73+
myMap.Zoom *= 1;
74+
}
75+
else if (radZoomIn.Active)
76+
{
77+
myMap.Zoom *= 0.5;
78+
}
79+
else
80+
{
81+
myMap.Zoom *= 1.5;
82+
}
83+
84+
Bitmap img = (Bitmap)myMap.GetMap();
85+
image3.Pixbuf = ImageToPixbuf(img);
86+
87+
}
88+
}

Trunk/GtkFormSamples/Readme.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This is just a bit of sample code that runs a simple SharpMap application in a GTKSharp and mono environement. It should be plateform independent as long as the OS has both GTK# 2.0 and Mono installed. This little sample was build on Ubuntu 11.04 with MonoDevelop 2.4. The nice thing is you can use the Static Visual GUI designer using GTK# in MonoDeveop.
2+
3+
Place the states.shp file in the Bin/Debug folder once you have build the application and it should just run.
4+
5+
Atv
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProductVersion>9.0.21022</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{D8C31343-91DA-463B-95E0-47C60B1D0FBF}</ProjectGuid>
9+
<OutputType>WinExe</OutputType>
10+
<RootNamespace>TestGtk</RootNamespace>
11+
<AssemblyName>TestGtk</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
</PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
15+
<DebugSymbols>true</DebugSymbols>
16+
<DebugType>full</DebugType>
17+
<Optimize>false</Optimize>
18+
<OutputPath>bin\Debug</OutputPath>
19+
<DefineConstants>DEBUG</DefineConstants>
20+
<ErrorReport>prompt</ErrorReport>
21+
<WarningLevel>4</WarningLevel>
22+
<PlatformTarget>x86</PlatformTarget>
23+
<ConsolePause>false</ConsolePause>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
26+
<DebugType>none</DebugType>
27+
<Optimize>false</Optimize>
28+
<OutputPath>bin\Release</OutputPath>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
<PlatformTarget>x86</PlatformTarget>
32+
<ConsolePause>false</ConsolePause>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
37+
<SpecificVersion>False</SpecificVersion>
38+
<Package>gtk-sharp-2.0</Package>
39+
</Reference>
40+
<Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
41+
<SpecificVersion>False</SpecificVersion>
42+
<Package>gtk-sharp-2.0</Package>
43+
</Reference>
44+
<Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
45+
<SpecificVersion>False</SpecificVersion>
46+
<Package>glib-sharp-2.0</Package>
47+
</Reference>
48+
<Reference Include="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
49+
<SpecificVersion>False</SpecificVersion>
50+
<Package>glade-sharp-2.0</Package>
51+
</Reference>
52+
<Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
53+
<SpecificVersion>False</SpecificVersion>
54+
<Package>gtk-sharp-2.0</Package>
55+
</Reference>
56+
<Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
57+
<SpecificVersion>False</SpecificVersion>
58+
<Package>gtk-sharp-2.0</Package>
59+
</Reference>
60+
<Reference Include="Mono.Posix" />
61+
<Reference Include="SharpMap, Version=0.9.4135.33490, Culture=neutral, PublicKeyToken=null">
62+
<SpecificVersion>False</SpecificVersion>
63+
<HintPath>..\..\SearchOGC\SharpMap\SharpMap\bin\Release\SharpMap.dll</HintPath>
64+
</Reference>
65+
<Reference Include="System.Drawing" />
66+
<Reference Include="System.Drawing.Design" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<EmbeddedResource Include="gtk-gui\gui.stetic">
70+
<LogicalName>gui.stetic</LogicalName>
71+
</EmbeddedResource>
72+
</ItemGroup>
73+
<ItemGroup>
74+
<Compile Include="gtk-gui\generated.cs" />
75+
<Compile Include="MainWindow.cs" />
76+
<Compile Include="gtk-gui\MainWindow.cs" />
77+
<Compile Include="Main.cs" />
78+
<Compile Include="AssemblyInfo.cs" />
79+
</ItemGroup>
80+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
81+
</Project>

Trunk/GtkFormSamples/TestGtk.pidb

6.77 KB
Binary file not shown.

Trunk/GtkFormSamples/TestGtk.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 10.00
3+
# Visual Studio 2008
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestGtk", "TestGtk.csproj", "{D8C31343-91DA-463B-95E0-47C60B1D0FBF}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|x86 = Debug|x86
9+
Release|x86 = Release|x86
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{D8C31343-91DA-463B-95E0-47C60B1D0FBF}.Debug|x86.ActiveCfg = Debug|x86
13+
{D8C31343-91DA-463B-95E0-47C60B1D0FBF}.Debug|x86.Build.0 = Debug|x86
14+
{D8C31343-91DA-463B-95E0-47C60B1D0FBF}.Release|x86.ActiveCfg = Release|x86
15+
{D8C31343-91DA-463B-95E0-47C60B1D0FBF}.Release|x86.Build.0 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(MonoDevelopProperties) = preSolution
18+
StartupItem = TestGtk.csproj
19+
EndGlobalSection
20+
EndGlobal
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Properties>
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" ctype="Workspace" />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="MainWindow.cs" ctype="Workbench">
4+
<Files>
5+
<File FileName="MainWindow.cs" Line="88" Column="2" />
6+
<File FileName="Main.cs" Line="1" Column="1" />
7+
<File FileName="AssemblyInfo.cs" Line="1" Column="1" />
8+
</Files>
9+
</MonoDevelop.Ide.Workbench>
10+
<MonoDevelop.Ide.DebuggingService.Breakpoints>
11+
<BreakpointStore />
12+
</MonoDevelop.Ide.DebuggingService.Breakpoints>
13+
<MonoDevelop.Ide.DebuggingService.PinnedWatches ctype="PinnedWatchStore" />
14+
</Properties>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:mime-type</Name><Value>application/octet-stream</Value></Property></Properties></ItemProperties>

0 commit comments

Comments
 (0)