Created
October 7, 2012 21:39
-
-
Save jyr/3849690 to your computer and use it in GitHub Desktop.
example backbone render map
This file contains hidden or 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
Backbone.js Events not firing | |
MapModalView = Backbone.View.extend({ | |
events: { | |
'click #closeMapModal': 'closeModal', | |
'click #modal_streetview': 'renderStreet' | |
}, | |
initialize: function(){ | |
this.el = $('.modal_box'); | |
this.template = _.template($('#map-modal-template').html()); | |
_.bindAll(this, 'renderMap', 'renderPin'); | |
}, | |
render: function(){ | |
$(this.el).show().append(this.template({ | |
model: this.model | |
})); | |
this.renderMap(); | |
this.renderPin(); | |
}, | |
renderMap: function(){ | |
this.thisLat = _this.model.get('lat'); | |
this.thisLng = _this.model.get('lng'); | |
this.modalMap = new google.maps.Map(document.getElementById('modalMap'), { | |
zoom : 12, | |
center : new google.maps.LatLng(this.thisLat, this.thisLng), // VANCOUVER | |
mapTypeId : google.maps.MapTypeId.ROADMAP | |
}); | |
}, | |
renderPin: function(){ | |
marker = new google.maps.Marker({ | |
position : new google.maps.LatLng(this.thisLat, this.thisLng), | |
map : this.modalMap, | |
animation : google.maps.Animation.DROP, | |
icon : '/img/lazy-pin.png' | |
}); | |
}, | |
renderStreet: function(e){ | |
e.preventDefault(); | |
this.modalMap.getStreetView().setPosition(this.modalMap.center); | |
this.modalMap.getStreetView().setVisible(true); | |
}, | |
closeModal: function(e){ | |
alert('hello'); | |
e.preventDefault(); | |
$(this.el).hide().find('div').remove(); | |
} | |
this.mapModalView = new MapModalView(); | |
ToolTipView = Backbone.View.extend({ | |
initialize: function() { | |
this.template = _.template($('#toolTip').html()); | |
this.mapTemplate = _.template($('#map-modal-template').html()); | |
this.model.bind('change:tooltip', this.toggleTooltip, this); | |
return this; | |
}, | |
events: { | |
'mouseenter': 'toolTipOn', | |
'mouseleave': 'toolTipOff', | |
'click #show-restaurant-map': 'mapModal' | |
}, | |
mapModal: function(){ | |
router.mapModalView.render(this.model); | |
}, | |
render: function() { | |
$(this.el).html(this.template({ | |
model: this.model | |
})); | |
this.delegateEvents(); | |
return this; | |
} | |
<script type="text/template" id="map-modal-template"> | |
<div id="map_modal"> | |
<button title="Close" id="closeMapModal" class="right">Close</button> | |
<h3>Restaurant Map & Access Information</h3> | |
<ul> | |
<li><a href="#" title="Map View" id="modal_mapview">Map</a></li> | |
<li><a href="#" title="Street View" id="modal_streetview">Street View</a></li> | |
<li><a href="#" title="Parking & Access Info" id="modal_parking">Parking & Access Info</a></li> | |
</ul> | |
<div id="modalMap"></div> | |
</div> | |
</script> | |
<div class="modal_box"></div> | |
render: function() { | |
$(this.el).show().append(this.template({ | |
model: this.model | |
})); | |
this.renderMap(); | |
this.renderPin(); | |
this.delegateEvents(); | |
}, | |
MapModalView = Backbone.View.extend({ | |
//... | |
_this: this, | |
_.bindAll(this, 'renderMap, 'renderPin'); | |
this.el = $('.modal_box'); | |
initialize: function() { | |
this.el = '.modal_box'; | |
this.$el = $(this.el); | |
//... | |
MapModalView = Backbone.View.extend({ | |
el: '.modal_box', | |
//... | |
m = new MapModalView({el: '.modal_box'}); | |
m.render(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment