I am making other method calls from onRendered that remove db records and they work as expected. The reason I am calling from onRendered is because there is no user interaction at all - it is meant to be fully automated.
I cannot go into too much detail as this is a research project for my company, but essentially this is a data visualization (heat map) app that will eventually update from live data transmitted from a drone.
Functionally, the drone gathers data, packages it as small data.json file and transmits it via POST to the meteor app. The json data is saved to a mongodb collection, âTagsâ. That json data is then written to the filesystem and is the input to the sar_server.py script referenced in the previous code snippet, which generates a 200x200 array of data points and stores that in the maps collection which is used to generate the heat map. As new data comes in, the heat map has to update without user interaction, hence calling from onRendered instead of a user-initiated event.
The method call in question is triggered by the insertion of the data.json object into the tags collections as such:
var handle = Tags.find().observeChanges({
added(newDoc) {
// DEBUG
console.log('tag: ', newDoc);
// get latest record from db
var thisTag = Tags.findOne({}, { sort: { _id: -1 }, limit: 1 });
var x = thisTag.tag.groundtruth.position_x;
var y = thisTag.tag.groundtruth.position_y;
// call server method to create heatmap data
Meteor.call('mapUpdate', function(error, result) {
if (error) throw error;
// get map db entry
var thisMap = Maps.findOne({ _id: 'rfid1' });
var map = thisMap.map;
// json to csv
var csv = Papa.unparse(map, {
newline: '\r\n',
dynamicTyping: true
});
// create heatmap
createHeatmap(csv, x, y);
// remove tag from db
Meteor.call('removeTag', thisTag._id);
});
}
});
The template is very simple:
<template name="heatmap">
<div id="rfid-heatmap"></div>
</template>
It is just a div that holds a d3js map.
Again, it all âworksâ except for the map data not being committed to the maps collection without a browser reload.
It is important to note that the method call âremoveTagâ functions exactly as it should, removing the record and committing the change immediately. Itâs just the âmapUpdateâ call that doesnât commit.
Any suggestions on how I can make this work without user interaction would be greatly appreciated.
-k