-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add point/polygon toggle to map search (#343)
* add polygon toggle to map search * persist setting in localStorage * make ternaries consistent * use constants
- Loading branch information
1 parent
d237415
commit 32f53c2
Showing
6 changed files
with
220 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,41 @@ | ||
// @flow | ||
|
||
const SESSION_DEFAULT = '{ "geocoding": "point" }'; | ||
|
||
/** | ||
* Restores the map session from the passed storage object. | ||
* | ||
* @param key | ||
* @param storage | ||
* | ||
* @returns {{}|any} | ||
*/ | ||
const restoreSession = (key, storage) => { | ||
if (!(key && storage)) { | ||
return {}; | ||
} | ||
|
||
const session = storage.getItem(key) || SESSION_DEFAULT; | ||
return JSON.parse(session); | ||
}; | ||
|
||
/** | ||
* Sets the passed map session on the passed storage object. | ||
* | ||
* @param key | ||
* @param storage | ||
* @param session | ||
*/ | ||
const setSession = (key, storage, session) => { | ||
if (!(key && storage)) { | ||
return; | ||
} | ||
|
||
const currentSession = restoreSession(key, storage); | ||
storage.setItem(key, JSON.stringify({ ...currentSession, ...session })); | ||
}; | ||
|
||
export default { | ||
restoreSession, | ||
setSession | ||
}; |
Oops, something went wrong.