MapWindow Gis 组件代码示例:

官方网站: http://www.mapwindow.org/

该示例使用mapwindow 4 MapWinGIS.ocx X86,其它版本请参考官网相关代码示例。

View Code

#region 地图相关//地图初始化private voidInitMap(){axMap.CursorMode=MapWinGIS.tkCursorMode.cmPan;axMap.SendMouseMove= true;axMap.SendMouseDown= true;axMap.DisableWaitCursor= true;Shapefile sf_provence_area= newShapefile();Shapefile sf_provence_city= newShapefile();Shapefile sf_diqu_area= newShapefile();Shapefile sf_diqu= newShapefile();Shapefile sf_town= newShapefile();sf_provence_area.Open(Application.StartupPath+ "\\Map\\bou2_4p.shp", null);sf_provence_city.Open(Application.StartupPath+ "\\Map\\res1_4m.shp", null);sf_diqu_area.Open(Application.StartupPath+ "\\Map\\diquJie_polyline.shp", null);sf_diqu.Open(Application.StartupPath+ "\\Map\\res2_4m.shp", null);//sf_town.Open(Application.StartupPath + "\\Map\\XianCh_point.shp", null);int idx1 = axMap.AddLayer(sf_provence_area, true);int idx2 = axMap.AddLayer(sf_provence_city, true);int idx3 = axMap.AddLayer(sf_diqu_area, true);int idx4 = axMap.AddLayer(sf_diqu, true);//int idx5 = axMap.AddLayer(sf_town, true);
axMap.set_ShapeLayerFillColor(idx1, (uint)ColorTranslator.ToOle(Color.FromArgb(0xF2, 0xEF, 0xE9)));axMap.set_ShapeLayerLineWidth(idx3,0.3f);axMap.set_ShapeLayerPointSize(idx2,5);axMap.set_ShapeLayerPointType(idx2, tkPointType.ptDiamond);axMap.set_ShapeLayerPointSize(idx4,1);//axMap.set_ShapeLayerPointSize(idx5, 1);#region 设置地区标签int idx_diqu =axMap.NewDrawing(tkDrawReferenceList.dlSpatiallyReferencedList);//axMap.set_DrawingLabelsScale(idx_diqu, true);axMap.DrawingFont(idx_diqu, "Tahoma", 7);axMap.set_UseDrawingLabelCollision(idx_diqu,true);axMap.set_DrawingLabelsShadow(idx_diqu,true);for (int i = 0; i < sf_diqu.NumShapes; i++){string labtxt = sf_diqu.get_CellValue(5, i).ToString();doublex, y;MapWinGIS.Shape sh=sf_diqu.get_Shape(i);x= sh.get_Point(0).x;y= sh.get_Point(0).y;axMap.AddDrawingLabel(idx_diqu, labtxt,0, x, y, tkHJustification.hjNone);}#endregion#region 设置省会标签int idx =axMap.NewDrawing(tkDrawReferenceList.dlSpatiallyReferencedList);axMap.DrawingFont(idx,"Tahoma", 8);axMap.set_UseDrawingLabelCollision(idx,true);axMap.set_DrawingLabelsShadow(idx,true);axMap.set_DrawingLabelsShadowColor(idx, (uint)(ColorTranslator.ToOle(Color.FromArgb(0xDD, 0xDD, 0xFF))));for (int i = 0; i < sf_provence_city.NumShapes; i++){string labtxt = sf_provence_city.get_CellValue(5, i).ToString();doublex, y;MapWinGIS.Shape sh=sf_provence_city.get_Shape(i);x= sh.get_Point(0).x;y= sh.get_Point(0).y;axMap.AddDrawingLabel(idx, labtxt,0, x, y, tkHJustification.hjNone);}#endregion#region  设置省份标签stringlabelText1;int _idx =axMap.NewDrawing(tkDrawReferenceList.dlSpatiallyReferencedList);axMap.DrawingFont(_idx,"Tahoma", 9);axMap.set_UseDrawingLabelCollision(_idx,true);axMap.set_DrawingLabelsShadow(_idx,true);axMap.set_DrawingLabelsShadowColor(_idx, (uint)(ColorTranslator.ToOle(Color.FromArgb(0xD6, 0xD6, 0xAD))));for (int i = 0; i < sf_provence_area.NumShapes; i++){labelText1= sf_provence_area.get_CellValue(6, i).ToString();double area = Convert.ToDouble(sf_provence_area.get_CellValue(0, i));if (area < 0.2){continue;}MapWinGIS.Shape sh=sf_provence_area.get_Shape(i);doublex, y;CalcShXY(sh,out x, outy);if (!sf_provence_area.PointInShape(i, x, y)){x= sh.get_Point(sh.numPoints * 3 / 4).x;y= sh.get_Point(sh.numPoints * 3 / 4).y;}axMap.AddDrawingLabel(_idx, labelText1, (uint)(ColorTranslator.ToOle(Color.Green)), x, y, tkHJustification.hjNone);}#endregionaxMap.set_UseLabelCollision(idx1,true);axMap.set_LayerLabelsShadow(idx1,true);}//计算地图中心点private void CalcShXY(MapWinGIS.Shape sh, out double x, out doubley){double minX = double.MaxValue;double minY = double.MaxValue;double maxX = 0.0;double maxY = 0.0;for (int m = 0; m < sh.numPoints; m++){if (sh.get_Point(m).x <minX){minX=sh.get_Point(m).x;}if (sh.get_Point(m).y <minY){minY=sh.get_Point(m).y;}if (sh.get_Point(m).x >maxX){maxX=sh.get_Point(m).x;}if (sh.get_Point(m).y >maxY){maxY=sh.get_Point(m).y;}}x= (maxX + minX) / 2;y= (maxY + minY) / 2;}//地图鼠标移动private void axMap_MouseMoveEvent(objectsender, AxMapWinGIS._DMapEvents_MouseMoveEvent e){double x = 0;double y = 0;axMap.PixelToProj(e.x, e.y,ref x, refy);tsLabTxt.Text= "东经:" + x.ToString("F5") + "北纬:" + y.ToString("F5");}//地图鼠标点击private void axMap_MouseDownEvent(objectsender, AxMapWinGIS._DMapEvents_MouseDownEvent e){double x = 0;double y = 0;if (2 ==e.button){axMap.ClearDrawing(_dictdrawHandels[DrawHandels.MeaSureHandel]);ClearMeasurePoints();tsOperateInfo.Caption= string.Empty;_cur=CurState.Arrow;axMap.MapCursor=tkCursor.crsrMapDefault;return;}axMap.PixelToProj(e.x, e.y,ref x, refy);MPoint point= newMPoint(){x=x,y=y};switch(_cur){caseCurState.Cross:tsTextPoint.Text= point.x.ToString("F5") + "," + point.y.ToString("F5");break;caseCurState.MeasurementLenth:_measurePoints.Add(point);axMap_AfterTrackingLayerDraw();tsOperateInfo.Caption= "距离为:" + CalcLenght(_measurePoints).ToString("F2") + "";break;caseCurState.AddSwerve:if ("FK_Swerve" ==gc.DataMember){if ("-1" ==edLookRoad.EditValue.ToString()){return;}intnewID;object[] objArray = new object[] { 0, Convert.ToInt32(edLookRoad.EditValue), Convert.ToInt32(point.x * 100000), Convert.ToInt32(point.y * 100000), 0, 0};EsClass.NewTableRow(esdbDS.t_swerve, objArray,"SwerveID", outnewID);_ppt.x=point.x;_ppt.y=point.y;menuItemSwerve.Tag= true;ShowInMap(false, false, false, true, false, false);axMap_AfterTrackingLayerDraw();}break;caseCurState.SetDepotGps:if ("FK_Depots" ==gc.DataMember){ChgGVGps(gvDepots.DataSource, point);menuItemDeport.Tag= true;menuItemAng.Tag= true;ShowInMap(false, true, true, false, false, false);axMap_AfterTrackingLayerDraw();}break;caseCurState.SetBroadcastGps:BindingSource bsBroadcast=(BindingSource)gvBroadcast.DataSource;if (null ==bsBroadcast.Current){return;}DataRowView drvBroadcast=(DataRowView)bsBroadcast.Current;gvBroadcast.FocusedColumn= gvBroadcast.Columns[0];if (string.Empty == drvBroadcast.Row["起始时间"].ToString() || string.Empty == drvBroadcast["结束时间"].ToString()){XtraMessageBox.Show("请先设置起止时间!");return;}if ("FK_Broadcast" ==gc.DataMember){ChgGVGps(gvBroadcast.DataSource, point);menuItemBroadcast.Tag= true;ShowInMap(false, false, false, false, false, true);axMap_AfterTrackingLayerDraw();}break;caseCurState.SetSwerveGps:if ("FK_Swerve" ==gc.DataMember){ChgGVGps(gvSwerve.DataSource, point);menuItemSwerve.Tag= true;menuItemDeport.Tag= true;ShowInMap(false, false, false, true, false, false);axMap_AfterTrackingLayerDraw();}break;caseCurState.ExtendSpeedArea:if ("FK_Speed" ==gc.DataMember){BindingSource bs=(BindingSource)gvSpeed.DataSource;if (null ==bs.Current){return;}DataRowView drv=(DataRowView)bs.Current;int pot = 0;string currentid = drv["SpeedID"].ToString();int currentspeed = (int)drv["限速"];for (int b = 0; b < esdbDS.t_speed.Rows.Count; b++){if (esdbDS.t_speed.Rows[b].RowState ==DataRowState.Deleted){continue;}if (esdbDS.t_speed.Rows[b].RowState ==DataRowState.Detached){continue;}if (currentid == esdbDS.t_speed.Rows[b]["SpeedID"].ToString()){pot=b;}}DataTable dt=esdbDS.t_speed;DataRow row=dt.NewRow();row.ItemArray= new object[]{ row.ItemArray[0], Convert.ToInt32(edLookRoad.EditValue), 1, Convert.ToInt32(point.x * 100000),Convert.ToInt32(point.y* 100000), currentspeed };dt.Rows.InsertAt(row, pot+ 1);dt.Columns["SpeedID"].Unique = true;dt.PrimaryKey= new DataColumn[] { dt.Columns["SpeedID"] };_ppt.x=point.x;_ppt.y=point.y;menuItemSpeed.Tag= true;ShowInMap(false, false, false, false, true, false);axMap_AfterTrackingLayerDraw();bs.MoveLast();bs.EndEdit();gc.MainView.CloseEditor();}break;}}//地图导航工具点击private void tool_track_axmap_ItemClicked(objectsender, ToolStripItemClickedEventArgs e){_cur=(CurState)(Convert.ToInt32(e.ClickedItem.Tag));axMap.MapCursor=tkCursor.crsrMapDefault;axMap.MouseWheelSpeed= 0.8;switch(_cur){caseCurState.Arrow:axMap.CursorMode=tkCursorMode.cmNone;break;caseCurState.Pan:axMap.CursorMode=tkCursorMode.cmPan;break;caseCurState.ZoomIn:axMap.CursorMode=tkCursorMode.cmZoomIn;break;caseCurState.ZoomOut:axMap.CursorMode=tkCursorMode.cmZoomOut;break;caseCurState.Global:axMap.CursorMode=tkCursorMode.cmNone;ShowFullPath();break;caseCurState.Cross:axMap.MapCursor=tkCursor.crsrCross;break;caseCurState.MeasurementLenth:axMap.CursorMode=tkCursorMode.cmNone;ClearMeasurePoints();break;caseCurState.ChgGpsDirection:axMap.CursorMode=tkCursorMode.cmNone;axMap.MouseWheelSpeed= 1;break;default:axMap.CursorMode=tkCursorMode.cmNone;break;}}//显示地图 加载地图数据private void ShowInMap(bool istrack, bool isdepotsx, bool isdepotxx, bool isswerve, bool isspeed, boolisbroadcast){if (null ==edLookRoad.EditValue){if(istrack){_arrTrack.Clear();}if(isdepotsx){_arrDepotsx.Clear();}if(isdepotxx){_arrDepotxx.Clear();}if(isswerve){_arrSwerve.Clear();}if(isspeed){_arrSpeed.Clear();}if(isbroadcast){_arrBroadCast.Clear();}return;}if(istrack){DataRow[] drs= esdbDS.t_track.Select("RoadID=" +edLookRoad.EditValue.ToString());if (drs.Length > 0){ShowTrack(esdbDS.t_track);}else{_arrTrack.Clear();CreateDTTrack();ShowTrack(dtTrack270);}}if(isdepotsx){_arrDepotsx.Clear();string filter = string.Format("上下行={0}", 0);foreach (DataRow row in esdbDS.Tables["t_depots"].Select(filter)){if (row.RowState ==DataRowState.Deleted){continue;}if (row["RoadID"].ToString() ==edLookRoad.EditValue.ToString()){MPoint pt= newMPoint();pt.x= Convert.ToDouble(row["经度"]) / 100000;pt.y= Convert.ToDouble(row["纬度"]) / 100000;DepotsSX dpts;dpts._name= (string)row["站名"];dpts._pt=pt;dpts._ang= (int)row["角度"];_arrDepotsx.Add(dpts);}}}if(isdepotxx){_arrDepotxx.Clear();string filter = string.Format("上下行={0}", 1);foreach (DataRow row in esdbDS.Tables["t_depots"].Select(filter)){if (row.RowState ==DataRowState.Deleted){continue;}if (row["RoadID"].ToString() ==edLookRoad.EditValue.ToString()){MPoint pt= newMPoint();pt.x= Convert.ToDouble(row["经度"]) / 100000;pt.y= Convert.ToDouble(row["纬度"]) / 100000;DepotsXX dpts;dpts._name= (string)row["站名"];dpts._pt=pt;dpts._ang= (int)row["角度"];_arrDepotxx.Add(dpts);}}}if(isswerve){_arrSwerve.Clear();foreach (DataRow row inesdbDS.t_swerve){if (row.RowState ==DataRowState.Deleted){continue;}if (row["RoadID"].ToString() ==edLookRoad.EditValue.ToString()){string state =row.RowState.ToString();MPoint pt= newMPoint();pt.x= Convert.ToDouble(row["经度"]) / 100000;pt.y= Convert.ToDouble(row["纬度"]) / 100000;Swerves swers;swers._pt=pt;swers._ang= (int)row["角度"];_arrSwerve.Add(swers);}}}if(isspeed){_arrSpeed.Clear();string filter = string.Format("RoadID={0}", edLookRoad.EditValue.ToString());DataRow[] drc= esdbDS.Tables["t_speed"].Select(filter);for (int i = 0; i <drc.Length; ){if (drc[i]["RoadID"].ToString() ==edLookRoad.EditValue.ToString()){if (drc[i].RowState ==DataRowState.Deleted){continue;}if ("0" == drc[i]["经度"].ToString() || "0" == drc[i]["纬度"].ToString()){List<MPoint> points = new List<MPoint>();Speed _speed= newSpeed();int speed = (int)drc[i]["限速"];if (++i ==drc.Length)break;while ("0" != drc[i]["经度"].ToString() || "0" != drc[i]["纬度"].ToString()){MPoint point= newMPoint();point.x= Convert.ToDouble(drc[i]["经度"]) / 100000;point.y= Convert.ToDouble(drc[i]["纬度"]) / 100000;points.Add(point);if (++i ==drc.Length)break;}_speed._points=points;_speed._speed=speed;_arrSpeed.Add(_speed);}}}}if(isbroadcast){_arrBroadCast.Clear();foreach (DataRow row inesdbDS.t_broadcast){if (row.RowState ==DataRowState.Deleted){continue;}if (row["RoadID"].ToString() ==edLookRoad.EditValue.ToString()){MPoint pt= newMPoint();pt.x= Convert.ToDouble(row["经度"]) / 100000;pt.y= Convert.ToDouble(row["纬度"]) / 100000;Broadcast bdct;bdct._pt=pt;bdct._type= row["类型"].ToString();_arrBroadCast.Add(bdct);}}}axMap_AfterTrackingLayerDraw();}//绘制地图private voidaxMap_AfterTrackingLayerDraw(){#region draw trackif ((bool)menuItemTrack.Tag){menuItemDeport.Tag= true;if(menuItemTrack.Checked){ClearspecificDrawing(_dictdrawHandels, DrawHandels.TrackDrawHandel,-1);_dictdrawHandels[DrawHandels.TrackDrawHandel]=axMap.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);for (int i = 0; i < _arrTrack.Count; i++){Track tr=(Track)_arrTrack[i];for (int k = 0; k < tr._points.Count; k++){if (k + 1 <tr._points.Count){axMap.DrawLineEx(_dictdrawHandels[DrawHandels.TrackDrawHandel], tr._points[k].x, tr._points[k].y, tr._points[k+ 1].x,tr._points[k+ 1].y, 1, (uint)(ColorTranslator.ToOle(Color.FromArgb(0, 0x72, 0xE3))));}}}}else{ClearspecificDrawing(_dictdrawHandels, DrawHandels.TrackDrawHandel,-1);}menuItemTrack.Tag= false;}#endregion#region draw depotif ((bool)menuItemDeport.Tag){if(menuItemDeport.Checked){ClearspecificDrawing(_dictdrawHandels, DrawHandels.DepotDrawHandle,-1);_dictdrawHandels[DrawHandels.DepotDrawHandle]=axMap.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);axMap.DrawingFont(_dictdrawHandels[DrawHandels.DepotDrawHandle],"Tahoma", 8);for (int i = 0; i < _arrDepotsx.Count; i++){DepotsSX mpt=(DepotsSX)_arrDepotsx[i];if (0 == mpt._pt.x && 0 ==mpt._pt.y){continue;}axMap.DrawCircleEx(_dictdrawHandels[DrawHandels.DepotDrawHandle], mpt._pt.x, mpt._pt.y,2, (uint)(ColorTranslator.ToOle(Color.Black)), true);AddDrawingLableDepot(_dictdrawHandels[DrawHandels.DepotDrawHandle], mpt._name, (uint)ColorTranslator.ToOle(Color.Green), mpt._pt.x, mpt._pt.y, tkHJustification.hjNone);}for (int i = 0; i < _arrDepotxx.Count; i++){DepotsXX mpt=(DepotsXX)_arrDepotxx[i];if (0 == mpt._pt.x && 0 ==mpt._pt.y){continue;}axMap.DrawCircleEx(_dictdrawHandels[DrawHandels.DepotDrawHandle], mpt._pt.x, mpt._pt.y,2, (uint)(ColorTranslator.ToOle(Color.Purple)), true);AddDrawingLableDepot(_dictdrawHandels[DrawHandels.DepotDrawHandle], mpt._name, (uint)ColorTranslator.ToOle(Color.FromArgb(0x6C, 0x6C, 0x6C)), mpt._pt.x, mpt._pt.y, tkHJustification.hjNone);}axMap.set_UseDrawingLabelCollision(_dictdrawHandels[DrawHandels.DepotDrawHandle],true);}else{ClearspecificDrawing(_dictdrawHandels, DrawHandels.DepotDrawHandle,-1);}menuItemDeport.Tag= false;}#endregion#region draw swerveif ((bool)menuItemSwerve.Tag){if(menuItemSwerve.Checked){Dictionary<int, int> fonts = new Dictionary<int, int>();Removelayer(ref_idx_shafile_swerve);Removelayer(ref_idx_shafile_swerve_ico);Shapefile shapefile_swerve= CreateShapefile("shapefile_swerve", ShpfileType.SHP_POINT, out_idx_shafile_swerve);Shapefile shapefile_swerve_ico= CreateShapefile("shapefile_swerve_ico", ShpfileType.SHP_POINT, out_idx_shafile_swerve_ico);List<MapWinGIS.Point> points = new List<MapWinGIS.Point>();for (int i = 0; i < _arrSwerve.Count; i++){Swerves sw=(Swerves)_arrSwerve[i];MapWinGIS.Point point= newMapWinGIS.Point{x=sw._pt.x,y=sw._pt.y,Z=sw._ang};points.Add(point);}ShapefileInsertPoints(shapefile_swerve, points);ShapefileInsertPoints(shapefile_swerve_ico, points);SetLayerEsFont(shapefile_swerve, _idx_shafile_swerve,"ES_Font", 14, fonts, 255, false);SetLayerEsFont(shapefile_swerve_ico, _idx_shafile_swerve_ico,"ES_Font", 8, (uint)(ColorTranslator.ToOle(Color.FromArgb(0x70, 0x70, 0x38))), false, 0x32);}else{Removelayer(ref_idx_shafile_swerve);Removelayer(ref_idx_shafile_swerve_ico);}menuItemSwerve.Tag= false;}#endregion#region draw speedif ((bool)menuItemSpeed.Tag){if(menuItemSpeed.Checked){ClearspecificDrawing(_dictdrawHandels, DrawHandels.SpeedHandel,-1);Removelayer(ref_idx_shfile_speed);_dictdrawHandels[DrawHandels.SpeedHandel]=axMap.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);axMap.DrawingFont(_dictdrawHandels[DrawHandels.SpeedHandel],"Tahoma", 6);Shapefile shapefile_speed= CreateShapefile("shapefile_broadcast", ShpfileType.SHP_POINT, out_idx_shfile_speed);List<MapWinGIS.Point> points = new List<MapWinGIS.Point>();axMap.set_UseDrawingLabelCollision(_dictdrawHandels[DrawHandels.SpeedHandel],true);axMap.set_DrawingLabelsOffset(_dictdrawHandels[DrawHandels.SpeedHandel],15);for (int i = 0; i < _arrSpeed.Count; i++){Speed sp=(Speed)_arrSpeed[i];foreach (MPoint point insp._points){MapWinGIS.Point p= newMapWinGIS.Point{x=point.x,y=point.y};points.Add(p);}for (int k = 0; k < sp._points.Count; k++){axMap.AddDrawingLabel(_dictdrawHandels[DrawHandels.SpeedHandel], sp._speed.ToString(), (uint)ColorTranslator.ToOle(Color.OrangeRed), sp._points[k].x, sp._points[k].y, tkHJustification.hjNone);if (k + 1 <sp._points.Count){axMap.DrawLineEx(_dictdrawHandels[DrawHandels.SpeedHandel], sp._points[k].x, sp._points[k].y, sp._points[k+ 1].x, sp._points[k + 1].y, 1,(uint)(ColorTranslator.ToOle(Color.FromArgb(0xFF, 0xC3, 0x45))));}}}ShapefileInsertPoints(shapefile_speed, points);SetLayerEsFont(shapefile_speed, _idx_shfile_speed,"ES_Font", 7, (uint)(ColorTranslator.ToOle(Color.Purple)), false, 0x23);}else{ClearspecificDrawing(_dictdrawHandels, DrawHandels.SpeedHandel,-1);Removelayer(ref_idx_shfile_speed);}menuItemSpeed.Tag= false;}#endregion#region draw broadcastif ((bool)menuItemBroadcast.Tag){if(menuItemBroadcast.Checked){ClearspecificDrawing(_dictdrawHandels, DrawHandels.BroadCastHandel,-1);Removelayer(ref_idx_shfile_broadcast);_dictdrawHandels[DrawHandels.BroadCastHandel]=axMap.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);axMap.set_UseDrawingLabelCollision(_dictdrawHandels[DrawHandels.BroadCastHandel],true);axMap.DrawingFont(_dictdrawHandels[DrawHandels.BroadCastHandel],"Tahoma", 8);axMap.set_DrawingLabelsOffset(_dictdrawHandels[DrawHandels.BroadCastHandel],15);Shapefile shapefile_broadcast= CreateShapefile("shapefile_broadcast", ShpfileType.SHP_POINT, out_idx_shfile_broadcast);List<MapWinGIS.Point> points = new List<MapWinGIS.Point>();for (int i = 0; i < _arrBroadCast.Count; i++){Broadcast bc=(Broadcast)_arrBroadCast[i];MapWinGIS.Point point= newMapWinGIS.Point{x=bc._pt.x,y=bc._pt.y,};points.Add(point);string type = bc._type == "0" ? "安全信息" : "广告";axMap.AddDrawingLabel(_dictdrawHandels[DrawHandels.BroadCastHandel], type, (uint)ColorTranslator.ToOle(Color.FromArgb(0xC4, 0xC4, 0)), bc._pt.x, bc._pt.y, tkHJustification.hjNone);}ShapefileInsertPoints(shapefile_broadcast, points);SetLayerEsFont(shapefile_broadcast, _idx_shfile_broadcast,"ES_Font", 12, 255, false, 0x2F);}else{ClearspecificDrawing(_dictdrawHandels, DrawHandels.BroadCastHandel,-1);Removelayer(ref_idx_shfile_broadcast);}menuItemBroadcast.Tag= false;}#endregion#region draw measure line & pointif (_measurePoints.Count > 0){ClearspecificDrawing(_dictdrawHandels, DrawHandels.MeaSureHandel,-1);_dictdrawHandels[DrawHandels.MeaSureHandel]=axMap.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);for (int i = 0; i < _measurePoints.Count; i++){MPoint point=_measurePoints[i];for (int k = 0; k < _measurePoints.Count; k++){if (k + 1 <_measurePoints.Count){axMap.DrawLineEx(_dictdrawHandels[DrawHandels.MeaSureHandel], _measurePoints[k].x, _measurePoints[k].y, _measurePoints[k+ 1].x, _measurePoints[k + 1].y, 1,(uint)(ColorTranslator.ToOle(Color.FromArgb(0x64, 0x21, 0))));}axMap.DrawCircleEx(_dictdrawHandels[DrawHandels.MeaSureHandel], _measurePoints[k].x, _measurePoints[k].y,1.8, 255, true);}}}#endregion#region draw angif ((bool)menuItemAng.Tag){if(menuItemAng.Checked){if (_idx_shpfile_ang > 1){axMap.RemoveLayer(_idx_shpfile_ang);_idx_shpfile_ang= -1;}Dictionary<int, int> fonts = new Dictionary<int, int>();Shapefile shapefile_ang= CreateShapefile("shapefile_ang", ShpfileType.SHP_POINT, out_idx_shpfile_ang);List<MapWinGIS.Point> points = new List<MapWinGIS.Point>();for (int i = 0; i < _arrDepotsx.Count; i++){DepotsSX mpt=(DepotsSX)_arrDepotsx[i];if(0 == mpt._pt.x && 0 ==mpt._pt.y){continue;}MapWinGIS.Point point= newMapWinGIS.Point(){x=mpt._pt.x,y=mpt._pt.y,Z=mpt._ang,};points.Add(point);}for (int i = 0; i < _arrDepotxx.Count; i++){DepotsXX mpt=(DepotsXX)_arrDepotxx[i];if (0 == mpt._pt.x && 0 ==mpt._pt.y){continue;}MapWinGIS.Point point= newMapWinGIS.Point(){x=mpt._pt.x,y=mpt._pt.y,Z=mpt._ang,};points.Add(point);}ShapefileInsertPoints(shapefile_ang, points);SetLayerEsFont(shapefile_ang, _idx_shpfile_ang,"ES_Font", 14, fonts, 255, false);}else{if (_idx_shpfile_ang > 1){axMap.RemoveLayer(_idx_shpfile_ang);_idx_shpfile_ang= -1;}}menuItemAng.Tag= false;}#endregionif (tsChBox.Checked && _ppt.x != 0.0 && _ppt.x != 0.0){CenterAt(_ppt);}}//创建一个shapefileprivate Shapefile CreateShapefile(string shName, ShpfileType type, out intindex){Shapefile shapefile= newShapefile();shapefile.CreateNew(shName, ShpfileType.SHP_POINT);index= axMap.AddLayer(shapefile, true);returnshapefile;}//给Shapefile添加点private void ShapefileInsertPoints(Shapefile sh, List<MapWinGIS.Point>points){foreach (MapWinGIS.Point point inpoints){Shape shape= newShape();shape.Create(ShpfileType.SHP_POINT);int idxshape_ang_SX = 0;int pointidx = 0;shape.InsertPoint(point,refpointidx);sh.EditInsertShape(shape,refidxshape_ang_SX);}}//地图以某点为中心private voidCenterAt(MPoint _ppt){MapWinGIS.Extents myExtents=(Extents)axMap.Extents;MPoint center= newMPoint{x= (myExtents.xMax + myExtents.xMin) / 2,y= (myExtents.yMax + myExtents.yMin) / 2};double _x = center.x -_ppt.x;double _y = center.y -_ppt.y;double minX = myExtents.xMin -_x;double maxX = myExtents.xMax -_x;double minY = myExtents.yMin -_y;double maxY = myExtents.yMax -_y;myExtents.SetBounds(minX, minY,0, maxX, maxY, 0);axMap.Extents=myExtents;}//显示全局private voidShowFullPath(){if (_minx == 360.0){_minx= 53.0;}if (_maxx == 0.0){_maxx= 135.0;}if (_miny == 360.0){_miny= 18.0;}if (_maxy == 0){_maxy= 53.0;}MapWinGIS.Extents myExtents=(Extents)axMap.Extents;myExtents.SetBounds(_minx- 0.003, _miny - 0.003, 0, _maxx + 0.003, _maxy + 0.003, 0);axMap.Extents=myExtents;}//ToolStripMenuItem反选private void menuItem_Click(objectsender, EventArgs e){ToolStripMenuItem ts= sender asToolStripMenuItem;ts.Checked= !ts.Checked;ts.Tag= true;axMap_AfterTrackingLayerDraw();}//显示地图private void btnShowMap_ItemClick(objectsender, ItemClickEventArgs e){dockPanelMap.Show();gvDepots.OptionsView.ColumnAutoWidth= false;}//关闭地图private void btnClosMap_ItemClick(objectsender, ItemClickEventArgs e){dockPanelMap.Close();gvDepots.OptionsView.ColumnAutoWidth= true;}//定位private void tsBtnPointTo_Click(objectsender, EventArgs e){Pointo(tsTextPoint.Text.Trim());}//定位某个点private void Pointo(stringgpspt){if (0 ==gpspt.Length){return;}try{string delimStr = ",";char[] sp =delimStr.ToCharArray();List<string> ss = new List<string>();string[] ssn = null;ssn=gpspt.Split(sp);for (int i = 0; i < ssn.Length; i++){string s =ssn[i].Trim();if (s == "," || s == ":" || s.Length <= 0){continue;}ss.Add(s);}if (ss.Count != 2){XtraMessageBox.Show("请输入一对经纬度值!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}if (Convert.ToDouble(ss[0]) > 135.0 || Convert.ToDouble(ss[0]) < 74.0 || Convert.ToDouble(ss[1]) > 53.0 || Convert.ToDouble(ss[1]) < 18.0){XtraMessageBox.Show("请输入一个有效的中国范围内的经纬度值!", "经纬度超出范围", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;}double x = Convert.ToDouble(ss[0]);double y = Convert.ToDouble(ss[1]);MapWinGIS.Point pt= newMapWinGIS.Point();pt.x=x;pt.y=y;MapWinGIS.Extents myExtents=(Extents)axMap.Extents;myExtents.SetBounds(pt.x- 0.03, pt.y - 0.03, 0, pt.x + 0.03, pt.y + 0.03, 0);axMap.Extents=myExtents;ClearspecificDrawing(_dictdrawHandels, DrawHandels.PointToHandel,-1);_dictdrawHandels[DrawHandels.PointToHandel]=axMap.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList);axMap.AddDrawingLabel(_dictdrawHandels[DrawHandels.PointToHandel],"", 255, pt.x, pt.y, tkHJustification.hjNone);new System.Threading.Thread(newSystem.Threading.ThreadStart(ClearPoint)).Start();}catch(Exception ex){XtraMessageBox.Show(ex.Message);return;}}//清除定位点private voidClearPoint(){System.Threading.Thread.Sleep(3000);axMap.ClearDrawing(_dictdrawHandels[DrawHandels.PointToHandel]);}//站点选择改变private void gvDepots_FocusedRowChanged(objectsender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e){objectdatasouse;if ("FK_Depots" ==gc.DataMember){datasouse= (sender asDevExpress.XtraGrid.Views.BandedGrid.BandedGridView).DataSource;}else{datasouse= (sender asDevExpress.XtraGrid.Views.Grid.GridView).DataSource;}BindingSource bs=(BindingSource)datasouse;if (null !=bs){if (null !=bs.Current){DataRowView drv=(DataRowView)bs.Current;_ppt.x= Convert.ToDouble(drv.Row["经度"]) / 100000;_ppt.y= Convert.ToDouble(drv.Row["纬度"]) / 100000;SetAllMenuItmeTags();axMap_AfterTrackingLayerDraw();}}}//自动定位勾选private void tsChBox_CheckedChanged(objectsender, EventArgs e){if(tsChBox.Checked){SetAllMenuItmeTags();axMap_AfterTrackingLayerDraw();}}//鼠标滚珠滚动private void dockPanelMap_MouseWheel(objectsender, MouseEventArgs e){if (CurState.ChgGpsDirection ==_cur){if ("FK_Depots" ==gc.DataMember){if (!(menuItemAng.Checked)){return;}ChgDirection(gvDepots.DataSource, e,false);ShowInMap(false, true, true, false, false, false);}else if ("FK_Swerve" ==gc.DataMember){ChgDirection(gvSwerve.DataSource, e,true);ShowInMap(false, false, false, true, false, false);}axMap_AfterTrackingLayerDraw();}}//改变GPS方位private void ChgDirection(object dataSource, MouseEventArgs e, boolswerve){BindingSource bs=(BindingSource)dataSource;if (null !=bs){if (null !=bs.Current){DataRowView drv=(DataRowView)bs.Current;int value = (int)drv.Row["角度"];if (e.Delta > 0){value= value + 5 >= 360 ? 0 : value + 5;}else if (e.Delta < 0){value= value - 5 < 0 ? 359 : value - 5;}drv.Row["角度"] =value;menuItemAng.Tag= true;if(swerve){menuItemSwerve.Tag= true;}}}}//清除测距点private voidClearMeasurePoints(){int count =_measurePoints.Count;for (int i = 0; i < count; i++){_measurePoints.RemoveAt(0);}axMap.Refresh();}//导航条按钮点击private void gc_EmbeddedNavigator_ButtonClick(objectsender, NavigatorButtonClickEventArgs e){if (null !=e.Button.Tag){if (0 == (int)e.Button.Tag){axMap.MapCursor=tkCursor.crsrCross;if ("FK_Swerve" ==gc.DataMember){_cur=CurState.AddSwerve;}else if ("FK_Depots" ==gc.DataMember){_cur=CurState.SetDepotGps;}else if ("FK_Speed" ==gc.DataMember){AddSpeedControlCustomerBtnClick();axMap.CursorMode=tkCursorMode.cmNone;}else if ("FK_Broadcast" ==gc.DataMember){_cur=CurState.SetBroadcastGps;}}else if (1 == (int)e.Button.Tag){axMap.MapCursor=tkCursor.crsrCross;if ("FK_Swerve" ==gc.DataMember){_cur=CurState.SetSwerveGps;}else if ("FK_Speed" ==gc.DataMember){_cur=CurState.ExtendSpeedArea;}}else if (2 == (int)e.Button.Tag){axMap.CursorMode=tkCursorMode.cmNone;if ("FK_Swerve" ==gc.DataMember){DelSwerveControlCustomerBtnClick();}else if ("FK_Speed" ==gc.DataMember){DelSpeedControlCustomerBtnClick();}else if ("FK_Broadcast" ==gc.DataMember){DelBroadCastControlCustomerBtnClick();}}else if (3 == (int)e.Button.Tag){if ("FK_Depots" ==gc.DataMember){UpDepotControlCustomerBtnClick();}}else if (4 == (int)e.Button.Tag){if ("FK_Depots" ==gc.DataMember){DownDepotControlCumtomerBtnClick();}}else if (5 == (int)e.Button.Tag){gvDepots.OptionsView.ColumnAutoWidth= !gvDepots.OptionsView.ColumnAutoWidth;}}}//改变GPS方位private void ChgGVGps(objectdatasource, MPoint pt){BindingSource bs=(BindingSource)datasource;if (null ==bs.Current){return;}DataRowView drv=(DataRowView)bs.Current;drv.Row["经度"] = Convert.ToInt32(pt.x * 100000);drv.Row["纬度"] = Convert.ToInt32(pt.y * 100000);_ppt.x=pt.x;_ppt.y=pt.y;}//设置某图层的字体为ES_Fontprivate void SetLayerEsFont(Shapefile sp, int spIdx, string fontName, int fontsize, Dictionary<int, int> fonts, uint color, boolisBold){axMap.set_ShapeLayerPointType(spIdx, MapWinGIS.tkPointType.ptFontChar);axMap.set_UDPointFontCharFont(spIdx, fontName, fontsize, isBold,false, false);for (int i = 0x7B; i > 0x32; i--){int idx =axMap.set_UDPointFontCharListAdd(spIdx, i, color);fonts.Add((0x7B - i) * 5, idx);}int numShapes =sp.NumShapes;for (int i = 0; i < numShapes; i++){MapWinGIS.Shape sh=sp.get_Shape(i);MapWinGIS.Point point= sh.get_Point(0);int ang = ((int)point.Z / 5) * 5;int idx =fonts[ang];axMap.set_ShapePointType(spIdx, i, MapWinGIS.tkPointType.ptFontChar);axMap.set_ShapePointFontCharListID(spIdx, i, idx);}}//SetLayerEsFont重载private void SetLayerEsFont(Shapefile sp, int spIdx, string fontName, int fontsize, uint color, bool isBold, intval){axMap.set_ShapeLayerPointType(spIdx, MapWinGIS.tkPointType.ptFontChar);axMap.set_UDPointFontCharFont(spIdx, fontName, fontsize, isBold,false, false);int idx =axMap.set_UDPointFontCharListAdd(spIdx, val, color);int numShapes =sp.NumShapes;for (int i = 0; i < numShapes; i++){axMap.set_ShapePointType(spIdx, i, MapWinGIS.tkPointType.ptFontChar);axMap.set_ShapePointFontCharListID(spIdx, i, idx);}}//移除指定Layerprivate void Removelayer(ref intidx){if (idx > 1){axMap.RemoveLayer(idx);idx= -1;}}//ShapeFile添加标签private void ShapeFileAddLabel(int hndl, intfield, UInt32 col){MapWinGIS.Shapefile sf;MapWinGIS.Shape sh= newMapWinGIS.Shape();doublex, y;stringtext;sf=(MapWinGIS.Shapefile)axMap.get_GetObject(hndl);for (int i = 0; i < sf.NumShapes; i++){sh=sf.get_Shape(i);text=sf.get_CellValue(field, i).ToString();MapWinGIS.Extents ext=sf.QuickExtents(i);x= (ext.xMax + ext.xMin) / 2;y= (ext.yMax + ext.yMin) / 2;axMap.AddLabel(hndl, text, col, x, y, MapWinGIS.tkHJustification.hjCenter);}}//Depot添加一个标签private void AddDrawingLableDepot(int handle, string drawTxt, uint color, double x, doubley, tkHJustification fication){axMap.AddDrawingLabel(handle, drawTxt, color, x, y, fication);axMap.set_DrawingLabelsShadow(handle,true);axMap.set_DrawingLabelsShadowColor(handle, (uint)(ColorTranslator.ToOle(Color.FromArgb(0xEC, 0xF5, 0xFF))));axMap.set_DrawingLabelsOffset(handle,20);}//清除指定图层的绘制private void ClearspecificDrawing(Dictionary<DrawHandels, int> dict, DrawHandels handel, intval){axMap.ClearDrawing(dict[handel]);dict[handel]=val;}#endregion

