mirror of
https://github.com/Ekokumppanit/Lentolaskuri.git
synced 2026-02-09 21:45:20 +00:00
Initial commit
This commit is contained in:
41
app/scripts/views/map.js
Normal file
41
app/scripts/views/map.js
Normal file
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
define([
|
||||
'backbone',
|
||||
'libs/maps'
|
||||
], function (Backbone, Maps) {
|
||||
|
||||
var MapView = Backbone.View.extend({
|
||||
el: '#gmap',
|
||||
initialize: function () {
|
||||
this.collection.on('sort', this.render, this);
|
||||
this.collection.on('remove', this.render, this);
|
||||
this.collection.on('add', this.add, this);
|
||||
|
||||
this.map = new Maps.Map(this.el);
|
||||
|
||||
this.route = new Maps.Line({
|
||||
geodesic: true,
|
||||
map: this.map,
|
||||
strokeColor: '#000'
|
||||
});
|
||||
|
||||
this.bounds = new Maps.Bounds(this.map);
|
||||
},
|
||||
render: function () {
|
||||
this.route.clear();
|
||||
this.bounds.clear();
|
||||
this.collection.forEach(this.route.add);
|
||||
this.collection.forEach(this.bounds.add);
|
||||
this.bounds.use();
|
||||
},
|
||||
add: function (model, collection, options) {
|
||||
this.route.add(model);
|
||||
this.bounds.add(model);
|
||||
this.bounds.use();
|
||||
}
|
||||
});
|
||||
|
||||
return MapView;
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user