管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2023-09-23 6de2aa3b55fb547ca4c28c5be0819d9a5ff8a96c
添加地形服务
已添加3个文件
已修改3个文件
已删除1个文件
300 ■■■■ 文件已修改
ExportMap/App_Start/WebApiConfig.cs 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/Controllers/TerraController.cs 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/Controllers/WebController.cs 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/ExportMap.csproj 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/Sources/empty.terrain 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/Web.config 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/cs/WebUtils.cs 169 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/App_Start/WebApiConfig.cs
@@ -1,4 +1,5 @@
using ExportMap.cs;
using ExportMap.Controllers;
using ExportMap.cs;
using MultipartDataMediaFormatter;
using Newtonsoft.Json.Converters;
using System;
@@ -37,7 +38,10 @@
            timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(timeConverter);
            // ServicePoint å¯¹è±¡å…è®¸çš„æœ€å¤§å¹¶å‘连接数。对于托管的应用程序,默认连接限制为 10,对于所有其他应用程序,默认连接限制为 2。
            //System.Net.ServicePointManager.DefaultConnectionLimit = 20; // 2
            //config.MessageHandlers.Add(new WebHandler());
        }
    }
}
ExportMap/Controllers/TerraController.cs
ÎļþÒÑɾ³ý
ExportMap/Controllers/WebController.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,69 @@
using ExportMap.cs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace ExportMap.Controllers
{
    //[RoutePrefix("Web")]
    public class WebController : ApiController
    {
        // http://localhost/ExportMap/web/dem/layer.json
        [Route("web/{path}/layer.json")]
        [HttpGet]
        public string GetLayerJsonTest(string path)
        {
            return path + "/layer.json";
        }
        // http://localhost/ExportMap/web/dem/3/1/2.terrain
        [Route("web/{path}/{z}/{x}/{y}.terrain")]
        [HttpGet]
        public string GetTerrainTest(string path, int z, int x, int y)
        {
            return path + "/" + z + "/" + x + "/" + y + ".terrain";
        }
        /*[Route("api/order/{id:int=3}/ordertype")]
        [HttpGet]
        public IHttpActionResult GetById(int id)
        {
            return Ok<string>("Success" + id);
        }
        [AcceptVerbs("GET", "POST")]
        public IHttpActionResult GetById(int id)
        {
            return Ok<string>("Success" + id);
        }*/
        // http://localhost/ExportMap/terra/layer.json?path=3d/terrain/dem/t
        [Route("terra/layer.json")]
        [HttpGet]
        public HttpResponseMessage GetLayerJson([FromUri]string path)
        {
            return WebUtils.GetLayerJson(Request, path);
        }
        // http://localhost/ExportMap/terra/0/1/0.terrain?path=3d/terrain/dem/t
        [Route("terra/{z}/{x}/{y}.terrain")]
        [AcceptVerbs("GET", "POST")]
        public HttpResponseMessage GetTerrain(int z, int x, int y, [FromUri]string path)
        {
            return WebUtils.GetTerrain(Request, path, z, x, y);
        }
        // http://localhost/ExportMap/terra0/1/3/0.terrain?path=3d/terrain/dem/t
        [Route("terra0/{z}/{x}/{y}.terrain")]
        [AcceptVerbs("GET", "POST")]
        public HttpResponseMessage GetTerrain0(int z, int x, int y, [FromUri]string path)
        {
            return WebUtils.GetTerrain0(Request, path, z, x, y);
        }
    }
}
ExportMap/ExportMap.csproj
@@ -120,6 +120,7 @@
    <Content Include="js\tumap.js" />
    <Content Include="js\turf.min.6.5.js" />
    <Content Include="lf.html" />
    <Content Include="Sources\empty.png" />
    <Content Include="Sources\Lengend.png" />
    <Content Include="Sources\logo.png" />
    <Content Include="Sources\merge.py" />
@@ -142,7 +143,7 @@
    <Compile Include="Controllers\FloatServerController.cs" />
    <Compile Include="Controllers\licenseEncryptionController.cs" />
    <Compile Include="Controllers\TBController.cs" />
    <Compile Include="Controllers\TerraController.cs" />
    <Compile Include="Controllers\WebController.cs" />
    <Compile Include="Controllers\UploadController.cs" />
    <Compile Include="cs\CacheUtils.cs" />
    <Compile Include="cs\CommonUtils.cs" />
@@ -159,6 +160,7 @@
    <Compile Include="cs\TerrainUtils.cs" />
    <Compile Include="cs\TerraUtils.cs" />
    <Compile Include="cs\Tools.cs" />
    <Compile Include="cs\WebUtils.cs" />
    <Compile Include="cs\XYZUtils.cs" />
    <Compile Include="db\ModelHandler.cs" />
    <Compile Include="db\PostgreHelper.cs" />
@@ -204,6 +206,7 @@
    </Content>
    <Content Include="Sources\xyz.qgz" />
    <Content Include="TerraBuilder\tb.tbp" />
    <Content Include="Sources\empty.terrain" />
  </ItemGroup>
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
ExportMap/Sources/empty.terrain
Binary files differ
ExportMap/Web.config
@@ -49,6 +49,7 @@
    <pages controlRenderingCompatibilityVersion="4.0"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <security>
      <requestFiltering>
        <!-- 1GB = 1073741824 -->
