I am using maps and backbone.js together. Map JS library used is Leaflet, but Google maps API will apply here as well.
Problem: Backbone.js allows us to seperate the presentation (Views) from the data (Models, Collections). When using Google Maps JS API or Leaflets, we do not seem to have control over the rendering of the markers, thus unable to have a Backbone View for each marker. Is this true?
When using Maps together with backbone.js, I start to get nested views and event handlers in the callback functions.
JS (Leaflet, similar to Google Maps API)
// Handle a dragging on the map
map.on('dragend', function() {
App.markersList.fetch(
data: someData,
processData: true
function() {
App.markersListView.render();
};)
});
// Handle a click on a Marker
map.on('popupopen', function() {
// Activate bootstrap tabs
$('#tabs').tab();
// Submit click handler
$('#submit-button').click(function() {
$.post('/api/submit-something',
{data: data},
function() {
// Remove some divs
$('#some-divs').fadeOut();
})
})
// Activate slideshow
Galleria.loadTheme('/js/vendor/galleria.miniml.min.js');
Galleria.configure({
height: 320
});
Galleria.run('#galleria');
// Validation
$('.email-link form').validate({
rules: { ... }
});
});
Well you get the idea... I need to do these outside of Backbone's MVC structure. I could be missing out on the correct way to integrate both together. Any ideas? Thanks!!