Skip to content

Instantly share code, notes, and snippets.

@zackham
Created November 3, 2011 19:44
Show Gist options
  • Save zackham/1337578 to your computer and use it in GitHub Desktop.
Save zackham/1337578 to your computer and use it in GitHub Desktop.
// dont worry, not doing a massive refactoring... just going to put
// new things and things i touch into this backbone view instead of
// adding to the hugely long init below
PlannerView = Backbone.View.extend({
el: $('#route_container'),
initialize: function() {
this.map = Routes.activeMap;
this.bind('jump_to:change', _.bind(this.onJumpToChange, this));
// set up places autocomplete for gi
if(rwgps.site == 'gi') {
Application.setupPlaceAutocomplete( '#jumplocation' );
var self = this;
$('#jumplocation').bind('autocompleteselect', function(e,ui) {
self.map.gotoLocation(ui.item.value, true);
self.trigger('jump_to:change');
});
}
},
events: {
'click .remove_jump_to_marker': 'removeJumpToMarker',
// jump to location str
'keypress #jumplocation': 'jumpToLocationOnEnter',
'click #jumpbutton': 'jumpToLocation',
// jump to lat lng
'click .jump_to_lat_lng_toggle a': 'toggleJumpToLatLng',
'keypress #jump_to_lat_lng input': 'jumpToLatLngOnEnter',
'click #jump_to_lat_lng_button': 'jumpToLatLng',
'click .route_to_point': 'routeToPoint'
},
// make sure the right things are visible
onJumpToChange: function() {
if(this.jumpToMarker)
$('.remove_jump_to_marker').show();
else
$('.remove_jump_to_marker').hide();
},
onJumpSuccess: function(marker) {
this.removeJumpToMarker();
this.jumpToMarker = marker;
this.trigger('jump_to:change');
},
jumpToLocationOnEnter: function(e) {
if(e.keyCode == 13) this.jumpToLocation();
},
jumpToLocation: function() {
var locationStr = $('#jumplocation').val();
this.map.gotoLocation(locationStr, true).done(_.bind(this.onJumpSuccess, this));
},
toggleJumpToLatLng: function() {
$('#jump_to_lat_lng').toggle();
},
jumpToLatLngOnEnter: function(e) {
if(e.keyCode == 13) this.jumpToLatLng();
},
jumpToLatLng: function() {
var lat = $('#jumplat').val(),
lng = $('#jumplng').val(),
marker = this.map.gotoLatLng(lat, lng, true);
this.onJumpSuccess(marker);
},
removeJumpToMarker: function(e) {
if(this.jumpToMarker) {
this.jumpToMarker.setMap(null);
delete this.jumpToMarker;
}
this.map.closeStickyInfoWindow();
this.trigger('jump_to:change');
},
routeToPoint: function(e) {
var point = this.jumpToMarker.position;
this.map.onClickAddPoint({latLng: point});
this.removeJumpToMarker();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment