I want to run code in a Template.foo.rendered only once. I have a Leaflet map and a locate-control plugin integrated. It works quite good so far but it seems the rendered template is rerun frequently. So my marker for locating the user on the map is reset every few seconds. I just want to initialize it once.
var map, mapInit;
map = void 0;
mapInit = function (element){
map = L.mapbox.map(element, 'examples.map-20v6611k').setView(new L.LatLng(52.02312,13.02627), 11);
L.control.locate({drawCircle: true, position: 'topright'}).addTo(map);
}
Template.map.rendered = function () {
$(window).resize(function () {
var h = $(window).height();
$mc = $('#map');
$mc.css('height', h);
}).resize();
if (!this.rendered) {
mapInit('map');
this.rendered = true;
}
}