-
-
Notifications
You must be signed in to change notification settings - Fork 125
LayerBookmarks Plugin: Save and restore layer bookmarks without changing map position #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NinaRoeckeleinSWM
wants to merge
2
commits into
qgis:master
Choose a base branch
from
NinaRoeckeleinSWM:layerBookmarks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /** | ||
| * Copyright 2025 Stadtwerke München GmbH | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import axios from 'axios'; | ||
|
|
||
| import bookmarkReducer from '../reducers/bookmark'; | ||
| import ReducerIndex from '../reducers/index'; | ||
| import ConfigUtils from '../utils/ConfigUtils'; | ||
| ReducerIndex.register("bookmark", bookmarkReducer); | ||
|
|
||
| export const SET_BOOKMARKS = 'SET_BOOKMARKS'; | ||
|
|
||
| export function setBookmarks(bookmarks) { | ||
| return { | ||
| type: SET_BOOKMARKS, | ||
| bookmarks | ||
| }; | ||
| } | ||
|
|
||
| export function refreshUserBookmarks() { | ||
| return (dispatch, getState) => { | ||
| const username = ConfigUtils.getConfigProp("username"); | ||
| const permalinkServiceUrl = ConfigUtils.getConfigProp("permalinkServiceUrl"); | ||
| if (username && permalinkServiceUrl) { | ||
| axios.get(permalinkServiceUrl.replace(/\/$/, '') + "/bookmarks/") | ||
| .then(response => { | ||
| dispatch(setBookmarks(response.data || [])); | ||
| }) | ||
| .catch(() => { | ||
| dispatch(setBookmarks([])); | ||
| }); | ||
| } | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /** | ||
| * Copyright 2021 Oslandia SAS <[email protected]> | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import classnames from 'classnames'; | ||
| import isEmpty from 'lodash.isempty'; | ||
| import isEqual from 'lodash.isequal'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| import ConfigUtils from '../utils/ConfigUtils'; | ||
| import Icon from './Icon'; | ||
| import Spinner from './widgets/Spinner'; | ||
|
|
||
| import '../plugins/style/Bookmark.css'; | ||
|
|
||
|
|
||
| /** | ||
| * Reusable panel component for managing bookmarks. | ||
| * | ||
| * Used in both Bookmark and LayerBookmark plugins. | ||
| */ | ||
| export default class BookmarkPanel extends React.Component { | ||
| static propTypes = { | ||
| bookmarks: PropTypes.array, | ||
| onAdd: PropTypes.func, | ||
| onOpen: PropTypes.func, | ||
| onRemove: PropTypes.func, | ||
| onUpdate: PropTypes.func, | ||
| onZoomToExtent: PropTypes.func, | ||
| translations: PropTypes.objectOf(PropTypes.string) | ||
| }; | ||
| state = { | ||
| currentBookmark: null, | ||
| description: "", | ||
| adding: false, | ||
| saving: false, | ||
| trashing: false | ||
| }; | ||
| componentDidUpdate(prevProps) { | ||
| if (prevProps.bookmarks !== this.props.bookmarks) { | ||
| this.setState({adding: false, saving: false, trashing: false}); | ||
| // Select a recently added bookmark | ||
| const addedBookmark = this.props.bookmarks.find(bookmark => | ||
| !prevProps.bookmarks.some(prevBookmark => prevBookmark.key === bookmark.key) | ||
| ); | ||
| if (addedBookmark) { | ||
| this.setState({ | ||
| currentBookmark: addedBookmark.key, | ||
| description: addedBookmark.description | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| render() { | ||
| const username = ConfigUtils.getConfigProp("username"); | ||
| const currentBookmark = this.props.bookmarks.find(bookmark => bookmark.key === this.state.currentBookmark); | ||
|
|
||
| return ( | ||
| <div className="bookmark-body" role="body"> | ||
| {!username ? ( | ||
| this.props.translations?.notloggedin | ||
| ) : ( | ||
| <> | ||
| <h4>{this.props.translations?.manage}</h4> | ||
| <div className="bookmark-create"> | ||
| <input onChange={ev => this.setState({description: ev.target.value})} | ||
| onKeyDown={ev => {if (ev.key === "Enter" && this.state.description !== "") { this.addBookmark(); }}} | ||
| placeholder={this.props.translations?.description} type="text" value={this.state.description} /> | ||
| </div> | ||
| <div className="bookmark-actions controlgroup"> | ||
| <button className="button" disabled={!currentBookmark} onClick={() => this.props.onOpen(currentBookmark.key, false)} title={this.props.translations?.open}> | ||
| <Icon icon="folder-open" /> | ||
| </button> | ||
| <button className="button" disabled={!currentBookmark} onClick={() => this.props.onOpen(currentBookmark.key, true)} title={this.props.translations?.openTab}> | ||
| <Icon icon="open_link" /> | ||
| </button> | ||
| {this.props.onZoomToExtent ? ( | ||
| <button className="button" disabled={!currentBookmark} onClick={() => this.props.onZoomToExtent(currentBookmark.key)} title={this.props.translations?.zoomToExtent}> | ||
| <Icon icon="zoom" /> | ||
| </button> | ||
| ) : null} | ||
| <span className="bookmark-actions-spacer" /> | ||
| <button className="button" disabled={!this.state.description} onClick={this.addBookmark} title={this.props.translations?.add}> | ||
| {this.state.adding ? (<Spinner />) : (<Icon icon="plus" />)} | ||
| </button> | ||
| <button className="button" disabled={!currentBookmark || !this.state.description} onClick={() => this.updateBookmark(currentBookmark)} title={this.props.translations?.update}> | ||
| {this.state.saving ? (<Spinner />) : (<Icon icon="save" />)} | ||
| </button> | ||
| <button className="button" disabled={!currentBookmark} onClick={() => this.removeBookmark(currentBookmark)} title={this.props.translations?.remove}> | ||
| {this.state.trashing ? (<Spinner />) : (<Icon icon="trash" />)} | ||
| </button> | ||
| </div> | ||
| <div className="bookmark-list"> | ||
| {this.props.bookmarks.map((bookmark) => { | ||
| const itemclasses = classnames({ | ||
| "bookmark-list-item": true, | ||
| "bookmark-list-item-active": this.state.currentBookmark === bookmark.key | ||
| }); | ||
| return ( | ||
| <div className={itemclasses} key={bookmark.key} | ||
| onClick={() => this.toggleCurrentBookmark(bookmark)} | ||
| onDoubleClick={() => this.props.onOpen(bookmark.key, false)} | ||
| title={this.props.translations?.lastUpdate + ": " + bookmark.date} | ||
| > | ||
| {bookmark.description} | ||
| </div> | ||
| ); | ||
| })} | ||
| {isEmpty(this.props.bookmarks) ? ( | ||
| <div className="bookmark-list-item-empty">{this.props.translations?.nobookmarks}</div> | ||
| ) : null} | ||
| </div> | ||
| </> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| toggleCurrentBookmark = (bookmark) => { | ||
| if (this.state.currentBookmark === bookmark.key) { | ||
| this.setState({currentBookmark: null, description: ""}); | ||
| } else { | ||
| this.setState({currentBookmark: bookmark.key, description: bookmark.description}); | ||
| } | ||
| }; | ||
| addBookmark = () => { | ||
| this.setState({adding: true, description: "", currentBookmark: null}); | ||
| this.props.onAdd(this.state.description); | ||
| }; | ||
| updateBookmark = (bookmark) => { | ||
| this.setState({saving: true}); | ||
| this.props.onUpdate(bookmark.key, this.state.description); | ||
| }; | ||
| removeBookmark = (bookmark) => { | ||
| this.setState({trashing: true, description: "", currentBookmark: null}); | ||
| this.props.onRemove(bookmark.key); | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /** | ||
| * Copyright 2025 Stadtwerke München GmbH | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import React, {Component} from 'react'; | ||
|
|
||
| import PropTypes from 'prop-types'; | ||
|
|
||
| /** | ||
| * Dropdown for selecting options grouped under sections. | ||
| */ | ||
| export default class GroupSelect extends Component { | ||
| static propTypes = { | ||
| defaultOption: PropTypes.array, | ||
| onChange: PropTypes.func, | ||
| options: PropTypes.object, | ||
| placeholder: PropTypes.string, | ||
| value: PropTypes.string | ||
| }; | ||
| static defaultProps = { | ||
| defaultOption: null, | ||
| placeholder: null | ||
| }; | ||
| render() { | ||
| return ( | ||
| <select onChange={this.onChange} role="input" value={this.props.value}> | ||
| {this.props.placeholder !== null ? ( | ||
| <option disabled hidden selected> | ||
| {this.props.placeholder} | ||
| </option> | ||
| ) : null} | ||
| {this.props.defaultOption !== null ? ( | ||
| <option key={this.props.defaultOption[0]} value={this.props.defaultOption[0]}> | ||
| {this.props.defaultOption[1]} | ||
| </option> | ||
| ) : null} | ||
| {Object.entries(this.props.options || {}).map(([title, options], index) => ( | ||
| options && options.length > 0 ? ( | ||
| <optgroup key={"optgroup-" + index} label={title}> | ||
| {options.map(([value, description]) => ( | ||
| <option key={value} value={value}>{description}</option> | ||
| ))} | ||
| </optgroup> | ||
| ) : null | ||
| ))} | ||
| </select> | ||
| ); | ||
| } | ||
| onChange = (e) => { | ||
| this.props.onChange(e.target.value); | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.