UPDATE: Add raster tiles

This commit is contained in:
2026-04-14 09:34:56 +07:00
parent 72efb480ac
commit 34c97e803a
8 changed files with 291 additions and 6 deletions

View File

@@ -0,0 +1,57 @@
package services
import (
"context"
"history-api/internal/repositories"
"github.com/gofiber/fiber/v3"
)
type RasterTileService interface {
GetMetadata(ctx context.Context) (map[string]string, error)
GetTile(ctx context.Context, z, x, y int) ([]byte, map[string]string, error)
}
type rasterTileService struct {
tileRepo repositories.RasterTileRepository
}
func NewRasterTileService(
TileRepo repositories.RasterTileRepository,
) RasterTileService {
return &rasterTileService{
tileRepo: TileRepo,
}
}
func (t *rasterTileService) GetMetadata(ctx context.Context) (map[string]string, error) {
metaData, err := t.tileRepo.GetMetadata(ctx)
if err != nil {
return nil, fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return metaData, nil
}
func (t *rasterTileService) GetTile(ctx context.Context, z, x, y int) ([]byte, map[string]string, error) {
contentType := make(map[string]string)
data, format, err := t.tileRepo.GetTile(ctx, z, x, y)
if err != nil {
return nil, contentType, fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
switch format {
case "png":
contentType["Content-Type"] = "image/png"
case "jpg", "jpeg":
contentType["Content-Type"] = "image/jpeg"
case "webp":
contentType["Content-Type"] = "image/webp"
default:
contentType["Content-Type"] = "application/octet-stream"
}
return data, contentType, nil
}

View File

@@ -40,12 +40,15 @@ func (t *tileService) GetTile(ctx context.Context, z, x, y int) ([]byte, map[str
if err != nil {
return nil, contentType, fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
contentType["Content-Type"] = "image/png"
if format == "jpg" {
contentType["Content-Type"] = "image/jpeg"
}
if format == "pbf" {
switch format {
case "pbf":
contentType["Content-Type"] = "application/x-protobuf"
case "png":
contentType["Content-Type"] = "image/png"
case "jpg", "jpeg":
contentType["Content-Type"] = "image/jpeg"
default:
contentType["Content-Type"] = "application/octet-stream"
}
if isPBF {