简体   繁体   中英

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? 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/ ) 上给出了答案,他非常高效且可用于解决此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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