I am working on a C# project which requires some map task.
What I am doing is writing a html file in C# and display it with a webview-like component.
And this is awkward.
Somebody came up with a more reasonable way? This can be a general problem since there are so many Javascript API.
You would need to have a Javascript engine running within your C program in order to interpret and execute Javascript code. This can be done though it’s seldom without issue since a lot of Javascript code assumes the existence of a browser (e.g. calling
window.locationor methods that add DOM elements).This is definitely going to be more trouble than it’s worth for your particular case – as well as being orders of magnitude less efficient than just writing the algorithm in C#. You should be looking for a C# library that simplifies the creation of HTML, rather than trying to embed an interpreted, weakly-typed language.
(However it can be a valid approach for other situations where you have important business logic in Javascript, and need to replicate this in a performance-insensitive batch process. Or if you want to run automated tests on your JS code alongside C#/Java classes.)