- Created backend structure with Go, including main application logic and API endpoints. - Added Docker support for both development and production environments. - Introduced frontend using Nuxt 3 with Tailwind CSS for styling. - Included configuration files for Docker and environment variables. - Established basic documentation for contributing, development, and deployment processes. - Set up .gitignore and .dockerignore files to manage ignored files in the repository.
74 lines
2.0 KiB
JavaScript
74 lines
2.0 KiB
JavaScript
import L, { Util, Browser } from 'leaflet'
|
|
|
|
export const SmartTileLayer = L.TileLayer.extend({
|
|
cache: {},
|
|
invalidTile: '',
|
|
map: 0,
|
|
|
|
getTileUrl(coords) {
|
|
if (!this._map) return this.invalidTile
|
|
let zoom
|
|
try {
|
|
zoom = this._getZoomForUrl()
|
|
} catch {
|
|
return this.invalidTile
|
|
}
|
|
return this.getTrueTileUrl(coords, zoom)
|
|
},
|
|
|
|
getTrueTileUrl(coords, zoom) {
|
|
const data = {
|
|
r: Browser.retina ? '@2x' : '',
|
|
s: this._getSubdomain(coords),
|
|
x: coords.x,
|
|
y: coords.y,
|
|
map: this.map,
|
|
z: zoom,
|
|
}
|
|
if (this._map && !this._map.options.crs.infinite) {
|
|
const invertedY = this._globalTileRange.max.y - coords.y
|
|
if (this.options.tms) {
|
|
data.y = invertedY
|
|
}
|
|
data['-y'] = invertedY
|
|
}
|
|
|
|
const cacheKey = `${data.map}:${data.x}:${data.y}:${data.z}`
|
|
data.cache = this.cache[cacheKey]
|
|
|
|
// Don't request tiles for invalid/unknown map (avoids 404 spam in console)
|
|
if (data.map === undefined || data.map === null || data.map < 1) {
|
|
return this.invalidTile
|
|
}
|
|
// Only use placeholder when server explicitly marks tile as invalid (-1)
|
|
if (data.cache === -1) {
|
|
return this.invalidTile
|
|
}
|
|
// Allow tile request when map is valid even if SSE snapshot hasn't arrived yet
|
|
// (avoids empty map when proxy/SSE delays or drops first message)
|
|
if (data.cache === undefined || data.cache === null) {
|
|
data.cache = 0
|
|
}
|
|
|
|
return Util.template(this._url, Util.extend(data, this.options))
|
|
},
|
|
|
|
refresh(x, y, z) {
|
|
let zoom = z
|
|
const maxZoom = this.options.maxZoom
|
|
const zoomReverse = this.options.zoomReverse
|
|
const zoomOffset = this.options.zoomOffset
|
|
|
|
if (zoomReverse) {
|
|
zoom = maxZoom - zoom
|
|
}
|
|
zoom += zoomOffset
|
|
|
|
const key = `${x}:${y}:${zoom}`
|
|
const tile = this._tiles[key]
|
|
if (tile) {
|
|
tile.el.src = this.getTrueTileUrl({ x, y }, z)
|
|
}
|
|
},
|
|
})
|