@@ -60,6 +61,7 @@
      <remove name="OPTIONSVerbHandler"/>
      <remove name="TRACEVerbHandler"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
      <!--<add name="HtmlFileHandler" path="*.json,*.terrain" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>-->
    </handlers>
    <staticContent>
      <remove fileExtension=".wsv"/>
@@ -82,8 +84,8 @@
      <mimeMap fileExtension=".bgltf" mimeType="model/gltf-binary"/>
      <remove fileExtension=".glb"/>
      <mimeMap fileExtension=".glb" mimeType="model/gltf-binary"/>
      <remove fileExtension=".json"/>
      <mimeMap fileExtension=".json" mimeType="application/json"/>
      <!--<remove fileExtension=".json"/>
      <mimeMap fileExtension=".json" mimeType="application/json"/>-->
      <remove fileExtension=".geojson"/>
      <mimeMap fileExtension=".geojson" mimeType="application/json"/>
      <remove fileExtension=".topojson"/>
@@ -100,8 +102,8 @@
      <mimeMap fileExtension=".kmz" mimeType="application/vnd.google-earth.kmz"/>
      <remove fileExtension=".svg"/>
      <mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
      <remove fileExtension=".terrain"/>
      <mimeMap fileExtension=".terrain" mimeType="application/vnd.quantized-mesh"/>
      <!--<remove fileExtension=".terrain"/>
      <mimeMap fileExtension=".terrain" mimeType="application/vnd.quantized-mesh"/>-->
      <remove fileExtension=".ktx"/>
      <mimeMap fileExtension=".ktx" mimeType="image/ktx"/>
      <remove fileExtension=".crn"/>
ExportMap/cs/WebUtils.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,169 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Web;
using System.Web.Http;
namespace ExportMap.cs
{
    public class WebUtils
    {
        #region LFData
        private static string _lfData;
        public static string LFData
        {
            get
            {
                if (string.IsNullOrEmpty(_lfData))
                {
                    _lfData = Tools.GetSetting("lfData");
                }
                return _lfData;
            }
        }
        #endregion
        /// <summary>
        /// èŽ·å–åœ°å½¢å›¾å±‚æ–‡ä»¶
        /// </summary>
        public static HttpResponseMessage GetLayerJson(HttpRequestMessage Request, string path)
        {
            string basePath = Path.Combine(LFData, path);
            if (!Directory.Exists(basePath))
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "路径不存在!"));
            }
            string file = basePath + "\\layer.json";
            if (!File.Exists(file))
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "文件不存在!"));
            }
            return DownloadFile(file, "layer.json");
        }
        /// <summary>
        /// èŽ·å–åœ°å½¢æ–‡ä»¶
        /// </summary>
        public static HttpResponseMessage GetTerrain(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 + ".terrain";
            if (!File.Exists(file))
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "文件不存在!"));
            }
            return DownloadFile(file, y + ".terrain");
        }
        /// <summary>
        /// èŽ·å–åœ°å½¢æ–‡ä»¶ï¼Œä¸å­˜åœ¨è¿”å›žç©ºæ–‡ä»¶
        /// </summary>
        public static HttpResponseMessage GetTerrain0(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 + ".terrain";
            if (!File.Exists(file))
            {
                return DownloadFile(Tools.BaseDir + "\\Sources\\empty.terrain", y + ".terrain");
            }
            return DownloadFile(file, y + ".terrain");
        }
        /// <summary>
        /// ä¸‹è½½æ–‡ä»¶
        /// </summary>
        public static HttpResponseMessage DownloadFile(string file, string fileName)
        {
            //string fileName = Path.GetFileName(file);
            //FileStream stream = new FileStream(file, FileMode.Open);
            FileStream stream = File.OpenRead(file);
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
            response.Content = new StreamContent(stream);
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentDisposition.FileName = HttpUtility.UrlEncode(fileName);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            //response.Content.Headers.Add("Cache-Control", "max-age=2592000"); // ç¼“å­˜1个月
            response.Content.Headers.Expires = DateTimeOffset.Now.AddMonths(1); // new DateTimeOffset(DateTime.Now.AddMonths(1));
            return response;
        }
        /// <summary>
        /// Get请求
        /// </summary>
        public static string GetData(string url)
        {
            /*WebClient wc = new WebClient();
            Byte[] pageData = wc.DownloadData(url);
            Encoding coding = Encoding.GetEncoding("UTF-8");
            string str = coding.GetString(pageData);
            return str;*/
            Uri uri = new Uri(url);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "GET";
            request.ContentType = "application/x-www-form-urlencoded";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string str = reader.ReadToEnd();
            reader.Close();
            return str;
        }
        /// <summary>
        /// Post请求
        /// string data = string.Format("token={0}&f=json&where={1}", Token, "");
        /// </summary>
        public static string PostData(string url, string data)
        {
            Uri uri = new Uri(url);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            if (data != null)
            {
                byte[] bytes = Encoding.UTF8.GetBytes(data);
                request.ContentLength = bytes.Length;
                Stream outstream = request.GetRequestStream();
                outstream.Write(bytes, 0, bytes.Length);
                outstream.Flush();
                outstream.Close();
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string result = reader.ReadToEnd();
            reader.Close();
            return result;
        }
    }
}