From 38ff6f2303068518460d6ce4486bda33daa3d3eb Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 27 六月 2023 12:31:44 +0800
Subject: [PATCH] 添加TB模板文件处理过程

---
 ExportMap/TerraBuilder/template.js |   46 +++++++++++++++
 ExportMap/cs/TBUtils.cs            |   88 ++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+), 2 deletions(-)

diff --git a/ExportMap/TerraBuilder/template.js b/ExportMap/TerraBuilder/template.js
new file mode 100644
index 0000000..3d02125
--- /dev/null
+++ b/ExportMap/TerraBuilder/template.js
@@ -0,0 +1,46 @@
+try {
+    // type: 0-Clip, 1-Fill, 2-NullValue
+    var project = TerraBuilder.OpenProject("{tbp}");
+    var shp = "{shp}";
+
+    var imgLayer = project.Layers.InsertLayer("{img}", "imagery");
+    if (null != imgLayer) {
+        imgLayer.ImageryPyramidFormat = 0;
+
+        //var poly1 = VBArray(project.Polygons.ImportPolygons(shp)).toArray()[0];
+        //poly1.AttachToLayer(imgLayer);
+        //poly1.type = 2;
+
+        var poly2 = VBArray(project.Polygons.ImportPolygons(shp)).toArray()[0];
+        poly2.AttachToLayer(imgLayer);
+        poly2.type = 0;
+    }
+
+    var eleLayer = project.Layers.InsertLayer("{dem}", "Elevation");
+    if (null != eleLayer) {
+        eleLayer.ElevationPyramidFormat = 0;
+
+        //var poly1 = VBArray(project.Polygons.ImportPolygons(shp)).toArray()[0];
+        //poly1.AttachToLayer(eleLayer);
+        //poly1.type = 1;
+        //poly1.ElevationFillBehavior = 1;
+
+        //var poly2 = VBArray(project.Polygons.ImportPolygons(shp)).toArray()[0];
+        //poly2.AttachToLayer(eleLayer);
+        //poly2.type = 2;
+
+        var poly3 = VBArray(project.Polygons.ImportPolygons(shp)).toArray()[0];
+        poly3.AttachToLayer(eleLayer);
+        poly3.type = 0;
+    }
+
+    project.CreateResolutionPyramids();
+    //project.Settings.MPTFileName = "D:\\LF\\data\\mpt\\0A.MPT";
+
+    //project.Save();
+    project.CreateMPT();
+
+    TerraBuilder.ExitWhenFinished();
+} catch (ex) {
+    alert(ex.message);
+}
diff --git a/ExportMap/cs/TBUtils.cs b/ExportMap/cs/TBUtils.cs
index ec2ac03..d32b9f9 100644
--- a/ExportMap/cs/TBUtils.cs
+++ b/ExportMap/cs/TBUtils.cs
@@ -1,5 +1,6 @@
 锘縰sing System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Web;
 
@@ -8,13 +9,96 @@
     public class TBUtils
     {
         /// <summary>
+        /// 鑾峰彇婧愮洰褰�
+        /// </summary>
+        public static string SourcesPath
+        {
+            get
+            {
+                return Path.Combine(Tools.BaseDir, "TerraBuilder");
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鏃堕棿瀹覆
+        /// </summary>
+        public static string GetTime
+        {
+            get
+            {
+                return DateTime.Now.ToString("yyyyMMddhhmmss");
+            }
+        }
+
+        /// <summary>
         /// 鍒涘缓MPT
         /// </summary>
         public static string CreateMpt(string path, ref string err)
         {
-            //
+            string tbp = null;
+            try
+            {
+                tbp = GetNewTbp();
 
-            return null;
+
+                return null;
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                err = ex.Message;
+                return null;
+            }
+            finally
+            {
+                if (tbp != null && File.Exists(tbp)) File.Delete(tbp);
+
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鏂癟bp鏂囦欢
+        /// </summary>
+        private static string GetNewTbp()
+        {
+            string tbp = Path.Combine(SourcesPath, "tb.tbp");
+            string newTbp = Path.Combine(SourcesPath, GetTime + ".tbp");
+
+            File.Copy(tbp, newTbp);
+
+            return newTbp;
+        }
+
+        /// <summary>
+        /// 鑾峰彇鏂癑S
+        /// </summary>
+        private static string GetNewJs(string tbp, string shp, string img, string dem)
+        {
+            string js = Path.Combine(SourcesPath, "template.js");
+            string str = File.ReadAllText(js);
+            str = str.Replace("{tbp}", tbp)
+                .Replace("{shp}", shp)
+                .Replace("{img}", img)
+                .Replace("{dem}", dem)
+                .Replace("\\", "\\\\");
+
+            string newJs = Path.Combine(SourcesPath, GetTime + ".js");
+            File.WriteAllText(newJs, str);
+
+            return newJs;
+        }
+
+        /// <summary>
+        /// 閲嶅惎TB绋嬪簭
+        /// </summary>
+        private static void ReloadTB()
+        {
+            List<string> list = new List<string>();
+            list.Add("taskkill /f /t /im TerraBuilder.exe");
+            list.Add("taskkill /f /t /im TBFuser.exe");
+            list.Add("start /d \"C:\\Program Files\\Skyline\\TerraBuilder Fuser\" TBFuser.exe");
+
+            Tools.ExecCmd(list, false);
         }
     }
 }

--
Gitblit v1.9.3