I’m writing an API controller in ASP.NET Core that returns a large set of point data from a postgres database. However, this causes performance issues on my client side app due to the volume of data it’s returning. I’m looking for a way to return this data as map vector tiles instead to improve the loading and rendering performance on the client side.
Here’s how I am currently fetching and returning data:
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace YourProject.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LocationsController : Controller
{
private readonly dbContext _context;
public LocationsController(dbContext context)
{
_context = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<LocationModel>>> GetLocationsAsync([FromQuery] string? id)
{
if (string.IsNullOrEmpty(id))
{
return BadRequest("ID is required.");
}
var locations = await _context.Markers
.Where(marker => marker.Id == id)
.Select(marker => new LocationModel
{
Id = marker.Id,
CoordinatesText = ConvertGeometryToText(marker.Geometry),
}).ToListAsync();
return locations;
}
private static string ConvertGeometryToText(Geometry geom)
{
if (geom is Point point)
{
return $"POINT({point.X} {point.Y})";
}
return string.Empty;
}
}
}
I haven’t found much documentation or examples on how to implement this. How can I transform this to map vector tiles instead?