关于c# gmap控件编程问题

运动的彩虹 发布于 2016/06/10 19:41
阅读 311
收藏 0
C#

最近用gmap编写winform程序,遇到一个问题请教:即用2个按钮产生2个画线事件,但是后画的线会自动将之前的线的属性覆盖,请大家帮帮忙,源程序如下


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using GMap.NET;
using GMap.NET.WindowsForms;
using GMap.NET.MapProviders;
using GMap.NET.WindowsForms.Markers;
using GMap;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {  
      
       GMapOverlay layer_temp1 = new GMapOverlay("route_dt1"); //放置polygon的图层

       GMapRoute route_line1 = null; //正在画的polygon
   
       GMapOverlay layer_temp2 = new GMapOverlay("route_dt2"); //放置polygon的图层

       GMapRoute route_line2 = null; //正在画的polygon
  

        public Form1()
        {
            InitializeComponent();
                       
            mapControl1.Manager.Mode = AccessMode.CacheOnly;
         //   mapControl1.MapProvider = GMapProviders.GoogleChinaSatelliteMap; //google china 地图
          
            mapControl1.MapProvider = GMapProviders.EmptyProvider;
         
            mapControl1.MinZoom = 1;  //最小比例
            mapControl1.MaxZoom = 8; //最大比例
            mapControl1.Zoom = 4;     //当前比例
            mapControl1.ShowCenter = false; //不显示中心十字点
            mapControl1.DragButton = System.Windows.Forms.MouseButtons.Middle; //左键拖拽地图
            mapControl1.Position = new PointLatLng(41.0000, 123.0000); //地图中心位置
                          
        }
   
        private void button10_Click(object sender, EventArgs e)
        {         
            List<PointLatLng> points = new List<PointLatLng>();
            points.Add(new PointLatLng(41.969562, 123.585789));
            points.Add(new PointLatLng(41.966205, 124.588171));
            points.Add(new PointLatLng(41.968134, 125.589759));
            points.Add(new PointLatLng(46.968134, 127.589759));

            if (route_line1==null)
            {
              route_line1 = new GMapRoute(points, "My route");          //画线
              route_line1.Stroke.Width = 1;
              route_line1.Stroke.Color = Color.Green;
              points = null;
            }
        
            layer_temp1.Routes.Add(route_line1);//将道路加入图层
      
            route_line1 = null;

          mapControl1.Overlays.Add(layer_temp1);
       
        }
    
        private void button11_Click(object sender, EventArgs e)
        {
            List<PointLatLng> points = new List<PointLatLng>();
            points.Add(new PointLatLng(44.969562, 126.585789));
            points.Add(new PointLatLng(44.966205, 126.588171));
            points.Add(new PointLatLng(44.968134, 127.589759));
            points.Add(new PointLatLng(48.968134, 129.589759));

            if (route_line2 == null)
            {
                route_line2 = new GMapRoute(points, "My route");          //画线
                route_line2.Stroke.Width = 3;
                route_line2.Stroke.Color = Color.Red;
                points = null;
            }

            layer_temp2.Routes.Add(route_line2);//将道路加入图层

            route_line2 = null;
           mapControl1.Overlays.Add(layer_temp2);
         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            mapControl1.Zoom = mapControl1.Zoom +0.2;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            mapControl1.Zoom = mapControl1.Zoom - 0.2;
        }

     
    }
}

加载中
返回顶部
顶部