GMap.Net zooming issue mouseovering / hovering a marker - c#

When my cursor is over a marker, it doesn't zoom. Is there any way around this?
Cheers
public MainForm(Dictionary<string, string> startupParams)
{
InitializeComponent();
gMapControl.MapProvider = GMapProviders.GoogleMap;
gMapControl.Position = new PointLatLng(-33.861468, 151.209179);
gMapControl.MinZoom = 0;
gMapControl.MaxZoom = 24;
gMapControl.Zoom = 9;
gMapControl.MarkersEnabled = true;
gMapControl.DragButton = MouseButtons.Left;
gMapControl.ShowCenter = false;
}
private void UpdateMap()
{
gMapControl.Position = new PointLatLng(Convert.ToDouble(LatLng.Split(',')[0]), Convert.ToDouble(LatLng.Split(',')[1]));
GMapOverlay markersOverlay = new GMapOverlay("markers");
GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(Convert.ToDouble(LatLng.Split(',')[0]), Convert.ToDouble(LatLng.Split(',')[1])), GMarkerGoogleType.green);
markersOverlay.Markers.Add(marker);
gMapControl.Overlays.Clear();
gMapControl.Overlays.Add(markersOverlay);
}

Yes, there's a simple way around this:
gMapControl.IgnoreMarkerOnMouseWheel = true;

Related

Gmap.net can't show multi markers use C# winform

