简体   繁体   English

使用 C# 调用外部 JS 库函数

[英]Calling an external JS library function with C#

I am trying to load an external javascript file ( http://turfjs.org/ a geospatial library I want to use within C#) and call a function (in my example turf.distance) I am using the code below using Jint but I got an exception Can you help me?我正在尝试加载一个外部 javascript 文件( http://turfjs.org/我想在 C# 中使用的地理空间库)并调用一个函数(在我的示例 turf.distance 中)我使用下面的代码使用 Jint,但我有一个例外你能帮帮我吗? Thank you谢谢

String path = "turf.min.js";
String jsContent=File.ReadAllText(path);
try
{
    var script = new Engine()
    .Execute(jsContent)
    .GetValue("turf.distance");
    var result = script.Invoke(43.625, 3.61815, 43.6267, 3.60394);
}
catch (Exception exception)
{
    // got an "Instance Error" (see image for details)
}

在此处输入图片说明

API 创建者已在 github ( https://github.com/Turfjs/turf/ ) 上给出了答案,他非常高效且可用于解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM