tile_proxy

package
v1.7.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

tile_cache.go

tile_proxy.go

safe_tile_processor.go

tile_utils.go

webtile_downloader.go

webtile_handler.go

Index

Constants

View Source
const (
	CoordWGS84 = "0" // WGS84
	CoordGCJ02 = "1" // 火星坐标系
	CoordBD09  = "2" // 百度坐标系
)

坐标系类型

View Source
const (
	MaxRetries   = 3                      // 最大重试次数
	RetryDelay   = 500 * time.Millisecond // 重试延迟
	RetryBackoff = 2                      // 退避倍数
)

重试配置

View Source
const (
	EarthRadius = 6378137.0
	OriginShift = math.Pi * EarthRadius // 20037508.342789244
)

Variables

This section is empty.

Functions

func CalculateRequiredTilesWithCrop

func CalculateRequiredTilesWithCrop(
	topLeftPixel, bottomRightPixel PixelCoord,
	tileSize int,
) (TileRange, CropInfo)

CalculateRequiredTilesWithCrop 计算需要请求的瓦片范围和精确裁剪信息

func GlobalPixelToTile

func GlobalPixelToTile(px, py float64, tileSize int) (tileX, tileY int, offsetX, offsetY float64)

GlobalPixelToTile 全局像素坐标转瓦片坐标

func SafeImageProcess added in v1.6.6

func SafeImageProcess(
	ctx context.Context,
	tiles []FetchedTile,
	tileRange TileRange,
	tileSize int,
	cropX, cropY int,
	outputFormat string,
) ([]byte, error)

SafeImageProcess 安全的图像处理

Types

type BoundingBox added in v1.7.4

type BoundingBox struct {
	MinLon float64
	MinLat float64
	MaxLon float64
	MaxLat float64
}

type CoordTransformFunc

type CoordTransformFunc func(lon, lat float64) (float64, float64)

CoordTransformFunc 坐标转换函数类型

type CropInfo

type CropInfo struct {
	// 在拼接画布上的裁剪起点
	CropX float64
	CropY float64
	// 裁剪宽高
	CropWidth  float64
	CropHeight float64
}

CalculateRequiredTilesAndCrop 计算需要请求的瓦片范围和裁剪信息

type DownloadRequest added in v1.7.4

type DownloadRequest struct {
	MapName   string          `json:"mapName" binding:"required"`
	ZoomLevel int             `json:"zoomLevel" binding:"required"`
	GeoJSON   json.RawMessage `json:"geoJson" binding:"required"`
}

DownloadRequest 下载请求参数

type DownloadSession added in v1.7.4

type DownloadSession struct {
	// contains filtered or unexported fields
}

DownloadSession 下载会话

type DownloadTask added in v1.7.4

type DownloadTask struct {
	ID              string     `json:"id"`
	MapName         string     `json:"mapName"`
	ZoomLevel       int        `json:"zoomLevel"`
	Status          string     `json:"status"` // pending, running, completed, failed
	Progress        float64    `json:"progress"`
	TotalTiles      int        `json:"totalTiles"`
	DownloadedTiles int        `json:"downloadedTiles"`
	FailedTiles     int        `json:"failedTiles"`
	Message         string     `json:"message"`
	OutputFile      string     `json:"outputFile"`
	CreatedAt       time.Time  `json:"createdAt"`
	StartedAt       *time.Time `json:"startedAt"`
	CompletedAt     *time.Time `json:"completedAt"`
}

DownloadTask 下载任务

type FetchedTile

type FetchedTile struct {
	Data   []byte
	X      int
	Y      int
	Format string
	Err    error
}

FetchedTile 获取的瓦片数据

type GeoJSONFeature added in v1.7.4

type GeoJSONFeature struct {
	Type       string          `json:"type"`
	Geometry   GeoJSONGeometry `json:"geometry"`
	Properties interface{}     `json:"properties"`
}

type GeoJSONFeatureCollection added in v1.7.4

type GeoJSONFeatureCollection struct {
	Type     string           `json:"type"`
	Features []GeoJSONFeature `json:"features"`
}

type GeoJSONGeometry added in v1.7.4

