1. 程式人生 > >利用WPF建立自己的3d gis軟體(非axhost方式)(十二)SDK中的導航系統

利用WPF建立自己的3d gis軟體(非axhost方式)(十二)SDK中的導航系統

先下載SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV0bPew 密碼:1te1

地圖資料包(sqlserver2008R2版本,也可以不下載):  https://pan.baidu.com/s/1PjcNamad7OVpCrsVJ7dwFQ 密碼:uw9r

下載 核心SDK升級包:https://pan.baidu.com/s/1Q3dlM-Va-RmlEYbnmi8Xuw 並覆蓋到SDK目錄中。裡面有也每一篇的例子程式碼

完整的視訊演示:http://v.youku.com/v_show/id_XMTU4MTI5NTE4NA==.html  再三強調一下,用網際網路的伺服器使用速度上會卡頓,建議最好的效果一定要下載sql資料庫,本地建服務。

下載完成以後,解壓出來,將30-1.exe 拖動到 把授權拖到我上面install.bat上完成授權安裝。。。

 

設定system.ini 如下內容
Server=122.112.229.220
user=GisTest
Password=chinamtouch.com

該資料庫中只提供 成都市火車南站附近的資料請注意,104.0648,30.61658

SDK中自帶了一套 導航系統,用的是比較詳細的導航資料,你們懂的,修正了一下在使用網際網路伺服器時候的一個BUG,請在使用這部分功能時務必下載上面地址中的核心更新包覆蓋。 截圖如下:

該導航圖為切片導航圖。年份嘛,你們懂的,另外導航系統為執行緒非同步工作。因需要資料庫支援,所以如果你是用的網際網路伺服器

導航演算法得到路徑的時間會有所增長,建議是把資料庫下載到本地才可以看到真實的導航演算法速度

  導航演算法在單獨的ShortRoad.dll中(可獨立使用,擔需要相關資料檔案。)導航演算法可根據權值進行微調,目前有高速優先和,最短路徑兩種。

ShortRoad.ShortPath.MyPareant = this.Dispatcher;  //因為導航演算法為非同步委託+多執行緒方式完成,需要一個非同步委託主物件(靜態)。

            ShortRoad.

ShortPath.chuslhi(); //初始化資料(靜態)

          MyShort = new ShortRoad.ShortPath();

//初始化導航類

            MyShort.OnShortPath += new ShortRoad.ShortPath.PathOver(ShortPath_OnShortPath);

//導航資料回撥事件

            MyShort.OnPro += new ShortRoad.ShortPath.ChuLiPro(ShortPath_OnPro);

//導航演算法資訊事件。

   MyShort.GetShortPath(BeginPoint.X, BeginPoint.Y, EndPoint.X, EndPoint.Y,false);

//獲取最短路徑:

引數起點經度,緯度,終點經度,緯度,是否啟用高速優先。

路徑回撥事件:

     void ShortPath_OnShortPath(System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<System.Drawing.PointF>> value,System.Windows.Point bx,System.Windows.Point ey)

        {            double Totolength = 0;

            Pareant.PlayPath.Add(new Point3D(BeginPoint.X, BeginPoint.Y, 0));

            foreach (string key in value.Keys)

            {

                Totolength += Convert.ToDouble(key.Split('#')[1].Split(',')[12]);

                foreach (System.Drawing.PointF y1 in value[key])

                {

                    Pareant.PlayPath.Add(new Point3D(y1.X, y1.Y, 0));

                }

            }

}

 

事件引數1:System.Collections.Generic.Dictionary<string,System.Collections.Generic.List<System.Drawing.PointF>>

存放有所有的路徑資料 KEY為路徑詳細資訊內容如下(Value中為經緯度資料):

"清江東路#464400 , 49559714 , 1 , 0302 , 130 , 3 , 2 , 1 ,  , 47106369 , 5880354 , 3 , 0.012 , 1 , 1 ,  , 0 , 1 , 0 , 510105 , 510105 , 1 ,  ,  , 5 ,  , 4 , 3 , 11110001110000000000000000000000 , 0 , 0 ,  ,  ,  , 600 ,  , 1 , 1 ,  , 清江東路"

該KEY描述了這條路的所有資訊。可參看下表:

 

欄位設定

取值範圍

註釋

含義

名稱

型別

1

圖幅號

MapID

Char(8)

 

 

 

2

號碼

ID

Char(13)

 

Link 號碼

 

3

種別程式碼數

Kind_num

Char(2)

1—4

種別個數

 

4

種別程式碼(M)

