我正在使用mapwingis并且我已经上传了所有需要的形状文件..现在我已经拥有了来自gps的数据,我想在我的地图中显示它。我研究过我可以使用drawcircleex,但它没有给我正确的位置,并且圆圈被卡在中心。继承我的代码:
MapWinGIS.Shapefile plane = new MapWinGIS.Shapefile();// shape 1
MapWinGIS.Shapefile roads = new MapWinGIS.Shapefile();// shape 2
MapWinGIS.Shapefile gensan = new MapWinGIS.Shapefile();// shape 3
MapWinGIS.Shapefile pois = new MapWinGIS.Shapefile();// shape 4
MapWinGIS.Shapefile pofw = new MapWinGIS.Shapefile();// shape 5
MapWinGIS.Shapefile places = new MapWinGIS.Shapefile();// shape 6
MapWinGIS.Shapefile roadsfin = new MapWinGIS.Shapefile();// shape 7
MapWinGIS.Shapefile circle = new MapWinGIS.Shapefile();// shape 8
int shape1, shape2, shape3, shape4, shape5, shape6, shape7, shape8;
public static string varname;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// layer of plane
plane.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/adminareasfinal.shp", null);
shape1 = axMap1.AddLayer(plane, true);
axMap1.set_ShapeLayerFillColor(shape1, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Linen)));
axMap1.set_ShapeLayerLineColor(shape1, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Linen)));
// layer of gensan
gensan.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/gensan_southcotabato/gensan_southcotabato.shp", null);
shape2 = axMap1.AddLayer(gensan, true);
axMap1.set_ShapeLayerFillColor(shape2, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.OldLace)));
axMap1.set_ShapeLayerLineColor(shape2, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)));
// layer of longitude and latitude
Single LineWidth1 = 1;
roadsfin.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/roadsfin.shp", null);
shape7 = axMap1.AddLayer(roadsfin, true);
axMap1.set_UDPointType(shape7, roadsfin);
axMap1.set_ShapeLayerPointSize(shape7, LineWidth1);
axMap1.set_ShapeLayerPointColor(shape7, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Transparent)));
// layer of roads
Single LineWidth = 2;
roads.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/roads.shp", null);
shape3 = axMap1.AddLayer(roads, true);
axMap1.set_ShapeLayerLineWidth(shape3, LineWidth);
axMap1.set_ShapeLayerLineColor(shape3, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.White)));
//layer of pois and pofw bitmap image
Single pointsize = 1;
pois.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/pois.shp", null);
shape4 = axMap1.AddLayer(pois, true);
pofw.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/pofw.shp", null);
shape5 = axMap1.AddLayer(pofw, true);
places.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/places.shp", null);
shape6 = axMap1.AddLayer(places, true);
int LineWidth7 = 10;
circle.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/newshape/finalepoint.shp", null);
shape8 = axMap1.AddLayer(circle, true);
axMap1.set_ShapeLayerPointColor(shape8, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)));
axMap1.set_ShapeLayerPointSize(shape8, LineWidth7);
string circlelabel;
double x12, y12;
for (int j = 0; j < circle.NumShapes - 1; j++)
{
circlelabel = System.Convert.ToString(roads.get_CellValue(1, j));
x12 = circle.get_Shape(j).Extents.xMin + (circle.get_Shape(j).Extents.xMax - circle.get_Shape(j).Extents.xMin) / 2;
y12 = circle.get_Shape(j).Extents.yMin + (circle.get_Shape(j).Extents.yMax - circle.get_Shape(j).Extents.yMin) / 2;
axMap1.AddLabel(shape8, circlelabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Red)), x12, y12, MapWinGIS.tkHJustification.hjCenter);
}
MapWinGIS.Image poisimage = new MapWinGIS.Image();
MapWinGIS.Image pofwimage = new MapWinGIS.Image();
MapWinGIS.Image placesimage = new MapWinGIS.Image();
poisimage.Open("C:/Users/User/Desktop/bitmap/poisimage.bmp", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null);
{
this.axMap1.set_ShapeLayerPointSize(shape4, pointsize);
this.axMap1.set_ShapeLayerPointType(shape4, MapWinGIS.tkPointType.ptUserDefined);
this.axMap1.set_UDPointType(shape4, poisimage);
}
axMap1.set_LayerVisible(shape4, true);
pofwimage.Open("C:/Users/User/Desktop/bitmap/pofwimage.bmp", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null);
{
this.axMap1.set_ShapeLayerPointSize(shape5, pointsize);
this.axMap1.set_ShapeLayerPointType(shape5, MapWinGIS.tkPointType.ptUserDefined);
this.axMap1.set_UDPointType(shape5, pofwimage);
}
axMap1.set_LayerVisible(shape5, true);
placesimage.Open("C:/Users/User/Desktop/bitmap/placesimage.bmp", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null);
{
this.axMap1.set_ShapeLayerPointSize(shape6, pointsize);
this.axMap1.set_ShapeLayerPointType(shape6, MapWinGIS.tkPointType.ptUserDefined);
this.axMap1.set_UDPointType(shape6, placesimage);
}
axMap1.set_LayerVisible(shape6, true);
// the following are the codes to show the names of Roads
string myLabel;
double x, y;
for (int i = 0; i < roads.NumShapes - 1; i++)
{
myLabel = System.Convert.ToString(roads.get_CellValue(4, i));
x = roads.get_Shape(i).Extents.xMin + (roads.get_Shape(i).Extents.xMax - roads.get_Shape(i).Extents.xMin) / 2;
y = roads.get_Shape(i).Extents.yMin + (roads.get_Shape(i).Extents.yMax - roads.get_Shape(i).Extents.yMin) / 2;
axMap1.AddLabel(shape2, myLabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), x, y, MapWinGIS.tkHJustification.hjCenter);
}
// the following are the codes to show the names of pois
string poislabel;
double pois1, pois2;
int handle = axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlScreenReferencedList);
for (int ps = 0; ps < pois.NumShapes - 1; ps++)
{
poislabel = System.Convert.ToString(pois.get_CellValue(4, ps));
pois1 = pois.get_Shape(ps).Extents.xMin + (pois.get_Shape(ps).Extents.xMax - pois.get_Shape(ps).Extents.xMin) / 2;
pois2 = pois.get_Shape(ps).Extents.yMin + (pois.get_Shape(ps).Extents.yMax - pois.get_Shape(ps).Extents.yMin) / 2;
double width = pois.get_Shape(ps).Extents.xMin + (pois.get_Shape(ps).Extents.xMax - pois.get_Shape(ps).Extents.xMin) / 2;
double height = pois.get_Shape(ps).Extents.yMin + (pois.get_Shape(ps).Extents.yMax - pois.get_Shape(ps).Extents.yMin) / 2;
axMap1.DrawCircleEx(handle, width, height, 5.0, 255, true);
axMap1.AddLabel(shape4, poislabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), pois1, pois2, MapWinGIS.tkHJustification.hjCenter);
}
// the following is to display the latitude
string latitude;// longitude;
double latx1, latx2;
for (int counter = 0; counter < roadsfin.NumShapes - 1; counter++)
{
latitude = System.Convert.ToString(roadsfin.get_CellValue(1, counter));
latx1 = roadsfin.get_Shape(counter).Extents.xMin + (roadsfin.get_Shape(counter).Extents.xMax - roadsfin.get_Shape(counter).Extents.xMin) / 2;
latx2 = roadsfin.get_Shape(counter).Extents.yMin + (roadsfin.get_Shape(counter).Extents.yMax - roadsfin.get_Shape(counter).Extents.yMin) / 2;
axMap1.AddLabel(shape7, latitude, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), latx1, latx2, MapWinGIS.tkHJustification.hjCenter);
}
// sample displaying of location
// the following are the codes to show the names of pofw
string pofwlabel;
double pofw1, pofw2;
for (int pf = 0; pf < pofw.NumShapes - 1; pf++)
{
pofwlabel = System.Convert.ToString(pofw.get_CellValue(4, pf));
pofw1 = pofw.get_Shape(pf).Extents.xMin + (pofw.get_Shape(pf).Extents.xMax - pofw.get_Shape(pf).Extents.xMin) / 2;
pofw2 = pofw.get_Shape(pf).Extents.yMin + (pofw.get_Shape(pf).Extents.yMax - pofw.get_Shape(pf).Extents.yMin) / 2;
axMap1.AddLabel(shape5, pofwlabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), pofw1, pofw2, MapWinGIS.tkHJustification.hjCenter);
}
// the following are the codes to show the names of places
string placeslabel;
double places1, places2;
for (int pl = 0; pl < places.NumShapes - 1; pl++)
{
placeslabel = System.Convert.ToString(places.get_CellValue(4, pl));
places1 = places.get_Shape(pl).Extents.xMin + (places.get_Shape(pl).Extents.xMax - places.get_Shape(pl).Extents.xMin) / 2;
places2 = places.get_Shape(pl).Extents.yMin + (places.get_Shape(pl).Extents.yMax - places.get_Shape(pl).Extents.yMin) / 2;
axMap1.AddLabel(shape6, placeslabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), places1, places2, MapWinGIS.tkHJustification.hjCenter);
}
double x_etchos = 125.141;
double y_etchos = 6.117;
double x_leche = 125.141;
double y_leche = 6.117;
// MapWinGIS.Extents ext = axMap1.Extents as MapWinGIS.Extents;
double ewanko;
for (int test1 = 0; test1 < roadsfin.NumShapes; test1++)
{
ewanko = System.Convert.ToDouble(roads.get_CellValue(4, test1));
if (x_etchos > roadsfin.get_Shape(test1).Extents.xMin && x_etchos < roadsfin.get_Shape(test1).Extents.xMax && y_etchos > roadsfin.get_Shape(test1).Extents.yMin && y_etchos < roadsfin.get_Shape(test1).Extents.yMax)
{
double width = roadsfin.get_Shape(test1).Extents.xMin + (roadsfin.get_Shape(test1).Extents.xMax - roadsfin.get_Shape(test1).Extents.xMin) / 2;
double height = roadsfin.get_Shape(test1).Extents.yMin + (roadsfin.get_Shape(test1).Extents.yMax - roadsfin.get_Shape(test1).Extents.yMin) / 2;
MessageBox.Show("width and height: " + width + " " + height);
//MessageBox.Show("x and y: " + ext.xMax + " <<max_X-min_X>> " + ext.xMin + " " + ext.yMax + " <<max_Y-min_X>> " + ext.yMin);
ext.SetBounds(x_etchos - width, y_etchos - height, 0.0, x_etchos + width, y_etchos + height, 0.0);
Application.DoEvents();
axMap1.ProjToPixel(x_etchos, y_etchos, ref x_leche, ref y_leche);
axMap1.DrawCircleEx(handle, x_leche, y_leche, 5.0, 255, true);
}
}
答案 0 :(得分:0)
此代码的问题是您只计算位置和位置一次。负载。您需要重新编写表单类来处理缩放/平移事件并重新计算形状位置和大小。
程序通常包含多个函数。 application.doEvents
将处理队列中的事件,但您不会根据事件更新形状。
提示强>
还有像
这样的东西pofw1 = pofw.get_Shape(pf).Extents.xMin + (pofw.get_Shape(pf).Extents.xMax - pofw.get_Shape(pf).Extents.xMin) / 2;
pofw2 = pofw.get_Shape(pf).Extents.yMin + (pofw.get_Shape(pf).Extents.yMax - pofw.get_Shape(pf).Extents.yMin) / 2;
很容易放入函数中,因为你在该函数中多次调用它。
private Point getCenter( Extents ext ) {
Point p;
p.X = ext.xMin + (ext.xMax - ext.xMin)/2.0;
p.Y = ext.yMin + (ext.yMax - ext.yMin)/2.0;
return p;
}
通过
调用Point pofwPoint = getCenter(pofw.get_Shape(pf).Extents);