1. 程式人生 > >利用WPF建立自己的3d gis軟體(非axhost方式)(十三)萬能的使用者層介面,(強大的WPF)

利用WPF建立自己的3d gis軟體(非axhost方式)(十三)萬能的使用者層介面,(強大的WPF)

先下載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中為了方便三方資料的接入,引入了一個使用者層介面。主要是完成三方資料的接入,含動態資料(如GPS),使用者可自行控制UI及UI的互動,可實現如滴滴打車的車輛控制,公安應用中的UI按屬性控制顯示,並且該使用者層的顯示是由核心部分直接呼叫,在需要顯示資料的呼叫下面的介面,這樣可防止因為使用者是從外部接入。而卡頓,影響使用者使用體驗。而UI的回收是由核心負責,不需要使用者干預,二次開發時使用者只用關心自己要承現的UI,及UI的互動:

     public interface UserGisData : INotifyPropertyChanged
    {


        NewGisBiao.Base.JunBiao.CenteType BiaoCenterType
        {
            get;  //這個UI物件的中心點型別
        }

        string LayName {
            get; //使用者層名稱
         
        }

     


        /// <summary>
        /// 標籤整體縮放
        /// </summary>
        double  MScal
        {
            get; //UI整體縮放參數
        }


        Dictionary <string, GisLib.DrawPointData> DrawObject
       {
           get;  //訪問當前已經存在UI物件
           set;
       }

        /// <summary>
        /// 是否顯示
        /// </summary>
       bool ISShow
       {
           get;  //隱藏和顯示該使用者層
           set;
       }

        /// <summary>
        /// 最小顯示層
        /// </summary>
       int MinZoom
       {
           get;  //該使用者層的最小顯示層
           set;
       }

        /// <summary>
        /// 最大顯示層
        /// </summary>
       int MaxZoom
       {
           get; //該使用者層的最大顯示層
           set;
       }




        /// <summary>
        /// 返回一個圖標表示這個層的圖示
        /// </summary>
        System.Windows.Media.Imaging.BitmapImage MICon
        {
            get;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="centerx">查詢中心點經度(如果沒有會傳入null) </param>
        /// <param name="centery">查詢中心點緯度(如果沒有會傳入null)</param>
        /// <param name="info">查詢的資訊(如果是全部會傳入*)</param>
        /// <param name="length">範圍(如果沒有會傳入null)</param>
        /// <returns></returns>
        Dictionary<SechData, Point> SechPro(double centerx, double centery, string info, double length);

        Dictionary<SechData, Point> SechForLine(List<Point> Line, string info, double length);
        Dictionary<SechData, Point> SechForRect(List<Point> Line, string info, double length);

        /// <summary>
        /// 畫使用者物體
        /// </summary>
        /// <param name="centerx"></param>
        /// <param name="centery"></param>
        /// <returns></returns>
        List<DrawPointData> DrawData(double centerx, double centery);


        void OnUserBiaoClick(DrawPointData va); //UI點選的事件,現已作廢,UI可自行響應所有互動事件



    }

 

List<DrawPointData> DrawData(double centerx, double centery); 為該介面的核心部分,傳入引數為當前地圖的中心 點經緯度,根據這個經緯度,二次開發使用者需要從 資料(如mysql或者其它三方資料中)查詢當前需要顯示範圍的 資料,並連通UI一起返回:例子如下:

 List<DrawPointData> UserGisData.DrawData(double centerx, double centery)
        {

            if (Con == null)
            {
                Con = new MySql.Data.MySqlClient.MySqlConnection(IniRead.IniReadWrite.GetMySqlDataConnstring());
                Con.Open();
            }

            int mmzoom = IniRead.IniReadWrite.MPareant.Zoom;
            int drawfanwei = 5;
            double bx, by, ex, ey;
            Int64 cx, cy;
            NewGisBiao.Help.MathHelp.MyConver(centerx, centery, out cx, out cy, (int)mmzoom - 1);
            NewGisBiao.Help.MathHelp.MyConver2(cx - drawfanwei, cy - drawfanwei, (int)mmzoom - 1, out bx, out by);
            NewGisBiao.Help.MathHelp.MyConver2(cx + drawfanwei, cy + drawfanwei, (int)mmzoom - 1, out ex, out ey);
            string t6 = " where (jingdu > " + bx.ToString() + " and jingdu<"
                               + ex.ToString() + " and weidu > "
                               + ey.ToString() + " and weidu < "
                               + by + ")";
            MySqlCommand cmd = Con.CreateCommand();
            cmd.CommandText = "select * from gw_shigu" + t6;
            MySqlDataReader read = cmd.ExecuteReader();

            try
            {


                if (read.HasRows)
                {
                    List<DrawPointData> y1 = new List<DrawPointData>();
                    while (read.Read())
                    {
                        if (MData.ContainsKey(read["number"].ToString() + "A") == false)
                        {

                            DrawPointData u1 = new DrawPointData();

                            u1.ISAutoAngle = true;
                            u1.ISAutoScal = true;
                            u1.MaxZoomScal = 15;


                            u1.ID = read["number"].ToString() + "A";
                            u1.MPoint = new Point(Convert.ToDouble(read["jingdu"].ToString()), Convert.ToDouble(read["weidu"].ToString()));
                            Image h1 = new Image();
                            u1.Hi = 0.05;
                            h1.Width = 45;
                            h1.Height = 70;
                            if (read["sgtype"].ToString().Trim() == "重傷")
                                h1.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\res\\重傷.png"));
                            if (read["sgtype"].ToString().Trim() == "輕傷")
                                h1.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\res\\輕傷.png"));
                            if (read["sgtype"].ToString().Trim() == "無傷")
                            {
                                BitmapImage u11 = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\res\\無傷.png"));
                                h1.Source = u11;
                                h1.Width = u11.Width;
                                h1.Height = u11.Height;
                            }
                            h1.Stretch = Stretch.Fill;


                            h1.Tag = read["number"].ToString() + ";" + u1.MPoint.X.ToString() + ";" + u1.MPoint.Y.ToString();
                            u1.UIObject = h1;
                            y1.Add(u1);
                        }
                    }
                    read.Close();
                  
                    return y1;
                }
                read.Close();
                return null;
            }
            catch
            {
                read.Close();
                return null;
            }




        }

上面的方法主要是從介面返回的中心點得到一 個範圍內的使用者資料,並根據使用者的屬性建立不同的UI,

這是根據車輛性制不同顯示的不同車輛圖示,也可以像下面這樣,顯示一些統計資料:

可以充分發揮WPF在UI上的優勢,做出漂亮的標籤

當UI顯示完成後還可以通過呼叫:

 /// <summary>
        /// 更新使用者層裡的UI物件
        /// </summary>
        /// <param name="Layes">使用者層名稱</param>
        /// <param name="ID">使用者層ID</param>
        /// <param name="NewPoint">新的經緯度</param>
        /// <param name="Angle">新的角度</param>
        /// <param name="NewUI">新的UI</param>
        /// <param name="Ami">是否動畫</param>
        /// <returns></returns>
        public bool UpdateUserObject(string Layes, string ID, Point NewPoint, double Angle, FrameworkElement NewUI, bool Ami = true)

 

介面對已經有的UI進行更新,可實現如滴滴打車一樣的車輛動態效果,該介面只對已經承現的UI有用。

 

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