custom map tile server supports annotation layer

This commit is contained in:
MaysWind
2024-07-21 20:39:10 +08:00
parent aae23c285e
commit 0f8de8d699
7 changed files with 52 additions and 24 deletions
+2 -1
View File
@@ -168,7 +168,8 @@ func startWebServer(c *cli.Context) error {
proxyRoute.GET("/map/tile/:zoomLevel/:coordinateX/:fileName", bindProxy(api.MapImages.MapTileImageProxyHandler)) proxyRoute.GET("/map/tile/:zoomLevel/:coordinateX/:fileName", bindProxy(api.MapImages.MapTileImageProxyHandler))
} }
if config.MapProvider == settings.TianDiTuProvider { if config.MapProvider == settings.TianDiTuProvider ||
(config.MapProvider == settings.CustomProvider && config.CustomMapTileServerAnnotationLayerUrl != "") {
proxyRoute.GET("/map/annotation/:zoomLevel/:coordinateX/:fileName", bindProxy(api.MapImages.MapAnnotationImageProxyHandler)) proxyRoute.GET("/map/annotation/:zoomLevel/:coordinateX/:fileName", bindProxy(api.MapImages.MapAnnotationImageProxyHandler))
} }
} }
+4 -1
View File
@@ -212,9 +212,12 @@ amap_application_secret =
# For "amap" only, Amap JavaScript API external proxy url, this setting must be provided when "amap_security_verification_method" is set to "external_proxy" # For "amap" only, Amap JavaScript API external proxy url, this setting must be provided when "amap_security_verification_method" is set to "external_proxy"
amap_api_external_proxy_url = amap_api_external_proxy_url =
# For "custom" only, the custom map tile server url, supports {x}, {y} (coordinates) and {z} (zoom level) placeholders, like "https://tile.openstreetmap.org/{z}/{x}/{y}.png" # For "custom" only, the tile layer url of custom map tile server, supports {x}, {y} (coordinates) and {z} (zoom level) placeholders, like "https://tile.openstreetmap.org/{z}/{x}/{y}.png"
custom_map_tile_server_url = custom_map_tile_server_url =
# For "custom" only, the optional annotation layer url of custom map tile server, supports {x}, {y} (coordinates) and {z} (zoom level) placeholders
custom_map_tile_server_annotation_url =
# For "custom" only, the min zoom level (0 - 255) for custom map tile server, default is 1 # For "custom" only, the min zoom level (0 - 255) for custom map tile server, default is 1
custom_map_tile_server_min_zoom_level = 1 custom_map_tile_server_min_zoom_level = 1
+3 -1
View File
@@ -58,7 +58,7 @@ func (p *MapImageProxy) MapTileImageProxyHandler(c *core.Context) (*httputil.Rev
} else if mapProvider == settings.TianDiTuProvider { } else if mapProvider == settings.TianDiTuProvider {
return tianDiTuMapTileImageUrlFormat + "&tk=" + settings.Container.Current.TianDiTuAPIKey, nil return tianDiTuMapTileImageUrlFormat + "&tk=" + settings.Container.Current.TianDiTuAPIKey, nil
} else if mapProvider == settings.CustomProvider { } else if mapProvider == settings.CustomProvider {
return settings.Container.Current.CustomMapTileServerUrl, nil return settings.Container.Current.CustomMapTileServerTileLayerUrl, nil
} }
return "", errs.ErrParameterInvalid return "", errs.ErrParameterInvalid
@@ -70,6 +70,8 @@ func (p *MapImageProxy) MapAnnotationImageProxyHandler(c *core.Context) (*httput
return p.mapImageProxyHandler(c, func(c *core.Context, mapProvider string) (string, *errs.Error) { return p.mapImageProxyHandler(c, func(c *core.Context, mapProvider string) (string, *errs.Error) {
if mapProvider == settings.TianDiTuProvider { if mapProvider == settings.TianDiTuProvider {
return tianDiTuMapAnnotationUrlFormat + "&tk=" + settings.Container.Current.TianDiTuAPIKey, nil return tianDiTuMapAnnotationUrlFormat + "&tk=" + settings.Container.Current.TianDiTuAPIKey, nil
} else if mapProvider == settings.CustomProvider {
return settings.Container.Current.CustomMapTileServerAnnotationLayerUrl, nil
} }
return "", errs.ErrParameterInvalid return "", errs.ErrParameterInvalid
+9 -1
View File
@@ -40,7 +40,15 @@ func ServerSettingsCookie(config *settings.Config) core.MiddlewareHandlerFunc {
settingsArr = append(settingsArr, buildStringSetting("cmzl", fmt.Sprintf("%d-%d-%d", config.CustomMapTileServerMinZoomLevel, config.CustomMapTileServerMaxZoomLevel, config.CustomMapTileServerDefaultZoomLevel))) settingsArr = append(settingsArr, buildStringSetting("cmzl", fmt.Sprintf("%d-%d-%d", config.CustomMapTileServerMinZoomLevel, config.CustomMapTileServerMaxZoomLevel, config.CustomMapTileServerDefaultZoomLevel)))
if !config.EnableMapDataFetchProxy { if !config.EnableMapDataFetchProxy {
settingsArr = append(settingsArr, buildEncodedStringSetting("cmsu", config.CustomMapTileServerUrl)) settingsArr = append(settingsArr, buildEncodedStringSetting("cmsu", config.CustomMapTileServerTileLayerUrl))
if config.CustomMapTileServerAnnotationLayerUrl != "" {
settingsArr = append(settingsArr, buildEncodedStringSetting("cmau", config.CustomMapTileServerAnnotationLayerUrl))
}
} else {
if config.CustomMapTileServerAnnotationLayerUrl != "" {
settingsArr = append(settingsArr, buildBooleanSetting("cmap", config.EnableMapDataFetchProxy))
}
} }
} }
+4 -2
View File
@@ -251,7 +251,8 @@ type Config struct {
AmapSecurityVerificationMethod string AmapSecurityVerificationMethod string
AmapApplicationSecret string AmapApplicationSecret string
AmapApiExternalProxyUrl string AmapApiExternalProxyUrl string
CustomMapTileServerUrl string CustomMapTileServerTileLayerUrl string
CustomMapTileServerAnnotationLayerUrl string
CustomMapTileServerMinZoomLevel uint8 CustomMapTileServerMinZoomLevel uint8
CustomMapTileServerMaxZoomLevel uint8 CustomMapTileServerMaxZoomLevel uint8
CustomMapTileServerDefaultZoomLevel uint8 CustomMapTileServerDefaultZoomLevel uint8
@@ -691,7 +692,8 @@ func loadMapConfiguration(config *Config, configFile *ini.File, sectionName stri
config.AmapApplicationSecret = getConfigItemStringValue(configFile, sectionName, "amap_application_secret") config.AmapApplicationSecret = getConfigItemStringValue(configFile, sectionName, "amap_application_secret")
config.AmapApiExternalProxyUrl = getConfigItemStringValue(configFile, sectionName, "amap_api_external_proxy_url") config.AmapApiExternalProxyUrl = getConfigItemStringValue(configFile, sectionName, "amap_api_external_proxy_url")
config.CustomMapTileServerUrl = getConfigItemStringValue(configFile, sectionName, "custom_map_tile_server_url") config.CustomMapTileServerTileLayerUrl = getConfigItemStringValue(configFile, sectionName, "custom_map_tile_server_url")
config.CustomMapTileServerAnnotationLayerUrl = getConfigItemStringValue(configFile, sectionName, "custom_map_tile_server_annotation_url")
config.CustomMapTileServerMinZoomLevel = getConfigItemUint8Value(configFile, sectionName, "custom_map_tile_server_min_zoom_level", 1) config.CustomMapTileServerMinZoomLevel = getConfigItemUint8Value(configFile, sectionName, "custom_map_tile_server_min_zoom_level", 1)
config.CustomMapTileServerMaxZoomLevel = getConfigItemUint8Value(configFile, sectionName, "custom_map_tile_server_max_zoom_level", 18) config.CustomMapTileServerMaxZoomLevel = getConfigItemUint8Value(configFile, sectionName, "custom_map_tile_server_max_zoom_level", 18)
config.CustomMapTileServerDefaultZoomLevel = getConfigItemUint8Value(configFile, sectionName, "custom_map_tile_server_default_zoom_level", 14) config.CustomMapTileServerDefaultZoomLevel = getConfigItemUint8Value(configFile, sectionName, "custom_map_tile_server_default_zoom_level", 14)
+7 -3
View File
@@ -1,7 +1,9 @@
import mapConstants from '@/consts/map.js'; import mapConstants from '@/consts/map.js';
import { import {
isMapDataFetchProxyEnabled, isMapDataFetchProxyEnabled,
getCustomMapTileServerUrl, getCustomMapTileLayerUrl,
getCustomMapAnnotationLayerUrl,
isCustomMapAnnotationLayerDataFetchProxyEnabled,
getCustomMapMinZoomLevel, getCustomMapMinZoomLevel,
getCustomMapMaxZoomLevel, getCustomMapMaxZoomLevel,
getCustomMapDefaultZoomLevel, getCustomMapDefaultZoomLevel,
@@ -77,7 +79,7 @@ export function createLeafletMapInstance(mapHolder, mapContainer, options) {
}); });
tileLayer.addTo(leafletInstance); tileLayer.addTo(leafletInstance);
if (mapTileSource.annotationUrlFormat) { if (mapTileSource.annotationUrlFormat || (mapHolder.mapProvider === 'custom' && isCustomMapAnnotationLayerDataFetchProxyEnabled())) {
if (isMapDataFetchProxyEnabled()) { if (isMapDataFetchProxyEnabled()) {
mapTileSource.annotationUrlFormat = services.generateMapProxyAnnotationImageUrl(mapHolder.mapProvider, options.language); mapTileSource.annotationUrlFormat = services.generateMapProxyAnnotationImageUrl(mapHolder.mapProvider, options.language);
mapTileSource.annotationUrlSubDomains = ''; mapTileSource.annotationUrlSubDomains = '';
@@ -160,8 +162,10 @@ export function removeLeafletMapCenterMaker(mapHolder) {
function createCustomMapSource() { function createCustomMapSource() {
return { return {
tileUrlFormat: getCustomMapTileServerUrl(), tileUrlFormat: getCustomMapTileLayerUrl(),
tileUrlSubDomains: '', tileUrlSubDomains: '',
annotationUrlFormat: getCustomMapAnnotationLayerUrl(),
annotationUrlSubDomains: '',
minZoom: getCustomMapMinZoomLevel(), minZoom: getCustomMapMinZoomLevel(),
maxZoom: getCustomMapMaxZoomLevel(), maxZoom: getCustomMapMaxZoomLevel(),
defaultZoomLevel: getCustomMapDefaultZoomLevel() defaultZoomLevel: getCustomMapDefaultZoomLevel()
+9 -1
View File
@@ -53,10 +53,18 @@ export function isMapDataFetchProxyEnabled() {
return getServerSetting('mp') === '1'; return getServerSetting('mp') === '1';
} }
export function getCustomMapTileServerUrl() { export function getCustomMapTileLayerUrl() {
return getServerDecodedSetting('cmsu'); return getServerDecodedSetting('cmsu');
} }
export function getCustomMapAnnotationLayerUrl() {
return getServerDecodedSetting('cmau');
}
export function isCustomMapAnnotationLayerDataFetchProxyEnabled() {
return getServerSetting('cmap') === '1';
}
export function getCustomMapMinZoomLevel() { export function getCustomMapMinZoomLevel() {
const zoomLevelSettings = (getServerSetting('cmzl') || '').split('-'); const zoomLevelSettings = (getServerSetting('cmzl') || '').split('-');
return (zoomLevelSettings && zoomLevelSettings[0]) ? parseInt(zoomLevelSettings[0]) : 1; return (zoomLevelSettings && zoomLevelSettings[0]) ? parseInt(zoomLevelSettings[0]) : 1;