type GeoJSONGeometry struct {
	Type        string          `json:"type"`
	Coordinates json.RawMessage `json:"coordinates"`
}

type MemCacheItem

type MemCacheItem struct {
	Data       []byte
	AccessTime time.Time
}

MemCacheItem 内存缓存项(用于热点数据)

type PendingTask added in v1.7.4

type PendingTask struct {
	Task      *DownloadTask
	NetMap    *models.NetMap
	Tiles     []TileIndex
	BBox      *BoundingBox
	ZoomLevel int
	CreatedAt time.Time
}

PendingTask 待处理任务(等待WebSocket连接)

type PixelCoord

type PixelCoord struct {
	X float64
	Y float64
}

PixelCoord 像素坐标

func LonLatToGlobalPixel

func LonLatToGlobalPixel(lon, lat float64, z int, tileSize int) PixelCoord

LonLatToGlobalPixel 经纬度转全局像素坐标

type ProcessTileResult added in v1.6.6

type ProcessTileResult struct {
	Data []byte
	Err  error
}

ProcessTileResult 处理结果

type ProgressMessage added in v1.7.4

type ProgressMessage struct {
	Type     string      `json:"type"` // connected, progress, completed, error
	TaskID   string      `json:"taskId,omitempty"`
	Progress float64     `json:"progress,omitempty"`
	Message  string      `json:"message,omitempty"`
	Data     interface{} `json:"data,omitempty"`
}

ProgressMessage WebSocket进度消息

type SafeTileProcessor added in v1.6.6

type SafeTileProcessor struct {
	// contains filtered or unexported fields
}

SafeTileProcessor 安全的瓦片处理器

func NewSafeTileProcessor added in v1.6.6

func NewSafeTileProcessor(maxConcurrent int) *SafeTileProcessor

NewSafeTileProcessor 创建安全处理器

func (*SafeTileProcessor) ProcessWithRecover added in v1.6.6

func (s *SafeTileProcessor) ProcessWithRecover(
	ctx context.Context,
	processFn func() ([]byte, error),
) (result ProcessTileResult)

ProcessWithRecover 带恢复的处理

type TileBounds

type TileBounds struct {
	MinLon float64
	MinLat float64
	MaxLon float64
	MaxLat float64
}

TileBounds 瓦片边界(WGS84经纬度)

func GetTileBoundsWGS84

func GetTileBoundsWGS84(z, x, y int) TileBounds

GetTileBoundsWGS84 获取瓦片的WGS84边界

type TileCache

type TileCache struct {
	// contains filtered or unexported fields
}

TileCache SQLite瓦片缓存

func NewTileCache

func NewTileCache(maxMemItems int, ttl time.Duration) *TileCache

NewTileCache 创建瓦片缓存

func (*TileCache) Clear

func (c *TileCache) Clear()

Clear 清空缓存

func (*TileCache) Close

func (c *TileCache) Close() error

Close 关闭缓存

func (*TileCache) Delete

func (c *TileCache) Delete(key string)

Delete 删除缓存

func (*TileCache) Get

func (c *TileCache) Get(key string) ([]byte, bool)

Get 获取缓存

func (*TileCache) Set

func (c *TileCache) Set(key string, data []byte)

Set 设置缓存

func (*TileCache) SetWithType

func (c *TileCache) SetWithType(key string, data []byte, contentType string)

SetWithType 设置缓存(带内容类型)

func (*TileCache) Size

func (c *TileCache) Size() int

Size 获取缓存大小

func (*TileCache) Stats

func (c *TileCache) Stats() map[string]interface{}

Stats 获取缓存统计信息

type TileConfig

type TileConfig struct {
	TileSize int // 瓦片大小,如256或512
}

TileConfig 瓦片配置

func DefaultTileConfig

func DefaultTileConfig() *TileConfig

DefaultTileConfig 默认瓦片配置

type TileCoord

type TileCoord struct {
	Z int
	X int
	Y int
}

TileCoord 瓦片坐标

func LonLatToTileCoord

func LonLatToTileCoord(lon, lat float64, z int) TileCoord

LonLatToTileCoord 经纬度转瓦片坐标

