gongqiuhong 1 gadu atpakaļ
vecāks
revīzija
163581ae79

+ 41 - 14
XdCxRhDW.App/ExtensionsDev/MapControlEx.cs

@@ -841,13 +841,26 @@ public static class MapControlEx
     /// </summary>
     /// <param name="ctrl"></param>
     /// <param name="url">such as http://192.168.100.63:58089</param>
+    /// <param name="layerName"></param>
     /// <returns></returns>
     public static MapControl UseWMTS(this MapControl ctrl, string url,string layerName)
     {
+        //var provider = new HttpMapDataProvider();
+        //var tileSource = provider.TileSource as HttpTileSource;
+        //tileSource.HttpServerAddr = url;
+        //ctrl.GetImageLayer().DataProvider = provider;
+        var wmsIp = ConfigurationManager.AppSettings["WMSIP"].Trim();
+        if (string.IsNullOrEmpty(wmsIp))
+        {
+            throw new ArgumentNullException("请在配置文件中配置WMSIP值");
+        }
         var provider = new HttpMapDataProvider();
         var tileSource = provider.TileSource as HttpTileSource;
-        tileSource.HttpServerAddr = url;
+        tileSource.HttpServerAddr = wmsIp;
+        tileSource.layerName = layerName;
         ctrl.GetImageLayer().DataProvider = provider;
+        ctrl.MinZoomLevel = 3;
+        ctrl.MaxZoomLevel = 20;
         return ctrl;
     }
     /// <summary>
@@ -863,20 +876,34 @@ public static class MapControlEx
         {
             throw new ArgumentNullException(nameof(ctrl));
         }
-        //if (string.IsNullOrEmpty(wmsURI))
-        //{
-        //    throw new ArgumentException($"“{nameof(wmsURI)}”不能为 null 或空。", nameof(wmsURI));
-        //}
+        if (string.IsNullOrEmpty(url))
+        {
+            throw new ArgumentException($"“{nameof(url)}”不能为 null 或空。", nameof(url));
+        }
 
-        //if (layerName is null)
-        //{
-        //    throw new ArgumentNullException(nameof(layerName));
-        //}
-        //var wmsIp = ConfigurationManager.AppSettings["WMSIP"].Trim();
-        //if (string.IsNullOrEmpty(wmsIp))
-        //{
-        //    throw new ArgumentNullException("请在配置文件中配置WMSIP值");
-        //}
+        if (layerName is null)
+        {
+            throw new ArgumentNullException(nameof(layerName));
+        }
+        var wmsIp = ConfigurationManager.AppSettings["WMSIP"].Trim();
+        if (string.IsNullOrEmpty(wmsIp))
+        {
+            throw new ArgumentNullException("请在配置文件中配置WMSIP值");
+        }
+        var provider = new WmsDataProvider();//地图瓦片提供者
+        provider.ServerUri = $"http://{wmsIp}/tilecache/service/wms";
+        if (!string.IsNullOrWhiteSpace(layerName))
+            provider.ActiveLayerName = layerName;
+        provider.CustomParameters.Add("format", "image/JPEG");
+        // provider.CustomParameters.Add("srs", "EPSG:4326");
+        var cs = (GeoMapCoordinateSystem)ctrl.CoordinateSystem;
+        cs.Projection = new EPSG4326Projection();
+        provider.ResponseCapabilities += (sender, e) =>
+        {
+            if (string.IsNullOrWhiteSpace(layerName))
+                provider.ActiveLayerName = e.Layers[0].Name;
+        };
+        ctrl.GetImageLayer().DataProvider = provider;
         //if (wmsType == EnumWmsType.ZKXT)//中科星图
         //{
         //    var provider = new WmsDataProvider();//地图瓦片提供者

+ 16 - 12
XdCxRhDW.App/UserControl/CtrlSysSettings.Designer.cs

@@ -43,6 +43,7 @@ namespace XdCxRhDW.App.UserControl
             this.txtYDPZThreshold = new DevExpress.XtraEditors.ButtonEdit();
             this.txtLayer = new DevExpress.XtraEditors.TextEdit();
             this.txtWMSType = new DevExpress.XtraEditors.ImageComboBoxEdit();
+            this.txtUrl = new DevExpress.XtraEditors.TextEdit();
             this.Root = new DevExpress.XtraLayout.LayoutControlGroup();
             this.layoutControlItem3 = new DevExpress.XtraLayout.LayoutControlItem();
             this.layoutControlItem4 = new DevExpress.XtraLayout.LayoutControlItem();