转载于:https://www.cnblogs.com/kakaliush/archive/2013/03/25/2981507.html

MapWindow Gis 组件代码示例:相关推荐

  1. Web 组件代码示例

    在本文中,我提供了对 Web 组件是什么以及如何使用它们的基本理解.使用现实生活中的示例,我将展示 Web 组件如何帮助使应用程序更可预测和更易于维护.此外,我分享了有关如何通过将 HTML/CSS/ ...

  2. .net word转pdf的开源组件代码示例

    你可以使用 iTextSharp 这个开源的 .NET 组件来将 Word 文档转换为 PDF.这是一个示例代码: using System; using System.IO; using iText ...

  3. 【Android 内存优化】自定义组件长图组件 ( 长图滚动区域解码 | 手势识别 GestureDetector | 滑动计算类 Scroller | 代码示例 )

    文章目录 一.GestureDetector 创建与设置 二.GestureDetector 触摸事件传递 三.触摸滑动操作 四.惯性滑动操作 五.长图滑动组件代码示例 六.运行效果 七.源码及资源下 ...

  4. [微信小程序]组件化开发,以一个自定义模块框组件当做示例(附完整示例代码和效果图)

    微信小程序开发交流qq群   173683895    承接微信小程序开发.扫码加微信. 正文: 自定义组件我把它分为简单的三个步骤, 1.创建组件 --- 2.编写组件  ---   3.调用,使用 ...

  5. MapWindow GIS二次开发

    1.mapwindow是基于MapWinGIS组件开发的插件式开源GIS软件,其中数据处理又基于开源的gdal. 2. MapWinGIS简单介绍 MapWinGIS是一个开源的ActiveX组件,功 ...

  6. 当前主要使用的python版本_如何获取当前使用的Python版本信息?(代码示例)

    本篇文章主要给大家介绍如何获取当前Python版本,希望对需要的朋友有所帮助! 版本信息: 包含版本号的五个组件的元组:major,minor,micro,releaselevel和serial.除r ...

  7. 【Google Play】从 Android 应用中跳转到 Google Play 中 ( 跳转代码示例 | Google Play 页面的链接格式 | Google Play 免安装体验 )

    文章目录 前言 一.从 Android 应用跳转到 Google Play 代码 二.Google Play 页面的链接格式 三.Google Play 免安装体验 前言 本博客参考资料 链接到 Go ...

  8. 【IOC 控制反转】Android 事件依赖注入 ( 事件依赖注入代码示例 )

    文章目录 总结 一.Android 事件依赖注入示例 1.创建依赖注入库 2.声明注解 (1).修饰注解的注解 (2).修饰方法的注解 3.Activity 基类 4.动态代理类调用处理程序 5.依赖 ...

  9. 【IOC 控制反转】Android 视图依赖注入 ( 视图依赖注入步骤 | 视图依赖注入代码示例 )

    文章目录 总结 一.Android 视图依赖注入步骤 二.Android 布局依赖注入示例 1.创建依赖注入库 2.声明注解 3.Activity 基类 4.依赖注入工具类 5.客户端 Activit ...

