Skip to content

Commit

Permalink
Zoom to bookmark extent
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitblanc committed Feb 28, 2024
1 parent c7af7f5 commit 9a8e558
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 21 deletions.
27 changes: 24 additions & 3 deletions plugins/Bookmark.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import Spinner from '../components/Spinner';
import {createBookmark, getUserBookmarks, removeBookmark, updateBookmark} from '../utils/PermaLinkUtils';
import './style/Bookmark.css';
import isEmpty from 'lodash.isempty';

import { zoomToPoint } from '../actions/map';
import { resolveBookmark } from '../utils/PermaLinkUtils';
import MapUtils from '../utils/MapUtils';

/**
* Allows managing user bookmarks.
Expand All @@ -29,10 +31,13 @@ import isEmpty from 'lodash.isempty';
*/
class Bookmark extends React.Component {
static propTypes = {
mapCrs: PropTypes.string,
mapScales: PropTypes.array,
/** The side of the application on which to display the sidebar. */
side: PropTypes.string,
state: PropTypes.object,
task: PropTypes.string
task: PropTypes.string,
zoomToPoint: PropTypes.func
};
static defaultProps = {
side: 'right'
Expand All @@ -49,6 +54,7 @@ class Bookmark extends React.Component {
render() {
const openTitle = LocaleUtils.tr("bookmark.open");
const openTabTitle = LocaleUtils.tr("bookmark.openTab");
const zoomTitle = LocaleUtils.tr("bookmark.zoomToExtent");
const username = ConfigUtils.getConfigProp("username");
const placeholder = LocaleUtils.tr("bookmark.description");
const addBookmarkTitle = LocaleUtils.tr("bookmark.add");
Expand Down Expand Up @@ -77,6 +83,9 @@ class Bookmark extends React.Component {
<button className="button" disabled={!currentBookmark} onClick={() => this.open(currentBookmark.key, true)} title={openTabTitle}>
<Icon icon="open_link" />
</button>
<button className="button" disabled={!currentBookmark} onClick={() => this.zoomToBookmarkExtent(currentBookmark.key)} title={zoomTitle}>
<Icon icon="zoom" />
</button>
</span>
<span className="bookmark-actions-spacer" />
<span className="bookmark-actions-buttonbox">
Expand Down Expand Up @@ -118,6 +127,14 @@ class Bookmark extends React.Component {
location.href = url;
}
};
zoomToBookmarkExtent = (bookmarkkey) => {
resolveBookmark(bookmarkkey, (params) => {
const scale = parseFloat(params.s);
const zoom = MapUtils.computeZoom(this.props.mapScales, scale);
const center = params.c.split(/[;,]/g).map(x => parseFloat(x));
this.props.zoomToPoint(center, zoom, this.props.mapCrs);
});
};
toggleCurrentBookmark = (bookmark) => {
if (this.state.currentBookmark === bookmark.key) {
this.setState({currentBookmark: null, description: ""});
Expand Down Expand Up @@ -163,8 +180,12 @@ class Bookmark extends React.Component {
}

const selector = state => ({
mapCrs: state.map.projection,
mapScales: state.map.scales,
task: state.task.id,
state
});

export default connect(selector)(Bookmark);
export default connect(selector, {
zoomToPoint: zoomToPoint
})(Bookmark);
3 changes: 2 additions & 1 deletion translations/ca-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Esborrar",
"removefailed": "Error al eliminar",
"savefailed": "Error al modificar",
"update": "Updatejar"
"update": "Updatejar",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Coordenades",
Expand Down
3 changes: 2 additions & 1 deletion translations/cs-CZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Smazat",
"removefailed": "Mazání záložky selhalo",
"savefailed": "Ukládání záložky selhalo",
"update": "Upravit"
"update": "Upravit",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Souřadnice",
Expand Down
3 changes: 2 additions & 1 deletion translations/de-CH.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Lesezeichen entfernen",
"removefailed": "Lesezeichen konnte nicht entfernt werden",
"savefailed": "Lesezeichen konnte nicht aktualisiert werden",
"update": "Lesezeichen aktualisieren"
"update": "Lesezeichen aktualisieren",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Koordinaten",
Expand Down
3 changes: 2 additions & 1 deletion translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Lesezeichen entfernen",
"removefailed": "Lesezeichen konnte nicht entfernt werden",
"savefailed": "Lesezeichen konnte nicht aktualisiert werden",
"update": "Lesezeichen aktualisieren"
"update": "Lesezeichen aktualisieren",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Koordinaten",
Expand Down
3 changes: 2 additions & 1 deletion translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Remove bookmark",
"removefailed": "Failed to remove bookmark",
"savefailed": "Failed to update bookmark",
"update": "Update bookmark"
"update": "Update bookmark",
"zoomToExtent": "Zoom to extent"
},
"bottombar": {
"mousepos_label": "Coordinates",
Expand Down
3 changes: 2 additions & 1 deletion translations/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Eliminar",
"removefailed": "Error al eliminar el marcador",
"savefailed": "Error al actualizar el marcador",
"update": "Actualizar marcador"
"update": "Actualizar marcador",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Coordenadas",
Expand Down
3 changes: 2 additions & 1 deletion translations/fi-FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Poista kirjanmerkki",
"removefailed": "",
"savefailed": "",
"update": "Päivitä kirjanmerkki"
"update": "Päivitä kirjanmerkki",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Koordinaatit",
Expand Down
3 changes: 2 additions & 1 deletion translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Supprimer le marque-page",
"removefailed": "Echec de suppression du marque-page",
"savefailed": "Echec d'enregistrement du marque-page",
"update": "Sauvegarder le marque-page"
"update": "Sauvegarder le marque-page",
"zoomToExtent": "Zommer sur l'étendue"
},
"bottombar": {
"mousepos_label": "Coordonnées",
Expand Down
3 changes: 2 additions & 1 deletion translations/hu-HU.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "",
"removefailed": "",
"savefailed": "",
"update": ""
"update": "",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Koordináták",
Expand Down
3 changes: 2 additions & 1 deletion translations/it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Rimuovi segnalibro",
"removefailed": "Impossibile rimuovere il segnalibro",
"savefailed": "Impossibile aggiornare il segnalibro",
"update": "Aggiorna segnalibro"
"update": "Aggiorna segnalibro",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Coordinate",
Expand Down
3 changes: 2 additions & 1 deletion translations/no-NO.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "",
"removefailed": "",
"savefailed": "",
"update": ""
"update": "",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Koordinater",
Expand Down
3 changes: 2 additions & 1 deletion translations/pl-PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "",
"removefailed": "",
"savefailed": "",
"update": ""
"update": "",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Współrzędne",
Expand Down
3 changes: 2 additions & 1 deletion translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Remover",
"removefailed": "Falha ao remover",
"savefailed": "Falha ao salvar",
"update": "Atualizar"
"update": "Atualizar",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Coordenadas",
Expand Down
3 changes: 2 additions & 1 deletion translations/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Remover",
"removefailed": "Falha ao Remover",
"savefailed": "Falha ao Guardar",
"update": "Atualizar"
"update": "Atualizar",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Coordenadas",
Expand Down
3 changes: 2 additions & 1 deletion translations/ro-RO.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "Elimină semn de carte",
"removefailed": "Semnul de carte nu a putut fi șters",
"savefailed": "Semnul de carte nu a putut fi salvat",
"update": "Actualizează semnul de carte"
"update": "Actualizează semnul de carte",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Coordonate",
Expand Down
3 changes: 2 additions & 1 deletion translations/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "",
"removefailed": "",
"savefailed": "",
"update": ""
"update": "",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Координаты",
Expand Down
3 changes: 2 additions & 1 deletion translations/sv-SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "",
"removefailed": "",
"savefailed": "",
"update": ""
"update": "",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Koordinater",
Expand Down
3 changes: 2 additions & 1 deletion translations/tr-TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"remove": "",
"removefailed": "",
"savefailed": "",
"update": ""
"update": "",
"zoomToExtent": ""
},
"bottombar": {
"mousepos_label": "Koordinatlar",
Expand Down
1 change: 1 addition & 0 deletions translations/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"bookmark.removefailed",
"bookmark.savefailed",
"bookmark.update",
"bookmark.zoomToExtent",
"bottombar.mousepos_label",
"bottombar.scale_label",
"bottombar.terms_label",
Expand Down
11 changes: 11 additions & 0 deletions utils/PermaLinkUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ export function resolvePermaLink(initialParams, callback) {
}
}

export function resolveBookmark(bookmarkKey, callback) {
axios.get(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/, '') + "/bookmarks/" + bookmarkKey)
.then(response => {
const data = response.data;
callback({...(data.query || {})}, (data.state || {}), !!data.query);
})
.catch(() => {
callback(bookmarkKey, {}, false);
});
}

export function getUserBookmarks(user, callback) {
if (user) {
axios.get(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/, '') + "/bookmarks/")
Expand Down

0 comments on commit 9a8e558

Please sign in to comment.