I am working on an app where I serve a map (Mapbox) to users and a part of this is calculating lines and polygons intersecting on the map. Currently, I am using Turf.js to do this calculation in JavaScript that is a part of the view. This means that every time the page loads, the calculation is redone. I would like to be able to do the calculation once on the server side and store it in a database. Then I would be able to send the precomputed data to the frontend to be rendered using Mapbox. Additionally, I would like to be able to recompute the data based on webhook events.
I have tried to look around, but I haven't been able to find much on how to do this. Is it really even possible?
Some alternatives I am thinking of:
- Is there some C# library that has similar capabilities of Turf.js?
- I guess I could send a variable to the view telling it whether or not to do the calculation, and then after, it could send the data back to an endpoint in my controller for inserting into the database. Think this would work but seems very clunky.
I have tried to use jsRuntime in the controller, but I was getting an error since I had not returned a view, so that was a bit of a dead end.
EDIT: Just though of this and I think it may be my solution. I assume I could host a javascript API (on Azure) that I call whenever I want to do the calculations. This would also work well with the webhooks since there is no client in that situation. I think I will go this route unless someone has something better. Leaving open to see if there are any other suggestions.