@@ -53,7 +54,6 @@ namespace XdCxRhDW.App.UserControl
             this.emptySpaceItem1 = new DevExpress.XtraLayout.EmptySpaceItem();
             this.emptySpaceItem2 = new DevExpress.XtraLayout.EmptySpaceItem();
             this.itemMapSource = new DevExpress.XtraLayout.LayoutControlItem();
-            this.txtUrl = new DevExpress.XtraEditors.TextEdit();
             this.itemMapUrl = new DevExpress.XtraLayout.LayoutControlItem();
             ((System.ComponentModel.ISupportInitialize)(this.tablePanel1)).BeginInit();
             this.tablePanel1.SuspendLayout();
@@ -65,6 +65,7 @@ namespace XdCxRhDW.App.UserControl
             ((System.ComponentModel.ISupportInitialize)(this.txtYDPZThreshold.Properties)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.txtLayer.Properties)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.txtWMSType.Properties)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.txtUrl.Properties)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.Root)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem4)).BeginInit();
@@ -75,7 +76,6 @@ namespace XdCxRhDW.App.UserControl
             ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem2)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.itemMapSource)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.txtUrl.Properties)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.itemMapUrl)).BeginInit();
             this.SuspendLayout();
             // 
@@ -198,6 +198,16 @@ namespace XdCxRhDW.App.UserControl
             this.txtWMSType.StyleController = this.layoutControl1;
             this.txtWMSType.TabIndex = 7;
             this.txtWMSType.ToolTip = "支持瓦片数据和wms";
+            this.txtWMSType.SelectedIndexChanged += new System.EventHandler(this.txtWMSType_SelectedIndexChanged);
+            // 
+            // txtUrl
+            // 
+            this.txtUrl.Location = new System.Drawing.Point(12, 288);
+            this.txtUrl.Name = "txtUrl";
+            this.txtUrl.Properties.AutoHeight = false;
+            this.txtUrl.Size = new System.Drawing.Size(372, 22);
+            this.txtUrl.StyleController = this.layoutControl1;
+            this.txtUrl.TabIndex = 10;
             // 
             // Root
             // 
@@ -303,6 +313,7 @@ namespace XdCxRhDW.App.UserControl
             this.itemMapLayer.Text = "图层名称";
             this.itemMapLayer.TextLocation = DevExpress.Utils.Locations.Top;
             this.itemMapLayer.TextSize = new System.Drawing.Size(96, 14);
+            this.itemMapLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
             // 
             // emptySpaceItem1
             // 
@@ -333,15 +344,7 @@ namespace XdCxRhDW.App.UserControl
             this.itemMapSource.Text = "地图来源";
             this.itemMapSource.TextLocation = DevExpress.Utils.Locations.Top;
             this.itemMapSource.TextSize = new System.Drawing.Size(96, 14);
-            // 
-            // txtUrl
-            // 
-            this.txtUrl.Location = new System.Drawing.Point(12, 288);
-            this.txtUrl.Name = "txtUrl";
-            this.txtUrl.Properties.AutoHeight = false;
-            this.txtUrl.Size = new System.Drawing.Size(372, 22);
-            this.txtUrl.StyleController = this.layoutControl1;
-            this.txtUrl.TabIndex = 10;
+            this.itemMapSource.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
             // 
             // itemMapUrl
             // 
@@ -358,6 +361,7 @@ namespace XdCxRhDW.App.UserControl
             this.itemMapUrl.Text = "地图URL";
             this.itemMapUrl.TextLocation = DevExpress.Utils.Locations.Top;
             this.itemMapUrl.TextSize = new System.Drawing.Size(96, 14);
+            this.itemMapUrl.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
             // 
             // CtrlSysSettings
             // 
@@ -377,6 +381,7 @@ namespace XdCxRhDW.App.UserControl
             ((System.ComponentModel.ISupportInitialize)(this.txtYDPZThreshold.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.txtLayer.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.txtWMSType.Properties)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.txtUrl.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.Root)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem4)).EndInit();
@@ -387,7 +392,6 @@ namespace XdCxRhDW.App.UserControl
             ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem2)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.itemMapSource)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.txtUrl.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.itemMapUrl)).EndInit();
             this.ResumeLayout(false);
 

+ 71 - 12
XdCxRhDW.App/UserControl/CtrlSysSettings.cs

@@ -95,13 +95,32 @@ namespace XdCxRhDW.App.UserControl
                         //if (txtMapType.SelectedIndex == 0)
                         //{
                         //    resNull.WMSType = null;
-                        //    resNull.LayerName = null;
-                        //}
-                        //else
-                        //{
-                        //    resNull.WMSType = (EnumWmsType)txtWMSType.EditValue;
-                        //    resNull.LayerName = txtLayer.Text;
+                        //    resNull.ZKXT_Url = null;
+                        //    resNull.ZKXT_LayerName = null;
+                        //    resNull.SJZX_Url = null;
+                        //    resNull.SJZX_LayerName = null;
+                        //    resNull.LW_Url = null;
+                        //    resNull.LW_LayerName = null;
                         //}
+                        if (txtMapType.SelectedIndex != 0)
+                        {
+                            resNull.WMSType = (EnumWmsType)txtWMSType.EditValue;
+                            if (resNull.WMSType == EnumWmsType.ZKXT)
+                            {
+                                resNull.ZKXT_Url = txtUrl.Text;
+                                resNull.ZKXT_LayerName = txtLayer.Text;
+                            }
+                           else if (resNull.WMSType == EnumWmsType.SJZX)
+                            {
+                                resNull.SJZX_Url = txtUrl.Text;
+                                resNull.SJZX_LayerName = txtLayer.Text;
+                            }
+                            else if (resNull.WMSType == EnumWmsType.LW)
+                            {
+                                resNull.LW_Url = txtUrl.Text;
+                                resNull.LW_LayerName = txtLayer.Text;
+                            }
+                        }
 
                         db.SysSetings.Add(resNull);
                         needStartHttpSvr = true;
@@ -115,14 +134,28 @@ namespace XdCxRhDW.App.UserControl
                         res.MapType = txtMapType.SelectedIndex;
                         //if (txtMapType.SelectedIndex == 0)
                         //{
-                        //    res.WMSType = null;
+                        //    res.WMSType = EnumWmsType.LW;
                         //    res.LayerName = null;
                         //}
-                        //else
-                        //{
-                        //    res.WMSType = (EnumWmsType)txtWMSType.EditValue;
-                        //    res.LayerName = txtLayer.Text;
-                        //}
+                        if (txtMapType.SelectedIndex != 0)
+                        {
+                            res.WMSType = (EnumWmsType)txtWMSType.EditValue;
+                            if (res.WMSType == EnumWmsType.ZKXT)
+                            {
+                                res.ZKXT_Url = txtUrl.Text;
+                                res.ZKXT_LayerName = txtLayer.Text;
+                            }
+                            else if (res.WMSType == EnumWmsType.SJZX)
+                            {
+                                res.SJZX_Url = txtUrl.Text;
+                                res.SJZX_LayerName = txtLayer.Text;
+                            }
+                            else if (res.WMSType == EnumWmsType.LW)
+                            {
+                                res.LW_Url = txtUrl.Text;
+                                res.LW_LayerName = txtLayer.Text;
+                            }
+                        }
                     }
 
                     await db.SaveChangesAsync();
@@ -171,14 +204,40 @@ namespace XdCxRhDW.App.UserControl
             {
                 itemMapSource.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                 itemMapLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
+                itemMapUrl.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
             }
             else
             {
                 itemMapSource.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
                 itemMapSource.Text = "WMS地址";
                 itemMapLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
+                itemMapUrl.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
             }
             layoutControl1.BestFit();
         }
+
+        private async void txtWMSType_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            using (RHDWContext db = new RHDWContext())
+            {
+                var res = await db.SysSetings.FirstOrDefaultAsync();
+                if (res == null) return;
+                if ((EnumWmsType)txtWMSType.EditValue == EnumWmsType.ZKXT)
+                {
+                    txtUrl.Text = res.ZKXT_Url;
+                    txtLayer.Text = res.ZKXT_LayerName;
+                }
+                if ((EnumWmsType)txtWMSType.EditValue == EnumWmsType.SJZX)
+                {
+                    txtUrl.Text = res.SJZX_Url;
+                    txtLayer.Text = res.SJZX_LayerName;
+                }
+                if ((EnumWmsType)txtWMSType.EditValue == EnumWmsType.LW)
+                {
+                    txtUrl.Text = res.LW_Url;
+                    txtLayer.Text = res.LW_LayerName;
+                }
+            }
+        }
     }
 }