I want show multi marker on Map , but seem can't , code follow :
button1_Click show Position ,button2_Click show markers !
anyone give me any instructions? thanks.
private void button1_Click(object sender, EventArgs e)
{
gmap.DragButton = MouseButtons.Left;
gmap.MapProvider = GMapProviders.GoogleMap;
gmap.Position = new PointLatLng(25.037531, 121.5639969);
gmap.MinZoom = 5;
gmap.MaxZoom = 100;
gmap.ShowCenter = false;
gmap.Zoom = 15;
}
private void button2_Click(object sender, EventArgs e)
{
Random r = new Random();
var marker = new GMarkerGoogle(new PointLatLng(r.Next(25, 500), 121), GMarkerGoogleType.green);
var marker1 = new GMarkerGoogle(new PointLatLng(r.Next(25, 500), 121), GMarkerGoogleType.pink);
var marker2 = new GMarkerGoogle(new PointLatLng(r.Next(25, 500), 121), GMarkerGoogleType.blue);
var marker3 = new GMarkerGoogle(new PointLatLng(r.Next(25, 500), 121), GMarkerGoogleType.yellow);
marker.IsVisible = true; marker1.IsVisible = true; marker2.IsVisible = true; marker3.IsVisible = true;
gMapOverlay.Markers.Add(marker);
gMapOverlay.Markers.Add(marker1);
gMapOverlay.Markers.Add(marker2);
gMapOverlay.Markers.Add(marker3);
gmap.Overlays.Add(gMapOverlay);
}
Your code is ok, but the problem with the random function that you use only generates integers, and a small change as 1 integer means changing a complete degree in either latitude or longitude and this is a hudge displacement.
So you have to generate a random Doubles number instead of Integers.
I edit the code to work correctly.
using GMap.NET;
using GMap.NET.WindowsForms.Markers;
public class Form1
{
private GMap.NET.WindowsForms.GMapOverlay gMapOverlay;
private Random rand = new Random();
private void Form1_Load(object sender, EventArgs e)
{
GMapControl1.DragButton = MouseButtons.Left;
GMapControl1.MapProvider = GMap.NET.MapProviders.GMapProviders.GoogleMap;
GMapControl1.Position = new PointLatLng(25.037531, 121.5639969);
GMapControl1.MinZoom = 5;
GMapControl1.MaxZoom = 20;
GMapControl1.ShowCenter = false;
GMapControl1.Zoom = 11;
gMapOverlay = new WindowsForms.GMapOverlay("markers");
gMapOverlay.IsVisibile = true;
}
private void button2_Click(object sender, EventArgs e)
{
var marker = new GMarkerGoogle(new PointLatLng(GetRandomDouble(24.8, 25.1), GetRandomDouble(121.3, 121.6)), GMarkerGoogleType.green);
var marker1 = new GMarkerGoogle(new PointLatLng(GetRandomDouble(24.8, 25.1), GetRandomDouble(121.3, 121.6)), GMarkerGoogleType.pink);
var marker2 = new GMarkerGoogle(new PointLatLng(GetRandomDouble(24.8, 25.1), GetRandomDouble(121.3, 121.6)), GMarkerGoogleType.blue);
var marker3 = new GMarkerGoogle(new PointLatLng(GetRandomDouble(24.8, 25.1), GetRandomDouble(121.3, 121.6)), GMarkerGoogleType.yellow);
marker.IsVisible = true;
marker1.IsVisible = true;
marker2.IsVisible = true;
marker3.IsVisible = true;
// Clear old markers
gMapOverlay.Markers.Clear();
gMapOverlay.Markers.Add(marker);
gMapOverlay.Markers.Add(marker1);
gMapOverlay.Markers.Add(marker2);
gMapOverlay.Markers.Add(marker3);
// Clear old overlay
GMapControl1.Overlays.Clear();
GMapControl1.Overlays.Add(gMapOverlay);
// Zoom the map to show all drawn markers
GMapControl1.ZoomAndCenterMarkers(gMapOverlay.Id);
}
public double GetRandomDouble(double min, double max)
{
return rand.NextDouble() * (max - min) + min;
}

How to add multiple makers on Gmap in c#

I have a text file with a list of GPS coordinates. I am trying to place a marker on each of the coordinates from the document. The problem is that the lengths of the documents change and the way I have it, the marker gets replaced with every iteration. How do I add a marker for each lat/lon point?
Here's the relevant code:
private GMapOverlay gMapOverlay;
private GMapMarker marker;
gmap.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;
gmap.MinZoom = 2;
gmap.MaxZoom = 25;
gmap.Zoom = 5;
gmap.ShowCenter = false;
gmap.DragButton = MouseButtons.Left;
//setup the map overlay for displaying routes/points
gMapOverlay = new GMapOverlay("Path");
gmap.Overlays.Add(gMapOverlay);
gMapOverlay.Markers.Clear();
gMapOverlay.Routes.Clear();
//GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(0, 0), GMarkerGoogleType.green);
marker = new GMarkerGoogle(new PointLatLng(0, 0), GMarkerGoogleType.green);
marker.IsVisible = false;
marker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
marker.ToolTipText = "Starting Point";
gMapOverlay.Markers.Add(marker);
private void btn_KMLFile_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog4.ShowDialog();
if (result == DialogResult.OK)
{
string filename = openFileDialog4.FileName;
string[] lines = System.IO.File.ReadAllLines(filename);
foreach (string line in lines)
{
string[] Data_Array = line.Split(',');
Double londecimal = Convert.ToDouble(Data_Array[0]);
Double latdecimal = Convert.ToDouble(Data_Array[1]);
marker.Position = new PointLatLng(latdecimal, londecimal);
marker.IsVisible = true;
gmap.Update();
}
}
}
private void openFileDialog4_FileOk(object sender, CancelEventArgs e)
{
OpenFileDialog openFileDialog4 = new OpenFileDialog();
}
The markers can go into the Markers collection:
public readonly ObservableCollection<GMapMarker> Markers;
Just add the markers to the collection as you do with your single marker.
EDIT
I was assuming a WPF client, so there's no Observable Collection if you are using WinForms. Have you tried to add a new marker to the collection as you do with your original marker? So in your loop:
string[] Data_Array = line.Split(',');
Double londecimal = Convert.ToDouble(Data_Array[0]);
Double latdecimal = Convert.ToDouble(Data_Array[1]);
// add a new one here
var marker = new GMarkerGoogle(new PointLatLng(latdecimal, londecimal), GMarkerGoogleType.green);
marker.IsVisible = true;
gMapOverlay.Markers.Add(marker);
I can fix with using list
List<GMapMarker> lMarks = new List<GMapMarker>();
int[] SelectedRows = gvProjects.GetSelectedRows();
map.Overlays.Clear();
GMapOverlay markers = new GMapOverlay("markers");
for (int i = 0; i < SelectedRows.Length; i++)
{
if (SelectedRows[i] >= 0)
{
double lat = Convert.ToDouble(gvProjects.GetRowCellValue(i-2,"Altitude"));
double lng = Convert.ToDouble(gvProjects.GetRowCellValue(i-2, "Longitude"));
PointLatLng point = new PointLatLng(lat, lng);
GMapMarker marker = new GMarkerGoogle(new PointLatLng(lat,lng),GMarkerGoogleType.yellow_pushpin);
marker.ToolTipMode = MarkerTooltipMode.Always;
marker.Tag = gvProjects.GetRowCellValue(i-2, "ID").ToString();
marker.ToolTipText = gvProjects.GetRowCellValue(i-2, "ProjectName").ToString();
lMarks.Add(marker);
}
}
markers.Markers.AddRange(lMarks);
map.Overlays.Add(markers);

