管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2023-09-07 52cb8e9d1363585733dbe9c0855b64e9877d3261
添加出图接口~
已添加3个文件
已修改3个文件
226 ■■■■■ 文件已修改
MoonExp/App_Start/WebApiConfig.cs 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/Controllers/ExportController.cs 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/MoonExp.csproj 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/Web.config 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/cs/NoBufferPolicySelector.cs 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/export.html 101 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/App_Start/WebApiConfig.cs
@@ -1,7 +1,10 @@
using System;
using MoonExp.cs;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Hosting;
namespace MoonExp
{
@@ -9,16 +12,35 @@
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Web API routes
            config.MapHttpAttributeRoutes();
            //config.Routes.MapHttpRoute(
            //    name: "TerraApi",
            //    routeTemplate: "{controller}/3d/terrain",
            //    defaults: new { controller = "Terra" }
            //);
            // {controller}/{id}
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                routeTemplate: "{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            // æ³¨å†Œæ‰©å±•主机缓存Policy
            GlobalConfiguration.Configuration.Services.Replace(typeof(IHostBufferPolicySelector), new NoBufferPolicySelector());
            // å±è”½è¿”回XML格式
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            // è§£å†³webapi在 multipart/form-data æ— æ³•映射实体类,HttpContext.Request.Files.Count
            //GlobalConfiguration.Configuration.Formatters.Add(new FormMultipartEncodedMediaTypeFormatter());
            // ä¿®æ”¹æ—¥æœŸæ ¼å¼
            IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
            timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(timeConverter);
        }
    }
}
MoonExp/Controllers/ExportController.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,54 @@
using MoonExp.cs;
using MoonExp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace MoonExp.Controllers
{
    public class ExportController : ApiController
    {
        [HttpGet]
        public string Test()
        {
            return DateTime.Now.ToString("yyyyy-MM-dd HH:mm:ss");
        }
        [HttpPost]
        public ResponseMsg<string> Start([FromBody]ExportArgs args)
        {
            try
            {
                if (args == null ||
                    string.IsNullOrWhiteSpace(args.layers) ||
                    string.IsNullOrWhiteSpace(args.token) ||
                    (args.xmin == 0 && args.ymin == 0 && args.xmax == 0 && args.ymax == 0))
                {
                    return ResponseMsg<string>.fail("参数不完整");
                }
                if (!ExportUtil.VerifyToken(args.token))
                {
                    return ResponseMsg<string>.fail("令牌无效");
                }
                string err = null;
                string imgPath = ExportUtil.Generate(args, ref err);
                if (string.IsNullOrEmpty(imgPath))
                {
                    return ResponseMsg<string>.fail(null == err ? "生成失败" : err);
                }
                return ResponseMsg<string>.success("成功", imgPath);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return ResponseMsg<string>.fail(ex.Message);
            }
        }
    }
}
MoonExp/MoonExp.csproj
@@ -14,7 +14,7 @@
    <RootNamespace>MoonExp</RootNamespace>
    <AssemblyName>MoonExp</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <UseIISExpress>true</UseIISExpress>
    <UseIISExpress>false</UseIISExpress>
    <IISExpressSSLPort />
    <IISExpressAnonymousAuthentication />
    <IISExpressWindowsAuthentication />
@@ -81,13 +81,16 @@
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Content Include="export.html" />
    <Content Include="Global.asax" />
    <Content Include="Web.config" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="App_Start\WebApiConfig.cs" />
    <Compile Include="Controllers\ExportController.cs" />
    <Compile Include="cs\ExportUtil.cs" />
    <Compile Include="cs\LogOut.cs" />
    <Compile Include="cs\NoBufferPolicySelector.cs" />
    <Compile Include="cs\PostgreHelper.cs" />
    <Compile Include="Global.asax.cs">
      <DependentUpon>Global.asax</DependentUpon>
@@ -104,7 +107,6 @@
  </ItemGroup>
  <ItemGroup>
    <Folder Include="App_Data\" />
    <Folder Include="Controllers\" />
  </ItemGroup>
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
@@ -119,9 +121,9 @@
        <WebProjectProperties>
          <UseIIS>True</UseIIS>
          <AutoAssignPort>True</AutoAssignPort>
          <DevelopmentServerPort>0</DevelopmentServerPort>
          <DevelopmentServerPort>1062</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          <IISUrl>http://localhost:1380/</IISUrl>
          <IISUrl>http://localhost/MoonExp</IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>False</UseCustomServer>
          <CustomServerUrl>
