From 6043404bd8aea8afee0f3e97b18558647cc23dbf Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期六, 23 九月 2023 17:42:55 +0800
Subject: [PATCH] 添加获取影像瓦片服务

---
 ExportMap/cs/WebUtils.cs               |   42 +++++++++++++++++++++
 ExportMap/Controllers/WebController.cs |   20 +++++++++-
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/ExportMap/Controllers/WebController.cs b/ExportMap/Controllers/WebController.cs
index a423dfa..23b76ca 100644
--- a/ExportMap/Controllers/WebController.cs
+++ b/ExportMap/Controllers/WebController.cs
@@ -52,7 +52,7 @@
 
         // http://localhost/ExportMap/terra/0/1/0.terrain?path=3d/terrain/dem/t
         [Route("terra/{z}/{x}/{y}.terrain")]
-        [AcceptVerbs("GET", "POST")]
+        [HttpGet]
         public HttpResponseMessage GetTerrain(int z, int x, int y, [FromUri]string path)
         {
             return WebUtils.GetTerrain(Request, path, z, x, y);
@@ -68,10 +68,26 @@
 
         // http://localhost/ExportMap/terra0/1/3/0.terrain?path=3d/terrain/dem/t
         [Route("terra0/{z}/{x}/{y}.terrain")]
-        [AcceptVerbs("GET", "POST")]
+        [HttpGet]
         public HttpResponseMessage GetTerrain0(int z, int x, int y, [FromUri]string path)
         {
             return WebUtils.GetTerrain0(Request, path, z, x, y);
         }
+
+        // http://localhost/ExportMap/tile/18/213517/107112.png?path=2d/tiles/0102
+        [Route("tile/{z}/{x}/{y}.png")]
+        [HttpGet]
+        public HttpResponseMessage GetTile(int z, int x, int y, [FromUri]string path)
+        {
+            return WebUtils.GetTile(Request, path, z, x, y);
+        }
+
+        // http://localhost/ExportMap/tile0/18/213517/107110.png?path=2d/tiles/0102
+        [Route("tile0/{z}/{x}/{y}.png")]
+        [HttpGet]
+        public HttpResponseMessage GetTile0(int z, int x, int y, [FromUri]string path)
+        {
+            return WebUtils.GetTile0(Request, path, z, x, y);
+        }
     }
 }
diff --git a/ExportMap/cs/WebUtils.cs b/ExportMap/cs/WebUtils.cs
index cd1d6ac..ed2a2b8 100644
--- a/ExportMap/cs/WebUtils.cs
+++ b/ExportMap/cs/WebUtils.cs
@@ -91,6 +91,46 @@
         }
 
         /// <summary>
+        /// 鑾峰彇褰卞儚鏂囦欢
+        /// </summary>
+        public static HttpResponseMessage GetTile(HttpRequestMessage Request, string path, int z, int x, int y)
+        {
+            string basePath = Path.Combine(LFData, path);
+            if (!Directory.Exists(basePath))
+            {
+                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "璺緞涓嶅瓨鍦紒"));
+            }
+
+            string file = basePath + "\\" + z + "\\" + x + "\\" + y + ".png";
+            if (!File.Exists(file))
+            {
+                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "鏂囦欢涓嶅瓨鍦紒"));
+            }
+
+            return DownloadFile(file, y + ".png");
+        }
+
+        /// <summary>
+        /// 鑾峰彇褰卞儚鏂囦欢锛屼笉瀛樺湪杩斿洖绌烘枃浠�
+        /// </summary>
+        public static HttpResponseMessage GetTile0(HttpRequestMessage Request, string path, int z, int x, int y)
+        {
+            string basePath = Path.Combine(LFData, path);
+            if (!Directory.Exists(basePath))
+            {
+                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "璺緞涓嶅瓨鍦紒"));
+            }
+
+            string file = basePath + "\\" + z + "\\" + x + "\\" + y + ".png";
+            if (!File.Exists(file))
+            {
+                return DownloadFile(Tools.BaseDir + "\\Sources\\empty.png", y + ".png");
+            }
+
+            return DownloadFile(file, y + ".png");
+        }
+
+        /// <summary>
         /// 涓嬭浇鏂囦欢
         /// </summary>
         public static HttpResponseMessage DownloadFile(string file, string fileName)
@@ -111,6 +151,7 @@
             return response;
         }
 
+        #region 鍙戦�佽姹�
         /// <summary>
         /// Get璇锋眰
         /// </summary>
@@ -165,5 +206,6 @@
 
             return result;
         }
+        #endregion
     }
 }

--
Gitblit v1.9.3