GMap.Net marker initially in incorrect position

I have added a marker using GMap with the lat/long specified. When the application starts, the marker is placed in the incorrect position(at the center of the GMap control) and then when I zoom, it then goes to the specified coordinates. Is this a bug in GMap or am I doing something wrong? Here is the code.
GMapOverlay markersOverlay, mo2;
GMarkerGoogle marker, marker5;
GMapOverlay polyOverlay;
List<PointLatLng> points;
GMapRoute gr;
Graphics g;
bool start = true;
double move = .0001;
double lt = 73, lg = -180;
public Form1()
{
AllocConsole();
InitializeComponent();
try
{
System.Net.IPHostEntry e = System.Net.Dns.GetHostEntry("www.google.com");
}
catch
{
gmap.Manager.Mode = AccessMode.CacheOnly;
MessageBox.Show("No internet connection avaible, going to CacheOnly mode.", "GMap.NET - Demo.WindowsForms", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
gmap.MapProvider = GMapProviders.BingHybridMap;
gmap.Position = new PointLatLng(32, -100);
gmap.MinZoom = 3;
gmap.MaxZoom = 15;
gmap.Zoom = 9;
markersOverlay = new GMapOverlay("markers");
mo2 = new GMapOverlay("markers5");
marker5 = new GMarkerGoogle(new PointLatLng(lt, lg), GMarkerGoogleType.orange_small);
g = this.CreateGraphics();
}
private void Form1_Load(object sender, EventArgs e)
{
gmap.DragButton = MouseButtons.Left;
gmap.ShowCenter = false;
points = new List<PointLatLng>();
polyOverlay = new GMapOverlay("polygons");
GMapPolygon polygon = new GMapPolygon(points, "mypolygon");
polygon.Fill = new SolidBrush(Color.FromArgb(50, Color.Magenta));
polygon.Stroke = new Pen(Color.Magenta, 2);
}
protected void OnMouseMove(object sender, MouseEventArgs e)
{
PointLatLng p = gmap.FromLocalToLatLng(e.X, e.Y);
MouseLatLong.Text = Convert.ToString(p);
}
private void SubmitButton_Click(object sender, EventArgs e)
{
marker = new GMarkerGoogle(new PointLatLng(double.Parse(LattextBox.Text), double.Parse(LongtextBox.Text)), new Bitmap(#"C:\Users\Vaib\Documents\Visual Studio 2013\Projects\testGmap\testGmap\Resources\wpt.png"));
mo2.Markers.Add(marker);
gmap.Overlays.Add(mo2);
marker.ToolTip = new GMapToolTip(marker);
marker.ToolTipText = NametextBox.Text;
marker.ToolTipMode = MarkerTooltipMode.Always;
if (start)
{
gmap.Position = new PointLatLng(marker.Position.Lat, marker.Position.Lng);
start = false;
}
points.Add(new PointLatLng(marker.Position.Lat, marker.Position.Lng));
gr = new GMapRoute(points, "route");
gr.Stroke = new Pen(Color.Magenta, 2);
polyOverlay.Routes.Add(gr);
gmap.Overlays.Add(polyOverlay);
ga = new GMarkerArrow(new PointLatLng(gr.From.Value.Lat, gr.From.Value.Lng));
if (points.Count >= 2)
{
ga.Bearing = (float)final(gr.From.Value.Lat, gr.From.Value.Lng, points[1].Lat, points[1].Lng);
}
markersOverlay.Clear();
markersOverlay.Markers.Add(ga);
gmap.Overlays.Add(markersOverlay);
}
The trick is to first add overlay and then the marker:
gMapControl.Overlays.Add(markersOverlay);
markersOverlay.Markers.Add(marker);
Solution
Like you can read in the comments: Adding
gmap.Overlays.Clear()
at the very beginning of the method
private void SubmitButton_Click(object sender, EventArgs e)
was the answer to his problem.
I'm working in MSVC2010 (C++) on a WinForms app and had the same problem - took most of the afternoon to resolve.
This thread was useful, but I find all you need to do is (sorry it's not C#) is comment out the first time you add the marker - see
// DO NOT ADD... line
// Make marker
WindowsForms::Markers::GMarkerGoogle ^MyMarker;
WindowsForms::Markers::GMarkerGoogleType MyType = safe_cast<WindowsForms::Markers::GMarkerGoogleType>(3); // Blue marker 3
MyMarker = gcnew WindowsForms::Markers::GMarkerGoogle( PointLatLng(40.7, -74.0), MyType);
// MyOverlay->Markers->Add(MyMarker); // DO NOT ADD THE MARKER!!!
gMapControl1->Overlays->Add(MyOverlay);
MyMarker = gcnew WindowsForms::Markers::GMarkerGoogle( PointLatLng(40.7, -74.0), MyType);
MyOverlay->Markers->Add(MyMarker);
gMapControl1->Overlays->Add(MyOverlay);
gMapControl1->ReloadMap();

How to change the default y axis for self stack bar

I want to plot a Bar series with MultiBars style as SelfStack. By default the self stack bar y axis value is 0 , Is there any way to change the default y axis for self stack bar
public class Bar_SelfStack
{
private Steema.TeeChart.Styles.Bar bar1;
private System.ComponentModel.IContainer components = null;
private Steema.TeeChart.TChart tChart1;
private Steema.TeeChart.Tools.GridBand gridBand1;
public Bar_SelfStack()
{
// This call is required by the Windows Form Designer.
InitializeComponent();
bar1.Add(100, "Cars");
bar1.Add(300, "Phones");
bar1.Add(200, "Lamps");
// Set "Self-Stacked":
bar1.MultiBar = Steema.TeeChart.Styles.MultiBars.SelfStack;
// cosmetic
bar1.Marks.Visible = false;
bar1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.Value;
bar1.ColorEach = true;
}
}
You can change the default Y axis to custom vertical axis as do in next simple code:
Steema.TeeChart.TChart tChart1;
public Form1()
{
InitializeComponent();
tChart1 = new TChart();
this.Controls.Add(tChart1);
tChart1.Top = 150;
tChart1.Left = 100;
tChart1.Height = 400;
tChart1.Width = 550;
InitializeChart();
}
Steema.TeeChart.Styles.Bar series1, series2, series3,series4;
Steema.TeeChart.Axis axis1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
series1 = new Bar(tChart1.Chart);
series2 = new Bar(tChart1.Chart);
series3 = new Bar(tChart1.Chart);
series4 = new Bar(tChart1.Chart);
axis1 = new Axis(tChart1.Chart);
tChart1.Axes.Custom.Add(axis1);
series1.FillSampleValues();
series2.FillSampleValues();
series3.FillSampleValues();
series4.FillSampleValues();
series1.Marks.Visible = false;
series2.Marks.Visible = false;
series3.Marks.Visible = false;
series4.Marks.Visible = false;
axis1.RelativePosition = tChart1.Panel.MarginLeft -12;
tChart1.Panel.MarginLeft = 10;
axis1.Horizontal = false;
series1.CustomVertAxis = axis1;
series1.MultiBar = MultiBars.SelfStack;
button1.Click +=button1_Click;
}
Could you tell us if previous code help you to achieve as you want?
I hope will helps.
Thanks,

GMap.NET question

i am trying to use GMap.NET to display a map using the following code
GMapControl g = new GMapControl();
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
g.Dock = DockStyle.Fill;
pnlMap.Controls.Add(g);
g.MapType = MapType.GoogleMap;
g.MaxZoom = 6;
g.MinZoom = 1;
g.Position = new PointLatLng(51.31835, 0.873866);
The issue is, the control loads but there is no visible map inside. Does anyone know what i might need to do
Thanks
edit:
the fix was this
public Form1()
{
InitializeComponent();
SuspendLayout();
GMapControl MainMap = new GMapControl();
{
MainMap.MapProvider = GMapProviders.YahooMap;
MainMap.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
MainMap.MinZoom = 1;
MainMap.MaxZoom = 17;
MainMap.Zoom = 9;
MainMap.Dock = DockStyle.Fill;
}
Controls.Add(MainMap);
ResumeLayout(true);
}

Categories

Resources