type TileIndex added in v1.7.4

type TileIndex struct {
	Z int
	X int
	Y int
}

type TileProxyService

type TileProxyService struct {
	// contains filtered or unexported fields
}

TileProxyService 瓦片代理服务

func NewTileProxyService

func NewTileProxyService() *TileProxyService

NewTileProxyService 创建瓦片代理服务

func (*TileProxyService) Close

func (s *TileProxyService) Close() error

Close 关闭服务

func (*TileProxyService) HandleCacheStats

func (s *TileProxyService) HandleCacheStats(c *gin.Context)

HandleCacheStats 获取缓存统计

func (*TileProxyService) HandleClearCache

func (s *TileProxyService) HandleClearCache(c *gin.Context)

HandleClearCache 清空缓存

func (*TileProxyService) HandleTileRequest

func (s *TileProxyService) HandleTileRequest(c *gin.Context)

HandleTileRequest 处理瓦片请求

func (*TileProxyService) RegisterRoutes

func (s *TileProxyService) RegisterRoutes(r *gin.RouterGroup)

RegisterRoutes 注册路由

type TileRange

type TileRange struct {
	MinX int
	MaxX int
	MinY int
	MaxY int
}

TileRange 瓦片范围

type TileRequest

type TileRequest struct {
	MapID uint
	Z     int
	X     int
	Y     int
}

TileRequest 瓦片请求参数

type WebMercatorBounds added in v1.7.6

type WebMercatorBounds struct {
	MinX float64
	MinY float64
	MaxX float64
	MaxY float64
}

func GetTileBoundsWebMercator added in v1.7.6

func GetTileBoundsWebMercator(z, x, y int) WebMercatorBounds

GetTileBoundsWebMercator 获取瓦片的 Web Mercator 边界

type WebTileDownloader added in v1.7.4

type WebTileDownloader struct {
	// contains filtered or unexported fields
}

WebTileDownloader 网络瓦片下载器

func NewWebTileDownloader added in v1.7.4

func NewWebTileDownloader(outputDir string) *WebTileDownloader

NewWebTileDownloader 创建下载器

func (*WebTileDownloader) Close added in v1.7.4

func (d *WebTileDownloader) Close() error

func (*WebTileDownloader) ConnectWebSocket added in v1.7.4

func (d *WebTileDownloader) ConnectWebSocket(c *gin.Context)

ConnectWebSocket WebSocket连接处理

func (*WebTileDownloader) GetTask added in v1.7.4

func (d *WebTileDownloader) GetTask(taskID string) (*DownloadTask, bool)

GetTask 获取任务状态

func (*WebTileDownloader) InitDownload added in v1.7.4

func (d *WebTileDownloader) InitDownload(c *gin.Context)

InitDownload 初始化下载任务

type WebTileHandler added in v1.7.4

type WebTileHandler struct {
	// contains filtered or unexported fields
}

WebTileHandler 网络瓦片处理器

func NewWebTileHandler added in v1.7.4

func NewWebTileHandler(outputDir string) *WebTileHandler

NewWebTileHandler 创建处理器

func (*WebTileHandler) Close added in v1.7.4

func (h *WebTileHandler) Close() error

Close 关闭处理器

func (*WebTileHandler) ConnectWebSocket added in v1.7.4

func (h *WebTileHandler) ConnectWebSocket(c *gin.Context)

ConnectWebSocket WebSocket连接

func (*WebTileHandler) DownloadResult added in v1.7.4

func (h *WebTileHandler) DownloadResult(c *gin.Context)

DownloadResult 下载结果文件

func (*WebTileHandler) GetTaskStatus added in v1.7.4

func (h *WebTileHandler) GetTaskStatus(c *gin.Context)

GetTaskStatus 获取任务状态(轮询备用)

func (*WebTileHandler) InitDownload added in v1.7.4

func (h *WebTileHandler) InitDownload(c *gin.Context)

InitDownload 初始化下载任务

func (*WebTileHandler) RegisterRoutes added in v1.7.4

func (h *WebTileHandler) RegisterRoutes(r *gin.RouterGroup)

RegisterRoutes 注册路由

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL