Hello,
I’m new to MapWinGis, and i would like to make a project which consists in placing points on the map, to draw the polygon according to the placed points except that I manage only to draw the polygon, no point is displayed. I try to add shape for point and polygon, what i’m doing wrong ? Thank you very much !
namespace test
{
public partial class Form1 : Form
{
bool flagNewShp, flagDgvValid;
Shape shp = new Shape();
Shape shpPoint = new Shape();
Shapefile sf = new Shapefile();
Shapefile sfPoint = new Shapefile();
public Form1()
{
InitializeComponent();
axMap1.CursorMode = tkCursorMode.cmNone;
axMap1.SendMouseDown = true;
axMap1.MouseDownEvent += AxMap1_MouseDownEvent;
dgvCoordonnees.Rows.Clear();
dgvCoordonnees.Columns.Clear();
dgvCoordonnees.AllowUserToAddRows = false;
dgvCoordonnees.AllowUserToDeleteRows = false;
dgvCoordonnees.AllowUserToOrderColumns = false;
dgvCoordonnees.AllowUserToResizeColumns = false;
dgvCoordonnees.AllowUserToResizeRows = false;
dgvCoordonnees.RowHeadersVisible = false;
dgvCoordonnees.Columns.Add("Point", "Point");
dgvCoordonnees.Columns.Add("Lat", "Lat");
dgvCoordonnees.Columns.Add("Lon", "Lon");
}
private void AxMap1_MouseDownEvent(object sender, _DMapEvents_MouseDownEvent e)
{
if (e.button == 1)
{
if (flagNewShp == true)
{
flagNewShp = false;
shp.Create(ShpfileType.SHP_POLYGON);
shpPoint.Create(ShpfileType.SHP_POINT);
sf.CreateNew("", ShpfileType.SHP_POLYGON);
sfPoint.CreateNew("1", ShpfileType.SHP_POINT);
flagDgvValid = true;
}
else
{
double x = 0.0, y = 0.0;
axMap1.PixelToProj(e.x, e.y, ref x, ref y);
shpPoint.AddPoint(x, y);
shp.AddPoint(x, y);
axMap1.PixelToDegrees(e.x, e.y, ref x, ref y);
double latitude = y;
double longitude = x;
if (flagDgvValid == true)
{
dgvCoordonnees.Rows.Add();
dgvCoordonnees[0, dgvCoordonnees.Rows.Count - 1].Value = dgvCoordonnees.Rows.Count;
dgvCoordonnees[1, dgvCoordonnees.Rows.Count - 1].Value = latitude;
dgvCoordonnees[2, dgvCoordonnees.Rows.Count - 1].Value = longitude;
}
sf.EditAddShape(shp);
sfPoint.EditAddShape(shpPoint);
ShapeDrawingOptions optionsPoint = sfPoint.DefaultDrawingOptions;
optionsPoint.PointType = tkPointSymbolType.ptSymbolStandard;
optionsPoint.PointShape = tkPointShapeType.ptShapeCross;
sfPoint.CollisionMode = MapWinGIS.tkCollisionMode.AllowCollisions;
sf.CollisionMode = MapWinGIS.tkCollisionMode.AllowCollisions;
ShapeDrawingOptions options = sf.DefaultDrawingOptions;
options.PointSize = 100;
options.FillVisible = true;
options.FillColor = new Utils().ColorByName(tkMapColor.LightPink);
options.FillTransparency = 100;
options.LineColor = new Utils().ColorByName(tkMapColor.Black);
options.LineWidth = 1;
MessageBox.Show($"Nombre de points : {shp.numPoints}");
MessageBox.Show($"Nombre de points : {shpPoint.numPoints}");
axMap1.AddLayer(shp, true);
axMap1.AddLayer(sf, true);
axMap1.AddLayer(sfPoint, true);
axMap1.AddLayer(shpPoint, true);
axMap1.Redraw();
//axMap1.CurrentZoom = 11;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
axMap1.Latitude = 46.827282F;
axMap1.Longitude = 8.227511F;
axMap1.CurrentZoom = 7;
}
private void btnNewShape_Click(object sender, EventArgs e)
{
flagNewShp = true;
}
}
}