(MapX)在地图上根据gps坐标绘制轨迹点与轨迹线

1.在地图上绘制船与船的轨迹线
文件:MapXCruiseOperate.cs
类:MapXOperate
方法: private void DrawShipSelf(Layer layer)
主题过程:
1.新建图元Feature和点Point
2.设置点的坐标与样式

View Code
Feature feature =  new FeatureClass();
            MapXLib.Point pt =  new PointClass();
            pt.Set(selfx, selfy); // 设置标记点的坐标
            StyleClass style =  new StyleClass();
            style.SymbolType = SymbolTypeConstants.miSymbolTypeTrueTypeFont;
            style.SymbolFont.Name =  " inpoint ";
            style.SymbolCharacter = ( short) 56;
            style.SymbolFont.Size =  24;
             if (_angle >=  360)
                _angle =  0;
            style.SymbolFontRotation = ( short)(_angle); // 设置标记点的朝向角度

            feature =  this._mapObject.FeatureFactory.CreateSymbol(pt, style); // 生成图元

3.设置图元的相关数据属性并添加到图层中

View Code
MapXLib.RowValues rv = layer.DataSets._Item( 1).get_RowValues( 0);
                    rv[ " Name "].Value = _selfshipname;
                    rv[ " FID "].Value = _selfdeviceid; //  +"_" + label;
                    feature.KeyValue = System.Web.HttpUtility.UrlEncode(_selfdeviceid);
                     if (shipOfSelf ==  null)
                        shipOfSelf = layer.AddFeature(feature, rv);
                     else
                        layer.UpdateFeature(shipOfSelf.FeatureKey, feature, rv);

 

4.绘制跟踪线
View Code
///   <summary>
        
///  画跟踪线
        
///   </summary>
        
///   <param name="color"> 线颜色 </param>
        
///   <param name="size"> 线宽度 </param>
        
///   <param name="linestyle"> 线样式 </param>
        
///   <param name="history_gps"> GPS数据集合 </param>
         private Feature DrawTraceLine( uint color,  int size,  int linestyle, GPS_MSG_GPSDATA_RESP[] history_gps)
        {
             if (history_gps.Length <=  1)
                 return  null;
            Points linePts =  new PointsClass(); // 标记点集合
             for ( int i =  0; i < history_gps.Length; i++) // 遍历gps数据集合
            {
                MapXLib.Point linePt =  new PointClass(); // 新建标记点
                linePt.Set(history_gps[i].Longitude, history_gps[i].Latitude); // 设置标记点的坐标
                linePts.Add(linePt, i +  1); // 将标记点添加到集合中
            }
            Style style =  new StyleClass();
            style.LineWidth = ( short)size;
            style.LineColor = color;
            style.LineStyle = (PenStyleConstants)linestyle; // 设置线的样式
            Feature lineObj =  this._mapObject.FeatureFactory.CreateLine(linePts, style); // 生成线的图元
            
// lineObj = this._mapObject.Layers.AnimationLayer.AddFeature(lineObj, Type.Missing);
             return lineObj;
        }
5.将跟踪线加入到图层中
View Code
                lineTarget = DrawTraceLine(( uint)ColorTranslator.ToWin32(PlugInHelper.Setting.TrackLineColor), PlugInHelper.Setting.TrackLineWidth,  59, selfHisData);
                layer.AddFeature(lineTarget, Type.Missing);

你可能感兴趣的:(map)