Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Save map center in cookie for next visiting
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonackermann committed May 2, 2017
1 parent 2b9e214 commit e0d3ae5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/stores/MapStore.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Cookies from 'js-cookie';

/**
* Stores settings for the map like current zoom state, the center
* Also contains the leaflet node (this.noe) to retrieve leaflet functions
Expand All @@ -9,11 +11,13 @@ class MapStore {
this.node = null;

this.config = {
// center of the map (51.3412, 12.3747 is center of Leipzig)
center: {
latitude: 51.3412,
longitude: 12.3747
},
// center of the map, get from cookie or use center of leipzig (51.3412, 12.3747)
center: Cookies.get('mapCenter') !== undefined
? JSON.parse(Cookies.get('mapCenter'))
: {
latitude: 51.3412,
longitude: 12.3747
},
// zoom value, the greater the value, the closer the zoom
zoom: 14,
// bounds of the map from upper right to bottom left, will initiated after loading the map
Expand Down Expand Up @@ -83,6 +87,10 @@ class MapStore {
* @param {Float} New longitude value
*/
updateCenter(newLatitude, newLongitude) {
Cookies.set('mapCenter', {
latitude: newLatitude,
longitude: newLongitude
}, { expires: 30 });
this.update('center', {
latitude: newLatitude,
longitude: newLongitude
Expand Down

0 comments on commit e0d3ae5

Please sign in to comment.