最新文章

  1. 聊聊rocketmq的ProducerImpl
  2. python工作太难找-Python工作难找吗?
  3. opnet中的例子模型
  4. android 北斗定位代码_大牛三步教你解决,BAT资深APP性能优化系列-卡顿定位问题,收藏哦
  5. vue 导出Excel
  6. html搜索框 模糊搜索,前端js模糊搜索(模糊查询)
  7. 【转】java获取当前路径的几种方法
  8. 解决Eclipse 鼠标悬停提示框是黑色的
  9. 孩子们各显神通对付 iOS 12「屏幕使用时间」的限制
  10. 团队管理13--设定工作目标
  11. 云知声开源全栈语音交互方案
  12. python软件如何下载-Python怎么下载安装
  13. 游戏设计师:如何对待高考倒数100天
  14. Xftp安装或卸载报1605和1628问题
  15. 模仿百度首页的图片轮播
  16. Autojs获取GPS定位信息
  17. 现代A200(MoboDA3360)玩家宝典
  18. 简单的营销策略重复做,发挥到极致就是一心一意的去做
  19. 行政公益诉讼与民事公益诉讼可相互转化
  20. 深入理解pdf.js,PDFObject, iframe 三种方式来打开PDF文件的区别

热门文章

  1. 计算机网络特色的班旗,保定七中 | 319班 “一班一特色”班级文化展示
  2. 5 FPGA时序约束理论篇之两种时序例外
  3. windows操作系统未启用登录失败处理功能引发的威胁
  4. CentOS7 安装98五笔输入法
  5. 小米max android7 root,小米Max高配版 LineageOS14.1(原CM) 安卓7.1.2 Xposed框架+主题+号码归属地-刷机之家...
  6. 三维数字矿山综合管理平台
  7. 深度分析:Android4.3下MMS发送到附件为音频文件(音频为系统内置音频)的彩信给自己,添加音频-发送彩信-接收彩信-下载音频附件-预览-播放(三,接收彩信2,下载彩信)
  8. 车辆控制单元诊断系统
  9. Mike Flanagan的JNCIE认证经历
  10. 传智播客 React 入门 三天课程