[MiluGPS]为MiluGPS增加显示兴趣点的功能

兴趣点文本格式:


地标名称,类别(预留),经度,纬度

纯文本格式,一行一个兴趣点,保存于Map文件夹中,文件名为POI.txt。

现在文件名为固定形式,今后再增加可以多种类别的兴趣点,并由用户设置要加载哪些兴趣点


 1汕头市澄海区工商局,2,116.76421,23.45816
 2汕头市澄海区环卫局,2,116.76378,23.45271
 3汕头市澄海区劳动局,2,116.76305,23.45636
 4汕头市澄海区物资局,2,116.7628,23.45649
 5聚星新形象美发连锁沙龙,2,116.74684,23.44001
 6鹏发美容美发,2,116.76734,23.45379
 7亚洲人美容美发形象设计中心,2,116.76313,23.45705
 8银都,2,116.76254,23.4561
 9中国移动莱美服务厅,2,116.76395,23.45512
10中国网通中山南路营业厅,2,116.76326,23.45675
11中国铁通外砂营业厅,2,116.74881,23.44344
12吉成手机大卖场,2,116.76451,23.45898
13狮龙手机连锁店外砂大卖场,2,116.74941,23.43482

加载兴趣点:

 1        /// <summary>
 2        /// 兴趣点
 3        /// </summary>

 4        public List<POI> PoiPoint = new List<POI>();
 5
 6        /// <summary>
 7        /// 载入兴趣点
 8        /// </summary>

 9        public void LoadPOI() {
10
11            //判断 地图的路径是否存在.
12            if (_MapPath == "" || _MapPath == nullreturn;
13            //载入兴趣点数据
14            StreamReader srRut = new StreamReader(MapPath + "\\POI.txt", System.Text.Encoding.Default);
15            //StreamReader srRut = new StreamReader(MapPath + "\\Cities.poi", System.Text.Encoding.Default);
16
17            //清除原来的兴趣点列表
18            PoiPoint.Clear();
19
20            //测试性能
21            int t = Environment.TickCount;
22
23            //调取一行
24            string line = srRut.ReadLine();
25            string[] p;
26            Point pnt;
27
28            while (line != null{
29                //把读入的一行文本分离成数组
30                p = line.Split(',');
31                //分离后的数组长度至少大于3个
32                if (p.Length >= 4{
33                    try {
34                        //把经纬度转为坐标点
35                        pnt = ConvertLatLonToXY(p[3], p[2]);
36                        //如果坐标点在当前的地图范围内,贴添加到兴趣点列表中
37                        if(pnt.X>0 && pnt.Y>0 && pnt.X<map.RefPoint2.x&&pnt.Y<map.RefPoint2.y){
38                            PoiPoint.Add(new POI(p[0], Convert.ToInt32(p[1]),pnt));
39                        }

40                    }
 catch {
41                    }

42                }

43                line = srRut.ReadLine();
44            }

45            srRut.Close();
46
47            System.Diagnostics.Debug.WriteLine("Load POI TickCounts:" + (Environment.TickCount - t));
48        }

显示兴趣点:

利用GDI+的DrawString输出兴趣点。
遍厉兴趣点,判断兴趣点是否在当前的缓存地图上,如果是,判断当前的文本输范围是否与"已存在的文本范围"重叠,不重叠的话,刚输出兴趣点的文本。并把当前的文本范围添加到"已存在的文本范围"列表中。

 

 1        /// <summary>
 2        /// 画兴趣点
 3        /// </summary>
 4        /// <param name="g"></param>

 5        public void DrawPOI(Graphics g) {
 6
 7            if (PoiPoint.Count > 0{
 8
 9                Font font = new Font("Nina", 12F, FontStyle.Regular);
10                SolidBrush br = new SolidBrush(Color.Red);
11                int px = 0;
12                int py = 0;
13                int bmpWidth = bmp.Width;
14                int bmpHeight = bmp.Height;
15                int t= Environment.TickCount;
16
17
18                List<Rectangle> rects = new List<Rectangle>();
19                Rectangle rect = new Rectangle();
20                bool isIntersect=false;
21
22                foreach (POI p in PoiPoint) {
23
24                        px = p.Longitude - MapCol * ImageTileWidth;
25                        py = p.Latitude - MapRow * ImageTileWidth - 4;
26                        if (px < 0 || py < 0 || px > bmpWidth || py > bmpHeight) {
27                            //上面的条件落在缓存图片之外
28                        }
 else {
29
30                            //测试文字区域
31                            rect.Size = g.MeasureString(p.Name, font).ToSize();
32                            rect.X = px;
33                            rect.Y = py;
34                            isIntersect = false;
35                            //判断是否与已有的文字区域相交
36                            foreach (Rectangle r in rects) {
37                                if (rect.IntersectsWith(r)) {
38                                    isIntersect = true;
39                                    break;
40                                }
                            
41                            }

42
43                            //如果不相交,输出文字,并把该方框添加到方框列表中
44                            if (!isIntersect) {
45                                g.DrawString(p.Name, font, br, px, py);
46                                rects.Add(rect);                                
47                            }

48                            
49                        }
               
50
51                }

52
53                rects.Clear();
54                
55                System.Diagnostics.Debug.WriteLine("Draw POI TickCounts:" + (Environment.TickCount - t));
56
57            }

58        }

59
posted @ 2008-03-24 02:07  一支鱼刺  阅读(909)  评论(0编辑  收藏  举报