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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using GMap.NET;
using GMap.NET.MapProviders;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using System.Windows.Media;
namespace Région_Kenitra_Services
{
public partial class FMainStations : Form
{
GMapOverlay overlayOne;
public FMainStations()
{
InitializeComponent();
cmbStation.SelectedIndex = 4;
}
private void FMainStations_Load(object sender, EventArgs e)
{
gMap.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
gMap.SetCurrentPositionByKeywords("K, M");
gMap.CanDragMap = true;
gMap.DragButton = MouseButtons.Left;
//gMap.Zoom = gMap.MinZoom + 1;
gMap.Dock = System.Windows.Forms.DockStyle.Fill;
gMap.MouseWheelZoomType = MouseWheelZoomType.MousePositionAndCenter;
//ajout des overlay
overlayOne = new GMapOverlay(gMap, "OverlayOne");
//ajout de Markers
overlayOne.Markers.Add(new GMap.NET.WindowsForms.Markers.GMapMarkerCross
(new PointLatLng(34.3252919244273, -6.5533447265635)));
//ajout de overlay à la map
gMap.Overlays.Add(overlayOne);
gMap.ZoomAndCenterMarkers(overlayOne.Id);
}
private void gMap_MouseDoubleClick(object sender, MouseEventArgs e)
{
double lat = 0,lng = 0 ;
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
lat = gMap.FromLocalToLatLng(e.X, e.Y).Lat;
lng = gMap.FromLocalToLatLng(e.X, e.Y).Lng;
}
MessageBox.Show(("Point : "+lat+"/"+lng));
}
private void btnImg_Click(object sender, EventArgs e)
{/*
try
{
ImageSource img = gMap.ToImageSource();
PngBitmapEncoder en = new PngBitmapEncoder();
en.Frames.Add(BitmapFrame.Create(img as BitmapSource));
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "GMap.NET Image"; // Default file name
dlg.DefaultExt = ".png"; // Default file extension
dlg.Filter = "Image (.png)|*.png"; // Filter files by extension
dlg.AddExtension = true;
dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
// Show save file dialog box
bool? result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Save document
string filename = dlg.FileName;
using (System.IO.Stream st = System.IO.File.OpenWrite(filename))
{
en.Save(st);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}*/
}
private void btnOK_Click(object sender, EventArgs e)
{
gMap.MaxZoom = 30;
string adresse1, adresse2, adresse3, adresse4 = "";
double lat1, lat2, lat3, lat4 = 0;
double lng1, lng2, lng3, lng4 = 0;
adresse1 = "Station 1 \n Hôtel La Rotonde, \n Rue Mohamed Diouri,\n Kénitra, Maroc";
lat1 = 34.2563970;
lng1 = -6.5827260;
adresse2 = "Station 2 \n Hotel Maamora \n,avenue Hassan II,\n place administrative, \n Kénitra, Maroc";
lat2 = 34.275658998631;
lng2 = -6.50802612304688;
adresse3 = "Station 3 \n Hôtel de ville de kenitra,\n Kénitra,\n Maroc";
lat3 = 34.3539238613087;
lng3 = -6.4654541015625;
adresse4 = "Station 4 \n Hotel Assam,N1, \n Kenitra, \n Maroc";
lat4 = 34.1811336709623;
lng4 = -6.50527954101563;
overlayOne.Markers.Clear();
MarkerTooltipMode mode = MarkerTooltipMode.Always;
System.Drawing.Brush ToolTipBackColor = new SolidBrush(System.Drawing.Color.Coral);
if (cmbStation.SelectedIndex.ToString() == "0")
{
gMap.Position = new PointLatLng(lat1, lng1);
GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(gMap.Position);
marker.ToolTip = new GMap.NET.WindowsForms.ToolTips.GMapBaloonToolTip(marker);
marker.ToolTip.Format.Alignment = StringAlignment.Center;
marker.ToolTipMode = mode;
marker.ToolTip.Fill = ToolTipBackColor;
marker.ToolTipText = adresse1.ToString();
overlayOne.Markers.Add(marker);
gMap.Overlays.Add(overlayOne);
}
else if (cmbStation.SelectedIndex.ToString() == "1")
{
gMap.Position = new PointLatLng(lat2, lng2);
//GMarkerGoogle marker = new GMarkerGoogle(gMap.Position, GMarkerGoogleType.blue);
GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(gMap.Position);
marker.ToolTip = new GMap.NET.WindowsForms.ToolTips.GMapBaloonToolTip(marker);
marker.ToolTip.Format.Alignment = StringAlignment.Center;
marker.ToolTipText = adresse2.ToString();
marker.ToolTipMode = mode;
marker.ToolTip.Fill = ToolTipBackColor;
overlayOne.Markers.Add(marker);
gMap.Overlays.Add(overlayOne);
}
else if (cmbStation.SelectedIndex.ToString() == "2")
{
gMap.Position = new PointLatLng(lat3, lng3);
GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(gMap.Position);
marker.ToolTip = new GMap.NET.WindowsForms.ToolTips.GMapBaloonToolTip(marker);
marker.ToolTip.Format.Alignment = StringAlignment.Center;
marker.ToolTipMode = mode;
marker.ToolTip.Fill = ToolTipBackColor;
marker.ToolTipText = adresse3.ToString();
overlayOne.Markers.Add(marker);
gMap.Overlays.Add(overlayOne);
}
else if (cmbStation.SelectedIndex.ToString() == "3")
{
gMap.Position = new PointLatLng(lat4, lng4);
GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(gMap.Position);
marker.ToolTip = new GMap.NET.WindowsForms.ToolTips.GMapBaloonToolTip(marker);
marker.ToolTip.Format.Alignment = StringAlignment.Center;
marker.ToolTipMode = mode;
marker.ToolTip.Fill = ToolTipBackColor;
marker.ToolTipText = adresse4.ToString();
overlayOne.Markers.Add(marker);
gMap.Overlays.Add(overlayOne);
}
else
{
for (int i = 0; i < cmbStation.Items.Count; i++)
{
gMap.Position = new PointLatLng(lat1, lng1);
GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(gMap.Position);
marker.ToolTip = new GMap.NET.WindowsForms.ToolTips.GMapBaloonToolTip(marker);
marker.ToolTip.Format.Alignment = StringAlignment.Center;
marker.ToolTipMode = mode;
marker.ToolTipText = "Station 1";
overlayOne.Markers.Add(marker);
gMap.Overlays.Add(overlayOne);
gMap.Position = new PointLatLng(lat2, lng2);
GMapMarkerGoogleRed marker2 = new GMapMarkerGoogleRed(gMap.Position);
marker2.ToolTip = new GMap.NET.WindowsForms.ToolTips.GMapBaloonToolTip(marker2);
marker2.ToolTip.Format.Alignment = StringAlignment.Center;
marker2.ToolTipMode = mode;
marker2.ToolTipText = "Station 2";
overlayOne.Markers.Add(marker2);
gMap.Overlays.Add(overlayOne);
gMap.Position = new PointLatLng(lat3, lng3);
GMapMarkerGoogleRed marker3 = new GMapMarkerGoogleRed(gMap.Position);
marker3.ToolTip = new GMap.NET.WindowsForms.ToolTips.GMapBaloonToolTip(marker3);
marker3.ToolTip.Format.Alignment = StringAlignment.Center;
marker3.ToolTipText = "Station 3";
marker3.ToolTipMode = mode;
overlayOne.Markers.Add(marker3);
gMap.Overlays.Add(overlayOne);
gMap.Position = new PointLatLng(lat4, lng4);
GMapMarkerGoogleRed marker4 = new GMapMarkerGoogleRed(gMap.Position);
marker4.ToolTip = new GMap.NET.WindowsForms.ToolTips.GMapBaloonToolTip(marker4);
marker4.ToolTip.Format.Alignment = StringAlignment.Near;
marker4.ToolTipText = "Station 4";
marker4.ToolTipMode = mode;
overlayOne.Markers.Add(marker4);
gMap.Overlays.Add(overlayOne);
gMap.ZoomAndCenterMarkers("OverlayOne");
}
}
}
}
} |
Partager