Dear Sir,
I want read marker value on Marker-click Event.Please give me a solution.I am using a function as given below
------------------------------------------------------------------------------------------------------------------------------------
private void winformsMap1_MapClick1(object sender, MapClickWinformsMapEventArgs e)
{
PointShape originalShape = ExtentHelper.ToWorldCoordinate(winformsMap1.CurrentExtent, new ScreenPointF(e.ScreenX, e.ScreenY), winformsMap1.Width, winformsMap1.Height);
ManagedProj4Projection projection = new ManagedProj4Projection();
projection.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326);
projection.ExternalProjectionParametersString = ManagedProj4Projection.GetGoogleMapParametersString();
projection.Open();
PointShape decimalDegreePoint = (PointShape)projection.ConvertToInternalProjection(originalShape);
projection.Close();
}
-------------------------------------------------------------------------------------------------------------------------------------------------
But this is not give me proper output.
Regards
Harish Upadhyay
How to read marker lat. long. value on click
Hi Harish,
I thought that should related with your projection setting.
Could you please paste some more code snippet about how you set your layer projection?
Regards,
Don
Dear Sir,
I want read marker value on Marker-click Event.Please give me a solution.I am using a function as given below
---------------------------------------------------------------------------------------
public void add_marker_layer3()
{
try
{
InMemoryFeatureLayer pointLayer2 = new InMemoryFeatureLayer();
pointLayer2.Open();
pointLayer2.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap;
pointLayer2.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolSize = 5;
pointLayer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
pointLayer2.Close();
pointOverlay.Layers.Add("PointLayer3", pointLayer2);
winformsMap1.Overlays.Add("pointOverlay3", pointOverlay);
Proj4Projection prj4 = new Proj4Projection();
prj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
prj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
prj4.Open();
pointLayer2.FeatureSource.Projection = prj4;
prj4.Close();
winformsMap1.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
public void add_marker2(double lat, double Long, string name)
{
try
{
double latitude = Convert.ToDouble(lat, CultureInfo.InvariantCulture);
double longitude = Convert.ToDouble(Long, CultureInfo.InvariantCulture);
Feature feature = new Feature(longitude, latitude, name);
InMemoryFeatureLayer pointLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("PointLayer");
pointLayer.Open();
pointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = new GeoImage(@"C:\Users\LABPC3\Desktop\AQUA_red.png");
if (!pointLayer.InternalFeatures.Contains(name))
{
winformsMap1.MapClick += new EventHandler<mapclickwinformsmapeventargs>(winformsMap1_MapClick3);</mapclickwinformsmapeventargs>
pointLayer.InternalFeatures.Add(name, feature);
}
pointLayer.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void winformsMap1_MapClick3(object sender, MapClickWinformsMapEventArgs e)
{
PointShape originalShape = ExtentHelper.ToWorldCoordinate(winformsMap1.CurrentExtent, new ScreenPointF(e.ScreenX, e.ScreenY), winformsMap1.Width, winformsMap1.Height);
ManagedProj4Projection projection = new ManagedProj4Projection();
projection.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326);
projection.ExternalProjectionParametersString = ManagedProj4Projection.GetGoogleMapParametersString();
projection.Open();
PointShape decimalDegreePoint = (PointShape)projection.ConvertToInternalProjection(originalShape);
projection.Close();
}
----------------------------------------------
But this is not give me proper output.
Regards
Harish Upadhyay
Hi Harish,
I did some small changes, it looks your code works well here, the image shows on anywhere I click.
Please view attached code and let me know whether that works for you.
Regards,
Don
001_DisplayASimpleMap.cs (8.12 KB)
Dear Sir,
This process i am use but this is not give me accurate output.this function calculate mouse click point and i want read marker exact lat. long. value on click.
Please give me a solution.
Thanks & Regards
Harish Upadhyay
Hi Harish,
Do you meant you want to add marker and get marker location when you click it?
If so then please view the code snippet as below, markerLocation should be what you want:
private void DisplayMap_Load(object sender, EventArgs e)
{
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
winformsMap1.CurrentExtent = new RectangleShape(-10, 10, 10, -10);
Marker marker = new Marker(new PointShape(0, 0));
marker.Image = Image.FromFile(@"C:\Users\LABPC3\Desktop\AQUA_red.png");
marker.Width = 20;
marker.Height = 34;
marker.Click += new EventHandler(marker_Click);
marker.Name = "m1";
Marker marker2 = new Marker(new PointShape(5, 5));
marker2.Image = Image.FromFile(@"C:\Users\LABPC3\Desktop\AQUA_red.png");
marker2.Width = 20;
marker2.Height = 34;
marker2.Click += new EventHandler(marker_Click);
marker2.Name = "m2";
SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay();
markerOverlay.MapControl = winformsMap1;
markerOverlay.Markers.Add(marker);
markerOverlay.Markers.Add(marker2);
winformsMap1.Overlays.Add("MarkerOverlay", markerOverlay);
winformsMap1.Refresh();
}
void marker_Click(object sender, EventArgs e)
{
Marker clickedMarker = sender as Marker;
PointShape markerLocation = clickedMarker.Position;
}
Regards,
Don
Dear sir,
how to use Proj4Projection layer with SimpleMarkerOverlay because the marker not show exact lat long Position.
Please give me a solution.
Thanks & Regards
Harish Upadhyay
Hi Harish,
Please follow the below codes:
ManagedProj4Projection proj4 =
new
ManagedProj4Projection();
proj4.InternalProjectionParametersString = ManagedProj4Projection.GetDecimalDegreesParametersString();
proj4.ExternalProjectionParametersString = ManagedProj4Projection.GetGoogleMapParametersString();
proj4.Open();
SimpleMarkerOverlay overlay =
new
SimpleMarkerOverlay();
overlay.MapControl = winformsMap1;
PointShape markerPoint = proj4.ConvertToExternalProjection(
new
PointShape(5, 5))
as
PointShape;
Marker marker =
new
Marker(markerPoint);
marker.Image = CSharpWinformsSamples.Properties.Resources.AQUA;
marker.Width = 20;
marker.Height = 34;
overlay.Markers.Add(marker);
winformsMap1.Overlays.Add(overlay);
If any questions, please feel free to let us know.
Regards,
Johnny
Dear Sir,
Thanks .
Regards
Harish Upadhyay
Hi Harish,
Any question please let us know.
Regards,
Don
Dear Sir,
Marker not show according to lat. long. value. I am using function given below as
-----------------------------------------------------------------
public void add_all_simplemarker_layer_of_Proj()
{
try
{
SimpleMarkerOverlay markerOverlay_green = new SimpleMarkerOverlay();
markerOverlay_green.MapControl = winformsMap1;
winformsMap1.Overlays.Add("markerOverlay_green", markerOverlay_green);
winformsMap1.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
public void simple_marker_green(double lat, double Long,string name)
{
try
{
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = ManagedProj4Projection.GetDecimalDegreesParametersString();
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
proj4.Open();
PointShape markerPoint = proj4.ConvertToExternalProjection(new PointShape(lat, Long)) as PointShape;
proj4.Close();
Marker marker = new Marker(markerPoint);
marker.Image = Properties.Resources.AQUA;
marker.Width = 20;
marker.Height = 30;
marker.YOffset = -17;
marker.Click += new EventHandler(marker_Click_green);
SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)winformsMap1.Overlays["markerOverlay_green"];
if (!markerOverlay.Markers.Contains(name))
{
markerOverlay.Markers.Add(name, marker);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void marker_Click_green(object sender,EventArgs e)
{
try
{
Marker clickedMarker = sender as Marker;
PointShape markerLocation = clickedMarker.Position;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
------------------------------------------------------------
Please give me a solution.
Regards
Harish Upadhyay
Hi Harish,
I created a small sample for you, please check it.
If the issue persists, please feel free to let us know.
Regards,
Troy
MarkerProjection.zip (15.1 KB)
Dear Sir,
I have problem regarding of lat. long. as given below
SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)winformsMap1.Overlays["MarkerOverlay"];
Marker marker = new Marker(27.2909,75.1929);
marker.Image = Properties.Resources.AQUA;
marker.Width = 20;
marker.Height = 34;
marker.YOffset = -17;
marker.Click += new EventHandler(marker_Click);
markerOverlay.Markers.Add(marker);
winformsMap1.Refresh();
And
You are assigning the map (x,y) coordinate.So Please give me a solution.
Regards
Harish Upadhyay
Dear Sir,
Thanks .
The Marker show on right place according to lat. long. .
Regards
Harish Upadhyay
Dear Sir,
This function as
SimpleMarkerOverlay markerOverlay_green = (SimpleMarkerOverlay)winformsMap1.Overlays["markerOverlay_green"];
markerOverlay_green.Markers.Remove(marker);
winformsMap1.Refresh();
Not remove the marker from map canvas. Please give me a solution.
Regards
Harihs Upadhyay
Dear Sir,
Thanks.
I have a problem about of delete marker layer.I am using a function as given below
SimpleMarkerOverlay markerOverlay_green = (SimpleMarkerOverlay)winformsMap1.Overlays["markerOverlay_green"];
markerOverlay_green.Markers.Remove(marker);
winformsMap1.Refresh();
But not remove the marker from map canvas. Please give me a solution.
Regards
Harihs Upadhyay
Hi Harish,
Except remove marker from marker list, we still need to dispose it.
SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)winformsMap1.Overlays[
"MarkerOverlay"
];
markerOverlay.Markers.Remove(clickedMarker);
clickedMarker.Dispose();
winformsMap1.Refresh();
Thanks,
Troy
Dear Sir,
Thanks.
But I want remove all markers with map control and SimpleMarkerOverlay at a time so please give me a solution.
I am using given below function
Marker marker;
public void clear_marker()
{
try
{
SimpleMarkerOverlay markerOverlay_green = (SimpleMarkerOverlay)winformsMap1.Overlays[“markerOverlay_green”];
markerOverlay_green.Markers.Remove(marker);
marker.Dispose();
markerOverlay_green.MapControl.Overlays.Remove(“markerOverlay_green”);
winformsMap1.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “Error”);
}
}
but this is working very slow and thread Exception throw in the application please find the attachment.
Regards
Harish Upadhyay
001_New_Microsoft_Word_Document.docx (133 KB)
Hi Harish,
Sorry for the misunderstanding, but I think the below codes should works for you.
SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)winformsMap1.Overlays["MarkerOverlay"];
foreach (var item in markerOverlay.Markers)
{
winformsMap1.Controls.Remove(item);
}
winformsMap1.Overlays.Remove(markerOverlay);
winformsMap1.Refresh();
Thanks,
Troy