Permalink
Browse files

ensure index added, basics of browse mode work

  • Loading branch information...
bmcmahen committed Mar 25, 2013
1 parent e2c9a2d commit 2906dbb9567cde0ee11790f5c06a2c3dca8d3379
@@ -268,6 +268,12 @@
'click .back' : function(){
Session.set('editingFeature', null);
+ },
+
+
+ 'click .trailorigin' : function(e, t){
+ console.log('hi??');
+ Session.set('promptInput', 'selectTrailhead');
}
});
@@ -298,15 +304,6 @@
'click .feature-instance' : function(e, t){
Session.set('selectedFeature', this._id);
Trailmix.map.highlightFeature(this._id);
- },
-
- 'click .trailorigin' : function(e, t){
- // On the map, show directions for the user.
- // i.e., 'Click to select trail origin'.
- // Also set our map object to 'listen'
- // for a click, and then update our map
- // with that that location.
- Session.set('editMap', 'trail-origin');
}
});
@@ -76,17 +76,19 @@ Trailmix.behaviors.observeBoundsChanges = function(context){
onBoundsChange: function(e) {
var bounds = context.map.getBounds(),
boundObject = {
- sourthWest: [ bounds._southWest.lat, bounds._southWest.lng ],
+ southWest: [ bounds._southWest.lat, bounds._southWest.lng ],
northEast: [ bounds._northEast.lat, bounds._northEast.lng ]
};
- if (MapBounds.find().count() > 1) MapBounds.insert(boundObject);
+ console.log(boundObject);
+ if (MapBounds.find().count() < 1) MapBounds.insert(boundObject);
else MapBounds.update({}, boundObject);
context.browseLocation = context.map.getCenter();
context.browseZoom = context.map.getZoom();
},
on : function(){
+ this.onBoundsChange();
context.map.on('moveend', this.onBoundsChange);
},
@@ -117,15 +119,40 @@ Trailmix.behaviors.geoLocate = function(context){
Trailmix.behaviors.selectOrigin = function(context){
return {
onClick: function(e){
- console.log('clicked here', e);
+ Trails.update({_id: Session.get('currentTrail')}, {
+ '$set' : { coordinates : [e.latlng.lat, e.latlng.lng] }
+ });
+ Session.set('promptInput', null);
},
on: function(){
context.map.on('click', this.onClick);
+ $(window).on('keyup', function(e){
+ if (e.keyCode === 27)
+ Session.set('promptInput', null);
+ });
},
off : function() {
context.map.off('click', this.onClick);
+ $(window).off('keyup');
}
};
};
+
+Trailmix.behaviors.displayMessage = function(message, context){
+ return {
+ $el : $('#map'),
+ template: function(message){
+ return "<div id='message'><p>"+message+"</p></div>";
+ },
+ on: function(){
+ this.$el.addClass('display-message');
+ this.$el.append(this.template(message));
+ },
+ off: function(){
+ this.$el.removeClass('display-message');
+ this.$el.find('#message').remove();
+ }
+ };
+};
@@ -15,9 +15,11 @@ Trailmix.MapView = (function(){
this.idToFeatures = {};
this.modes = {
detail : new Trailmix.modes.Detail(this),
- browse : new Trailmix.modes.Browse(this)
+ browse : new Trailmix.modes.Browse(this),
+ selectTrailhead: new Trailmix.modes.SelectTrailhead(this)
};
- this.determineMapMode();
+ this.determineMapMode().promptInput();
+
};
_.extend(MapView.prototype, {
@@ -43,18 +45,31 @@ Trailmix.MapView = (function(){
else if (Session.equals('mapView', 'browse'))
_this.enterMode('browse');
});
+ return this;
+ },
+
+ promptInput: function(){
+ var _this = this;
+ if (this.promptUserInput) this.promptUserInput.stop();
+
+ this.promptUserInput = Meteor.autorun(function(){
+ var input = Session.get('promptInput');
+
+ if (!input && _this.prompt) {
+ _this.prompt.exit();
+ delete _this.prompt;
+ } else if (input) {
+ if (_this.prompt) _this.prompt.exit();
+ var mode = _this.modes[input];
+ mode.enter();
+ _this.prompt = mode;
+ }
+
+ });
+ return this;
},
- // TODO: Modes aren't necessarily mutually exclusive.
- // If we are editing, for instance, we will be in 'detail' mode.
- // If we are switching between detail, and browse, then we
- // should reset our modes. This means we should probably
- // keep an array of modes, and iterate through each, exiting
- // each mode if need be.
- // Otherwise we could:
- // (1) Session.set('mapView', 'detail');
- // (2) Session.set('mapView', 'origin');
- // How do we _exit_ modes, then?
+ // How should we handle mutual exclusivity of these?
enterMode: function(name){
if (this.mode && name !== 'drawing') this.mode.exit();
console.log(this);
@@ -51,11 +51,13 @@
return mode;
};
- Trailmix.modes.UserInput = function(context){
+ Trailmix.modes.SelectTrailhead = function(context){
+ var message = 'Click to Select the Primary Trailhead';
var mode = {
context: context,
behaviors: [
- Trailmix.behaviors.selectOrigin(context)
+ Trailmix.behaviors.selectOrigin(context),
+ Trailmix.behaviors.displayMessage(message, context)
]
};
_.extend(mode, modeFunctions);
@@ -1,6 +1,7 @@
(function(Trailmix){
-
+ // Our Sidebar should change views if we are in browse
+ // mode, or detail mode.
Template.sideBar.helpers({
browsingView : function() {
return Session.equals('mapView', 'browse');
@@ -10,6 +11,7 @@
}
});
+ // Enter editing mode.
Template.detailView.events({
'click .edit-trail' : function(){
Session.set('isEditing', true);
@@ -51,7 +53,7 @@
Session.set('mapView', 'detail');
Session.set('currentTrail', this._id);
}
- })
+ });
@@ -57,3 +57,26 @@
border-top none
border-bottom none
display none
+
+#message
+ position absolute
+ left 0
+ right 0
+ top 10px
+ pointer-events none
+
+ & p
+ margin 0 auto
+ background rgba(50, 153, 102, 0.74)
+ top 0
+ left 0
+ width 400px
+ text-align center
+ line-height 35px
+ border-radius 3px
+ color white
+ font-size 15px
+ font-weight bold
+ font-family 'open sans condensed'
+ text-shadow 0 1px 1px rgba(0,0,0, 0.3)
+ height 35px
@@ -83,8 +83,9 @@ <h2>
<i class='icon icon-screenshot'></i>
Select Trailhead
</button>
- {{#if this.trailhead}}
- <span> trailhead </span>
+ {{#if this.coordinates}}
+ <span> Lat: {{this.coordinates.[0]}} </span>
+ <span> Lng: {{this.coordinates.[1]}} </span>
{{/if}}
</div>
<label> Description
View
@@ -2,51 +2,36 @@
/**
*
* Collections
- *
+ *
*/
Features = new Meteor.Collection('features');
Trails = new Meteor.Collection('trails');
+/**
+ * Ensure Indexes
+ */
Meteor.startup(function(){
- // Ensure index, and our 'trails' publish function will
- // be linked to the current mapBounds(), which will initially
- // be set based on geoLocation.
- //
- // The reactive datasource (local collection?) inside of our subscribe function
- // will be an array containing the current bounds of the
- // map. As our map changes, we will update this reactive
- // data source, which will update our subscription, which will
- // draw the newly received trails onto the map, and remove
- // the ones no longer on the map.
- //
- // We'll use the marker cluster to avoid bazilions of
- // trails appearing on the map at once. We should probably also
- // limit our subscription to a certain number of trails,
- // so as not to kill our app.
- //
- // Trails._ensureIndex({'coordinates': '2d'});
- // var results = Trails.find({'coordinates': {'$within' : { '$box' : [[0,0], [3,3]]}}}).fetch();
- // find({coordinates[0]})
-
+ Trails._ensureIndex({coordinates: '2d'});
});
+
/**
*
* Publish
- *
+ *
*/
-// Only publish features that belong to a specific trail.
+// Only publish features that belong to a specific trail.
Meteor.publish('features', function(trailId){
return Features.find({ trail: trailId });
});
// Publish those trails within the bounds of the map view.
Meteor.publish('trails', function(bounds){
if (bounds && bounds.southWest && bounds.northEast) {
- return Trails.find({'coordinates': {'$within' :
+ return Trails.find({'coordinates': {'$within' :
{ '$box' : [bounds.southWest, bounds.northEast] }
}}, {
limit: 100

0 comments on commit 2906dbb

Please sign in to comment.