Kind

Char(23)

 

道路等級屬性,多個之間用"|"分隔

(1)

 

 

5

 

 

幅寬

 

 

Width

 

 

Char(3)

15

<=3.0m

 

 

(2)

30

(3.0m, 5.5m]

55

(5.5m, 13.0m]

130

>13m

 

 

 

6

 

 

 

通行方向

 

 

 

Direction

 

 

 

Char(1)

0

未調查:預設為雙方向都可以通行

 

1

雙向:雙方向可以通行

 

2

順方向:單向通行,通行方向為起點到終點

方向

 

3

逆方向:單向通行,通行方向為終點到起點

方向

 

 

 

7

 

 

收費設定

 

 

Toll

 

 

Char(1)

0

未調查

 

 

(3)

 

 

下面上程式碼,先要引用shortroad.dll

 ShortRoad.ShortPath.MyPareant = this.Dispatcher;  //因為導航演算法為非同步委託+多執行緒方式完成,需要一個非同步委託主物件(靜態)。
            ShortRoad.ShortPath.chuslhi(); //初始化資料(靜態)
            MyShort = new ShortRoad.ShortPath();
            //初始化導航類
            MyShort.OnShortPath += this.MyShort_OnShortPath;
            //導航資料回撥事件


            MyShort.OnPro += MyShort_OnPro;
            //導航演算法資訊事件。

 

  #region 導航系統
        System.Windows.Point FirstJW= new System.Windows.Point();
        System.Windows.Point secJW = new System.Windows.Point();
        private void Button_Click_15(object sender, RoutedEventArgs e)
        {
            gis3d.State = GisLib.WindowsMT.GisState.獲取經緯度;
            gis3d.GetJWEvent += Gis3d_GetJWEvent2;
                
        }

        private void Gis3d_GetJWEvent2(System.Windows.Media.Media3D.Point3D value)
        {
            gis3d.GetJWEvent -= Gis3d_GetJWEvent2;
            FirstJW = new System.Windows.Point(value.X, value.Y);
            gis3d.State = GisLib.WindowsMT.GisState.漫遊;
        }

        private void Button_Click_16(object sender, RoutedEventArgs e)
        {
            gis3d.State = GisLib.WindowsMT.GisState.獲取經緯度;
            gis3d.GetJWEvent += Gis3d_GetJWEvent3;
        }

        private void Gis3d_GetJWEvent3(System.Windows.Media.Media3D.Point3D value)
        {
            gis3d.GetJWEvent -= Gis3d_GetJWEvent2;
            secJW = new System.Windows.Point(value.X, value.Y);
            MyShort.GetShortPath(FirstJW.X, FirstJW.Y, secJW.X, secJW.Y, true);
            gis3d.State = GisLib.WindowsMT.GisState.漫遊;
        }

        private void MyShort_OnPro(string value)
        {
            FirstShort.Content = value;
        }

        private void MyShort_OnShortPath(Dictionary<string, List<PointF>> value, System.Windows.Point mbegin, System.Windows.Point mend)
        {
            if (value == null)
                return;
            if (value.Count == 0)
                return;



            List<Point3D> PlayPath = new List<Point3D>();

            double Totolength = 0;

            // Pareant.PlayPath.Add(new Point3D(BeginPoint.X, BeginPoint.Y, 0));
            foreach (string key in value.Keys)
            {
                if (key.Length > 12)
                {
                    if (key.Split('#').Length >= 2)
                        Totolength += Convert.ToDouble(key.Split('#')[1].Split(',')[12]);
                }

                foreach (System.Drawing.PointF y1 in value[key])
                {
                    PlayPath.Add(new Point3D(y1.X, y1.Y, 0));
                }

            }
            PlayPath.Add(new Point3D(secJW.X, secJW.Y, 0));
            Random t1 = new System.Random();

            System.Windows.Media.Color pp = new System.Windows.Media.Color();
           
                pp = Colors.Red;

            //呼叫SDK提供的畫路方法把路畫出來
            gis3d.RemoveShotPath("導航路徑");
            gis3d.DrawShortPath(PlayPath, "導航路徑", pp, true);



        }
        #endregion

 

 

 效果如下:再三強調資料庫配合,所以用網際網路伺服器的時候。在計算時會比較慢,擔因為使用的是執行緒模式,所以不影響主程序做其它事。SDK自帶的drashortpath方法支援自動抽稀,可以顯示很長的導航路線。

  ,

 

 

http://www.chinamtouch.com QQ:40140203  微信公眾號:m3dgis2001