TagSpaces is an offline, open source, document manager with tagging support
feat: improved the handling of custom map tile servers
Ilian Sapundshievc9f9750c1949
diff --git a/assets/links.ts b/assets/links.tsindex 1b0d3249c..53cfd9572 100644--- a/assets/links.ts+++ b/assets/links.ts@@ -81,6 +81,7 @@ const Links = {taglibrary: 'https://docs.tagspaces.org/ui/taglibrary' + urlParams,search: 'https://docs.tagspaces.org/search' + urlParams,settings: 'https://docs.tagspaces.org/ui/settings' + urlParams,+ mapTiles: 'https://docs.tagspaces.org/maptiles' + urlParams,sharing: 'https://docs.tagspaces.org/sharing' + urlParams,creatingFiles: 'https://docs.tagspaces.org/creating-files' + urlParams,},diff --git a/src/renderer/components/NoTileServer.tsx b/src/renderer/components/NoTileServer.tsxindex e2eb5d5cf..695862b15 100644--- a/src/renderer/components/NoTileServer.tsx+++ b/src/renderer/components/NoTileServer.tsx@@ -1,12 +1,35 @@-import React from 'react';+import TsButton from '-/components/TsButton';+import MapTileServerDialog from '-/components/dialogs/MapTileServerDialog';+import { TS } from '-/tagspaces.namespace';+import { useState } from 'react';import { useTranslation } from 'react-i18next';function NoTileServer() {const { t } = useTranslation();+ const [tileServerDialog, setTileServerDialog] = useState<+ (TS.MapTileServer & { isDefault: boolean }) | undefined+ >(undefined);+return (<div style={{ textAlign: 'center' }}><h1>{t('core:noTileServersTitle')}</h1><h3>{t('core:addTileServersSettings')}</h3>+ <TsButton+ variant="contained"+ onClick={() =>+ setTileServerDialog({ ...({} as TS.MapTileServer), isDefault: true })+ }+ >+ {t('core:tileServerDialogAdd')}+ </TsButton>+ {tileServerDialog && (+ <MapTileServerDialog+ open={tileServerDialog !== undefined}+ onClose={() => setTileServerDialog(undefined)}+ tileServer={tileServerDialog}+ isDefault={tileServerDialog.isDefault}+ />+ )}</div>);}diff --git a/src/renderer/components/dialogs/MapTileServerDialog.tsx b/src/renderer/components/dialogs/MapTileServerDialog.tsxindex 3b1a228fe..9b0376994 100644--- a/src/renderer/components/dialogs/MapTileServerDialog.tsx+++ b/src/renderer/components/dialogs/MapTileServerDialog.tsx@@ -17,29 +17,42 @@*/import AppConfig from '-/AppConfig';+import { HelpIcon } from '-/components/CommonIcons';import DraggablePaper from '-/components/DraggablePaper';import TsButton from '-/components/TsButton';+import TsIconButton from '-/components/TsIconButton';import TsTextField from '-/components/TsTextField';import TsDialogActions from '-/components/dialogs/components/TsDialogActions';import TsDialogTitle from '-/components/dialogs/components/TsDialogTitle';import { AppDispatch } from '-/reducers/app';import { actions as SettingsActions } from '-/reducers/settings';+import { openUrl } from '-/services/utils-io';import { TS } from '-/tagspaces.namespace';import useValidation from '-/utils/useValidation';import Dialog from '@mui/material/Dialog';import DialogContent from '@mui/material/DialogContent';+import DialogContentText from '@mui/material/DialogContentText';import FormControl from '@mui/material/FormControl';-import FormHelperText from '@mui/material/FormHelperText';import ListItem from '@mui/material/ListItem';import ListItemText from '@mui/material/ListItemText';import Paper from '@mui/material/Paper';+import Stack from '@mui/material/Stack';import Switch from '@mui/material/Switch';import { useTheme } from '@mui/material/styles';import useMediaQuery from '@mui/material/useMediaQuery';-import { useRef } from 'react';+import Links from 'assets/links';+import { useRef, useState } from 'react';import { useTranslation } from 'react-i18next';import { useDispatch } from 'react-redux';+const OSM_TILE_SERVER = {+ name: 'OpenStreetMap',+ serverURL: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png',+ serverInfo:+ '<b>Leaflet</b> | Map data: © <a href="https://openstreetmap.org/copyright">OpenStreetMap</a> contributors',+};+const OSM_PRIVACY_URL = 'https://osmfoundation.org/wiki/Privacy_Policy';+interface Props {open: boolean;onClose: () => void;@@ -58,6 +71,17 @@ function MapTileServerDialog(props: Props) {const smallScreen = useMediaQuery(theme.breakpoints.down('md'));const { open, onClose } = props;const { setError, haveError } = useValidation();+ const [osmConfirmOpen, setOsmConfirmOpen] = useState(false);+ const [formKey, setFormKey] = useState(0);++ const applyOsmDefaults = () => {+ name.current = OSM_TILE_SERVER.name;+ serverURL.current = OSM_TILE_SERVER.serverURL;+ serverInfo.current = OSM_TILE_SERVER.serverInfo;+ setError('name', false);+ setFormKey((k) => k + 1);+ setOsmConfirmOpen(false);+ };const validateForm = () => {if (!name.current) {@@ -101,8 +125,20 @@ function MapTileServerDialog(props: Props) {const renderContent = () => (<DialogContent>+ {!props.tileServer.uuid && (+ <Stack sx={{ marginBottom: '8px' }}>+ <TsButton+ variant="outlined"+ data-tid="useOpenStreetMapTID"+ onClick={() => setOsmConfirmOpen(true)}+ >+ {t('core:tileServerUseOpenStreetMap')}+ </TsButton>+ </Stack>+ )}<FormControl fullWidth={true} error={haveError('name')}><TsTextField+ key={'name-' + formKey}error={haveError('name')}autoFocusname="name"@@ -119,6 +155,7 @@ function MapTileServerDialog(props: Props) {</FormControl><FormControl fullWidth={true}><TsTextField+ key={'url-' + formKey}name="serverURL"label={t('core:tileServerUrlTitle')}onChange={(event) => {@@ -129,14 +166,10 @@ function MapTileServerDialog(props: Props) {defaultValue={serverURL.current}data-tid="tileServerUrlTID"/>- <FormHelperText- sx={{ marginLeft: 0, marginTop: 0, marginBottom: '10px' }}- >- {t('core:tileServerUrlHelp')}- </FormHelperText></FormControl><FormControl fullWidth={true}><TsTextField+ key={'info-' + formKey}name="serverInfo"label={t('core:tileServerInfoTitle')}onChange={(event) => {@@ -180,25 +213,31 @@ function MapTileServerDialog(props: Props) {onClose={onClose}/>{renderContent()}- <TsDialogActions- sx={{- justifyContent: props.tileServer.uuid ? 'space-between' : 'flex-end',- }}- >- {props.tileServer.uuid && (- <TsButton- sx={{- marginLeft: '10px',- }}- data-tid="deleteTileServerTID"- onClick={() => {- dispatch(SettingsActions.deleteTileServer(props.tileServer.uuid));- props.onClose();- }}+ <TsDialogActions sx={{ justifyContent: 'space-between' }}>+ <div>+ <TsIconButton+ tooltip={t('core:documentation')}+ data-tid="tileServerHelpTID"+ onClick={() => openUrl(Links.documentationLinks.mapTiles)}+ aria-label="help">- {t('core:delete')}- </TsButton>- )}+ <HelpIcon />+ </TsIconButton>+ {props.tileServer.uuid && (+ <TsButton+ sx={{ marginLeft: AppConfig.defaultSpaceBetweenButtons }}+ data-tid="deleteTileServerTID"+ onClick={() => {+ dispatch(+ SettingsActions.deleteTileServer(props.tileServer.uuid),+ );+ props.onClose();+ }}+ >+ {t('core:delete')}+ </TsButton>+ )}+ </div><div><TsButton data-tid="closeTileServerDialogTID" onClick={props.onClose}>{t('core:closeButton')}@@ -213,6 +252,46 @@ function MapTileServerDialog(props: Props) {</TsButton></div></TsDialogActions>+ <Dialog+ open={osmConfirmOpen}+ onClose={() => setOsmConfirmOpen(false)}+ keepMounted={false}+ sx={{ zIndex: 1301 }}+ >+ <TsDialogTitle+ dialogTitle={t('core:tileServerOsmConfirmTitle')}+ closeButtonTestId="closeOsmConfirmTID"+ onClose={() => setOsmConfirmOpen(false)}+ />+ <DialogContent>+ <DialogContentText>+ {t('core:tileServerOsmConfirmText')}+ </DialogContentText>+ <TsButton+ variant="text"+ sx={{ marginTop: '8px', paddingLeft: 0 }}+ onClick={() => openUrl(OSM_PRIVACY_URL)}+ >+ {t('core:tileServerOsmPrivacyPolicy')}+ </TsButton>+ </DialogContent>+ <TsDialogActions>+ <TsButton+ data-tid="cancelOsmConfirmTID"+ onClick={() => setOsmConfirmOpen(false)}+ >+ {t('core:cancel')}+ </TsButton>+ <TsButton+ data-tid="acceptOsmConfirmTID"+ onClick={applyOsmDefaults}+ sx={{ marginLeft: AppConfig.defaultSpaceBetweenButtons }}+ variant="contained"+ >+ {t('core:tileServerOsmConfirmAccept')}+ </TsButton>+ </TsDialogActions>+ </Dialog></Dialog>);}diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.jsonindex 58fd3dad1..2e13bf62c 100644--- a/src/renderer/locales/en/core.json+++ b/src/renderer/locales/en/core.json@@ -636,12 +636,16 @@"tileServerDialogAdd": "Add Map Tile Server","tileServerNameTitle": "Server Name","tileServerUrlTitle": "Server URL",- "tileServerUrlHelp": "Example: https://{s}.tile.osm.org/{z}/{x}/{y}.png","tileServerInfoTitle": "Copyright Information","serverIsDefaultHelp": "Set as Default Map Tile Server","noTileServersTitle": "No map tile server!","addTileServersHelp": "Further map tile servers can be found in the OpenStreetMap documentation","addTileServersSettings": "In order to see the map, add at least one map tile server in the settings of the app",+ "tileServerUseOpenStreetMap": "Use OpenStreetMap",+ "tileServerOsmConfirmTitle": "Use the OpenStreetMap tile server?",+ "tileServerOsmConfirmText": "OpenStreetMap is a free, third-party map service operated by the OpenStreetMap Foundation. By using it you accept their terms of use, and requests sent to their servers will be subject to their privacy policy.",+ "tileServerOsmPrivacyPolicy": "Open OpenStreetMap Privacy Policy",+ "tileServerOsmConfirmAccept": "Accept and use","showFolderMapControl": "Show folders on the map","noSubFoldersFound": "No subfolders in the current folder","fileTaggingSetting": "File tagging method",diff --git a/src/renderer/reducers/settings-default.ts b/src/renderer/reducers/settings-default.tsindex 3911def5a..09dfb9bec 100644--- a/src/renderer/reducers/settings-default.ts+++ b/src/renderer/reducers/settings-default.ts@@ -20,7 +20,6 @@ import AppConfig from '-/AppConfig';import { extensionsFound, supportedFileTypes } from '-/extension-config';import { PerspectiveIDs } from '-/perspectives';import keyBindings from '-/reducers/keybindings-default';-import { getUuid } from '@tagspaces/tagspaces-common/utils-io';let desktopMode = !AppConfig.isMobile;if (AppConfig.ExtDisplayMode === 'mobile') {@@ -278,20 +277,5 @@ export default {? [...extensionsFound, ...AppConfig.ExtExtensionsFound]: extensionsFound,enabledExtensions: [],- mapTileServers: [- {- uuid: getUuid(),- name: 'Standard',- serverURL: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png',- serverInfo:- '<b>Leaflet</b> | Map data: © <b>https://openstreetmap.org/copyright</b> contributors',- },- {- uuid: getUuid(),- name: 'Topographic',- serverURL: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',- serverInfo:- '<b>Leaflet</b> | Map data: © <b>https://openstreetmap.org/copyright</b> contributors, SRTM | Map style: © <b>https://opentopomap.org</b> - OpenTopoMap (<b>https://creativecommons.org/licenses/by-sa/3.0/</b> - CC-BY-SA',- },- ],+ mapTileServers: [],};