⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 This is a document about routing [a spatial analysis - network]
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MapService
{
    public partial class Form1 : Form
    {
        private MapService map = new MapService();

        public Form1()
        {
            InitializeComponent();
            LoadMap("test");
        }

        //void GeoCode(string address)
        //{
        //    try
        //    {

        //        int pos = address.IndexOf(',');
        //        int num = Int32.Parse(address.Substring(0, pos));
        //        string name = address.Substring(pos + 1).Trim();
        //        Node n = map.GeoCode(num, name);
        //        if (n != null)
        //            ssStatus.Text = "Geocode: " + n.Key;
        //        else
        //            ssStatus.Text = "No geocode";
        //    }
        //    catch (Exception e) { }

        //}

        void LoadMap(string filename)
        {
            map.Load(filename);
            ssSystem.Text = "CoordSys: " + map.CoordSys;
            ssNodes.Text = "Nodes: " + map.NodeCount;
            ssRouting.Text = "Press LeftMouse for START point";
        }

        void DrawMap()
        {
            map.Draw(pictureBox1.CreateGraphics(), pictureBox1.Width, pictureBox1.Height);
            ssZoom.Text = "Zoom: " + (int)map.Zoom;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            Node p=map.XY2LonLat(e.X, e.Y);
            ssLonLat.Text = "Lon,Lat: " + String.Format("{0:n6},{1:n6}",p.Lon,p.Lat);
        }
     
        bool isStart = false;
        Node start;
        Node end;
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isStart = !isStart;
                if (isStart)
                {
                    start = map.XY2LonLat(e.X, e.Y);
                    ssRouting.Text = "Start: " + start.Key +" - Press LeftMouse for END point";
                }
                else
                {
                    end = map.XY2LonLat(e.X, e.Y);
                    ssRouting.Text = "Start: " + start.Key + " - End: " + end.Key + " - Press LeftMouse for START point or RightMouse for ROUTING";
                }
                //map.SnapEdge(map.XY2LonLat(e.X, e.Y));
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (start != null && end != null)
                {
                    int len = map.GetShortestPath(start, end);
                    if (len > 0)
                        ssRouting.Text = "Start: " + start.Key + " - End: " + end.Key + " - Distance(m): "+len;
                    else
                        ssRouting.Text = "Start: " + start.Key + " - End: " + end.Key + " - No route";
                }

                ssRouting.Text += " - Press LeftMouse for START point";
            }
        }

       

        private void btnLoad_Click(object sender, EventArgs e)
        {
            DrawMap();
        }               
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -