Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions plugins/Bookmark.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import classnames from 'classnames';
import isEmpty from 'lodash.isempty';
import PropTypes from 'prop-types';

import { zoomToExtent, zoomToPoint } from '../actions/map';
import Icon from '../components/Icon';
import SideBar from '../components/SideBar';
import Spinner from '../components/Spinner';
import ConfigUtils from '../utils/ConfigUtils';
import LocaleUtils from '../utils/LocaleUtils';
import {createBookmark, getUserBookmarks, removeBookmark, updateBookmark} from '../utils/PermaLinkUtils';
import MapUtils from '../utils/MapUtils';
import {createBookmark, getUserBookmarks, removeBookmark, resolveBookmark, updateBookmark} from '../utils/PermaLinkUtils';

import './style/Bookmark.css';


/**
* Allows managing user bookmarks.
*
Expand All @@ -32,10 +33,14 @@ import './style/Bookmark.css';
*/
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,
zoomToExtent: PropTypes.func,
zoomToPoint: PropTypes.func
};
static defaultProps = {
side: 'right'
Expand All @@ -52,6 +57,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 @@ -80,6 +86,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 @@ -121,6 +130,19 @@ class Bookmark extends React.Component {
location.href = url;
}
};
zoomToBookmarkExtent = (bookmarkkey) => {
resolveBookmark(bookmarkkey, (params) => {
if ('c' in params && 's' in 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, params.crs ?? this.props.mapCrs);
} else if ('e' in params) {
const bounds = (params.e).split(',').map(n => parseFloat(n));
this.props.zoomToExtent(bounds, params.crs ?? this.props.mapCrs);
}
});
};
toggleCurrentBookmark = (bookmark) => {
if (this.state.currentBookmark === bookmark.key) {
this.setState({currentBookmark: null, description: ""});
Expand Down Expand Up @@ -166,8 +188,13 @@ 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, {
zoomToExtent: zoomToExtent,
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 @@ -135,6 +135,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