From 81f67d9cf9632cc35ec5026655623a7263b74182 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 29 二月 2024 16:49:01 +0800 Subject: [PATCH] 添加V8引擎的调用 --- Turf/Turf.csproj | 2 Turf/Models/Coordinate.cs | 27 +++++++++++++ Turf/Controllers/CallController.cs | 4 - Turf/Web.config | 4 ++ Turf/cs/Tools.cs | 49 ++++++++++++++++++------ 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/Turf/Controllers/CallController.cs b/Turf/Controllers/CallController.cs index aec0bfd..a18e23f 100644 --- a/Turf/Controllers/CallController.cs +++ b/Turf/Controllers/CallController.cs @@ -23,9 +23,7 @@ return 0; } - Tools tools = new Tools(); - - return tools.CalcArea(code); + return Tools.CalcArea(code); } } } diff --git a/Turf/Models/Coordinate.cs b/Turf/Models/Coordinate.cs new file mode 100644 index 0000000..afebcc1 --- /dev/null +++ b/Turf/Models/Coordinate.cs @@ -0,0 +1,27 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Turf.Models +{ + public class Coordinate + { + public Coordinate() { } + + public Coordinate(double x, double y) + { + this.x = x; + this.y = y; + } + + public double x { get; set; } + + public double y { get; set; } + + public override string ToString() + { + return x + "," + y; + } + } +} diff --git a/Turf/Turf.csproj b/Turf/Turf.csproj index df2fad7..11488ae 100644 --- a/Turf/Turf.csproj +++ b/Turf/Turf.csproj @@ -115,6 +115,7 @@ <Compile Include="Global.asax.cs"> <DependentUpon>Global.asax</DependentUpon> </Compile> + <Compile Include="Models\Coordinate.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> @@ -124,7 +125,6 @@ <Folder Include="App_Data\" /> <Folder Include="Content\" /> <Folder Include="Data\" /> - <Folder Include="Models\" /> <Folder Include="Views\" /> </ItemGroup> <ItemGroup> diff --git a/Turf/Web.config b/Turf/Web.config index e8d5dc9..482d4e7 100644 --- a/Turf/Web.config +++ b/Turf/Web.config @@ -1,6 +1,10 @@ 锘�<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> + <!-- PG杩炴帴 --> + <add key="pgConn" value="Server=127.0.0.1;Port=5433;Database=langfang;User Id=postgres;Password=postgres;"/> + <!--<add key="pgConn" value="Server=192.168.20.205;Port=5433;Database=langfang;User Id=postgres;Password=Postgres!_14_Lf;"/>--> + <!--<add key="pgConn" value="Server=103.85.165.99;Port=5433;Database=langfang;User Id=postgres;Password=Postgres!_14_Lf;"/>--> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> diff --git a/Turf/cs/Tools.cs b/Turf/cs/Tools.cs index 9f05439..5617c3b 100644 --- a/Turf/cs/Tools.cs +++ b/Turf/cs/Tools.cs @@ -1,10 +1,16 @@ 锘縰sing Microsoft.ClearScript; using Microsoft.ClearScript.V8; +using Npgsql; using System; using System.Collections.Generic; +using System.Data; +using System.Data.Common; using System.IO; using System.Linq; +using System.Text; using System.Web; +using Turf.Models; +using static Mono.Security.X509.X520; namespace Turf.cs { @@ -16,26 +22,46 @@ public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory; - private static string js; + private static PostgreHelper _dbHelper; - public string TurfJS + public static PostgreHelper DBHelper { get { - if (null == js) + if (null == _dbHelper) { - string jsFile = Path.Combine(BaseDir, "js\\turf.min.6.5.js"); - if (File.Exists(jsFile)) - { - js = File.ReadAllText(jsFile); - } + _dbHelper = new PostgreHelper(); } - return js; + return _dbHelper; } } - public double CalcArea(string code) + public static string selectCoordinatesByCodeSql = "select ST_X(geom) x, ST_Y(geom) y from bs.s_explorationpoint b where dirid like @code and geom is not null"; + + public static string selectCoordinates(string code) + { + DbParameter dp = new NpgsqlParameter("@code", code + "%"); + + DataTable dt = DBHelper.GetDataTable(selectCoordinatesByCodeSql, dp); + if (null == dt || 0 == dt.Rows.Count) return null; + + List<Coordinate> list = ModelHandler.FillModel<Coordinate>(dt); + if (null == list || 0 == list.Count) return null; + + StringBuilder sb = new StringBuilder(); + sb.Append("["); + foreach (Coordinate cs in list) + { + sb.Append(cs.ToString() + ","); + } + sb.Remove(sb.Length - 1, 1); + sb.Append(']'); + + return sb.ToString(); + } + + public static double CalcArea(string code) { try { @@ -48,8 +74,7 @@ V8Script script = engine.CompileDocument(jsFile); engine.Execute(script); - string cs = "[113.23063216099904,31.21983148200005,113.23061312499972,31.219450768000044,113.23060360699967,31.21910812599997,113.2305679149997,31.218752397000046,113.23055006899986,31.21841570199999,113.230526275,31.218007625000023,113.23050485999988,31.217670932000015,113.23047154600006,31.21738182700004]"; - + string cs = selectCoordinates(code); object obj = engine.Invoke("pointsToPolygon", cs); return null == obj ? 0 : Convert.ToDouble(obj); -- Gitblit v1.9.3