MoonExp/Web.config
@@ -10,7 +10,9 @@
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <!-- maxRequestLength是上传文件时最大size(单位是KB,默认值是4096kb),executionTimeout是请求session(单位是秒,默认值是110s) -->
    <httpRuntime maxRequestLength="2147483647" executionTimeout="8640000"/>
    <pages controlRenderingCompatibilityVersion="4.0"/>
  </system.web>
  <system.webServer>
    <security>
MoonExp/cs/NoBufferPolicySelector.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web;
using System.Web.Http.WebHost;
namespace MoonExp.cs
{
    public class NoBufferPolicySelector : WebHostBufferPolicySelector
    {
        public override bool UseBufferedInputStream(object hostContext)
        {
            var context = hostContext as HttpContextBase;
            if (context != null)
            {
                if (context.Request.HttpMethod == HttpMethod.Post.ToString() && context.Request.ContentLength > 102400)
                {
                    return false;
                }
            }
            return true;
        }
    }
}
MoonExp/export.html
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,101 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>MoonExp</title>
  <meta http-equiv="Expires" content="0" />
  <meta http-equiv="Cache" content="no-cache" />
  <meta http-equiv="Pragma" content="no-cache" />
  <meta http-equiv="Cache-control" content="no-cache" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script src="js/jquery.1.12.4.js"></script>
  <script>
    var token = "384d7382-ea48-400b-bc92-58cb2b28bcbc";
    $(function () {
      $("#token").html(token);
    });
    // Ajax
    function ajax(url, type, data, dataType, contentType, fn) {
      $.ajax({
        url: url,
        type: type,
        data: data,
        dataType: dataType || "json", // html、json、jsonp、script、text
        contentType: contentType || "application/json", // "application/x-www-form-urlencoded"
        success: function (data) {
          fn(data);
        },
        error: function (e) {
          console.error(e);
          fn();
        }
      });
    }
    // å‡ºå›¾-1
    function exportMap1() {
      var page = $("#selectPage").find("option:selected").text();
      var data = {
        token: token,
        title: "管道基础大数据平台(DW1-01)",
        pageSize: page,
        province: "河北省",
        scale: "1:5万",
        resolution: "5ç±³",
        date: "2022.11.09",
        layers: "m_hydraulic_protection,m_marker,m_pipeline,m_sitepoint,m_valvehousepoint,m_crossing,高德矢量",
        rotation: 0,
        xmin: 103.394023,
        ymin: 30.690466,
        ymax: 37.871048,
        xmax: 112.534648
      };
      ajax("Export/Start", "POST", JSON.stringify(data), null, null, function (rs) {
        alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
        console.log(rs);
      });
    }
    // å‡ºå›¾-2
    function exportMap2() {
      var page = $("#selectPage").find("option:selected").text();
      var data = {
        token: token,
        title: "管道基础大数据平台(DW1-02)",
        pageSize: page,
        province: "山东省",
        scale: "1:1万",
        resolution: "2ç±³",
        date: "2022.11.10",
        layers: "bs_project,th_strategic_channel,m_hydraulic_protection,m_marker,m_pipeline,m_sitepoint,m_valvehousepoint,m_crossing,高德影像",
        rotation: 0,
        xmin: 103.394023,
        ymin: 30.690466,
        ymax: 37.871048,
        xmax: 112.534648
      };
      ajax("Export/Start", "POST", JSON.stringify(data), null, null, function (rs) {
        alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
        console.log(rs);
      });
    }
  </script>
</head>
<body>
  <h2>Toekn:<span id="token" style="font-size: 14px;"></span></h2>
  <select id="selectPage">
    <option>A0</option>
    <option>A1</option>
    <option>A2</option>
    <option>A3</option>
    <option selected="selected">A4</option>
  </select>
  <input type="button" value="出图-1" onclick="exportMap1()" />
  <input type="button" value="出图-2" onclick="exportMap2()" />
  <br /><br />
</body>
</html>