Skip to content

Commit

Permalink
Use reactive-var for mapBounds object storing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Kabalin authored and kabalin committed Feb 3, 2019
1 parent 18ed27e commit 75aabc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ aldeed:autoform
alanning:roles
accounts-admin-ui-bootstrap-3
jeremy:geocomplete
reactive-var
15 changes: 10 additions & 5 deletions client/templates/locations/locations_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Template.locationsPage.helpers({
});

Template.locationsPage.onRendered(function() {
var self = this;
var instance = this;
this.autorun(function(c) {
if (GoogleMaps.loaded()) {
var searchLocationInput = self.$('.search-locations-input');
var searchLocationInput = instance.$('.search-locations-input');
var mapProperties = {
map: self.$('.map-container'),
map: instance.$('.map-container'),
mapOptions: {
zoom: 12,
scrollwheel: true,
Expand All @@ -31,7 +31,7 @@ Template.locationsPage.onRendered(function() {
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
var boundsObject = {ne: {lng: ne.lng(), lat: ne.lat()}, sw: {lng: sw.lng(), lat: sw.lat()}};
Session.set('mapBounds', boundsObject);
instance.mapBounds.set(boundsObject);
}
});
c.stop();
Expand All @@ -40,14 +40,19 @@ Template.locationsPage.onRendered(function() {
});

Template.locationsPage.onCreated(function() {
// Init Googlemaps.
GoogleMaps.load({
libraries: 'places'
});

var instance = this;

// Init reactive var.
instance.mapBounds = new ReactiveVar({});

instance.autorun(function () {
// Subscribe to the locations publication.
var subscription = instance.subscribe('locations', Session.get('mapBounds'));
var subscription = instance.subscribe('locations', instance.mapBounds.get());
});
// Locations cursor.
instance.locations = function() {
Expand Down

0 comments on commit 75aabc9

Please sign in to comment.