diff --git a/cmd/webserver.go b/cmd/webserver.go index e7ad1433..2434b0a9 100644 --- a/cmd/webserver.go +++ b/cmd/webserver.go @@ -168,7 +168,8 @@ func startWebServer(c *cli.Context) error { 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)) } } diff --git a/conf/ezbookkeeping.ini b/conf/ezbookkeeping.ini index c62743db..12032a5a 100644 --- a/conf/ezbookkeeping.ini +++ b/conf/ezbookkeeping.ini @@ -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" 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 = +# 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 custom_map_tile_server_min_zoom_level = 1 diff --git a/pkg/api/map_image_proxies.go b/pkg/api/map_image_proxies.go index ffcc4cf3..4b6ebd07 100644 --- a/pkg/api/map_image_proxies.go +++ b/pkg/api/map_image_proxies.go @@ -58,7 +58,7 @@ func (p *MapImageProxy) MapTileImageProxyHandler(c *core.Context) (*httputil.Rev } else if mapProvider == settings.TianDiTuProvider { return tianDiTuMapTileImageUrlFormat + "&tk=" + settings.Container.Current.TianDiTuAPIKey, nil } else if mapProvider == settings.CustomProvider { - return settings.Container.Current.CustomMapTileServerUrl, nil + return settings.Container.Current.CustomMapTileServerTileLayerUrl, nil } 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) { if mapProvider == settings.TianDiTuProvider { return tianDiTuMapAnnotationUrlFormat + "&tk=" + settings.Container.Current.TianDiTuAPIKey, nil + } else if mapProvider == settings.CustomProvider { + return settings.Container.Current.CustomMapTileServerAnnotationLayerUrl, nil } return "", errs.ErrParameterInvalid diff --git a/pkg/middlewares/server_settings_cookie.go b/pkg/middlewares/server_settings_cookie.go index 695ccd89..f8153962 100644 --- a/pkg/middlewares/server_settings_cookie.go +++ b/pkg/middlewares/server_settings_cookie.go @@ -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))) 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)) + } } } diff --git a/pkg/settings/setting.go b/pkg/settings/setting.go index 49637956..3fdc42b4 100644 --- a/pkg/settings/setting.go +++ b/pkg/settings/setting.go @@ -240,21 +240,22 @@ type Config struct { EnableDataExport bool // Map - MapProvider string - EnableMapDataFetchProxy bool - MapProxy string - TomTomMapAPIKey string - TianDiTuAPIKey string - GoogleMapAPIKey string - BaiduMapAK string - AmapApplicationKey string - AmapSecurityVerificationMethod string - AmapApplicationSecret string - AmapApiExternalProxyUrl string - CustomMapTileServerUrl string - CustomMapTileServerMinZoomLevel uint8 - CustomMapTileServerMaxZoomLevel uint8 - CustomMapTileServerDefaultZoomLevel uint8 + MapProvider string + EnableMapDataFetchProxy bool + MapProxy string + TomTomMapAPIKey string + TianDiTuAPIKey string + GoogleMapAPIKey string + BaiduMapAK string + AmapApplicationKey string + AmapSecurityVerificationMethod string + AmapApplicationSecret string + AmapApiExternalProxyUrl string + CustomMapTileServerTileLayerUrl string + CustomMapTileServerAnnotationLayerUrl string + CustomMapTileServerMinZoomLevel uint8 + CustomMapTileServerMaxZoomLevel uint8 + CustomMapTileServerDefaultZoomLevel uint8 // Exchange Rates ExchangeRatesDataSource string @@ -691,7 +692,8 @@ func loadMapConfiguration(config *Config, configFile *ini.File, sectionName stri config.AmapApplicationSecret = getConfigItemStringValue(configFile, sectionName, "amap_application_secret") 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.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) diff --git a/src/lib/map/leaflet.js b/src/lib/map/leaflet.js index 35a38a0a..3ff3bb9c 100644 --- a/src/lib/map/leaflet.js +++ b/src/lib/map/leaflet.js @@ -1,7 +1,9 @@ import mapConstants from '@/consts/map.js'; import { isMapDataFetchProxyEnabled, - getCustomMapTileServerUrl, + getCustomMapTileLayerUrl, + getCustomMapAnnotationLayerUrl, + isCustomMapAnnotationLayerDataFetchProxyEnabled, getCustomMapMinZoomLevel, getCustomMapMaxZoomLevel, getCustomMapDefaultZoomLevel, @@ -77,7 +79,7 @@ export function createLeafletMapInstance(mapHolder, mapContainer, options) { }); tileLayer.addTo(leafletInstance); - if (mapTileSource.annotationUrlFormat) { + if (mapTileSource.annotationUrlFormat || (mapHolder.mapProvider === 'custom' && isCustomMapAnnotationLayerDataFetchProxyEnabled())) { if (isMapDataFetchProxyEnabled()) { mapTileSource.annotationUrlFormat = services.generateMapProxyAnnotationImageUrl(mapHolder.mapProvider, options.language); mapTileSource.annotationUrlSubDomains = ''; @@ -160,8 +162,10 @@ export function removeLeafletMapCenterMaker(mapHolder) { function createCustomMapSource() { return { - tileUrlFormat: getCustomMapTileServerUrl(), + tileUrlFormat: getCustomMapTileLayerUrl(), tileUrlSubDomains: '', + annotationUrlFormat: getCustomMapAnnotationLayerUrl(), + annotationUrlSubDomains: '', minZoom: getCustomMapMinZoomLevel(), maxZoom: getCustomMapMaxZoomLevel(), defaultZoomLevel: getCustomMapDefaultZoomLevel() diff --git a/src/lib/server_settings.js b/src/lib/server_settings.js index 63c94299..1f3b6413 100644 --- a/src/lib/server_settings.js +++ b/src/lib/server_settings.js @@ -53,10 +53,18 @@ export function isMapDataFetchProxyEnabled() { return getServerSetting('mp') === '1'; } -export function getCustomMapTileServerUrl() { +export function getCustomMapTileLayerUrl() { return getServerDecodedSetting('cmsu'); } +export function getCustomMapAnnotationLayerUrl() { + return getServerDecodedSetting('cmau'); +} + +export function isCustomMapAnnotationLayerDataFetchProxyEnabled() { + return getServerSetting('cmap') === '1'; +} + export function getCustomMapMinZoomLevel() { const zoomLevelSettings = (getServerSetting('cmzl') || '').split('-'); return (zoomLevelSettings && zoomLevelSettings[0]) ? parseInt(zoomLevelSettings[0]) : 1;