Got this to work by being able to monitor the $within cursor using http://blog.benmcmahen.com/post/48367809759/meteors-reactive-data-sources
Meteor.js - mongodb - Leaflet.js - geo query from client to server - $within $box refresh - stack call size exceeded
Вопрос
So I have a Meteor.js project with a 'server' and a 'client' folders. In there I have a leaflet.js map.
Inside server.js I have a query to only show markers within a certain bounding box. This works fine. I am trying to update this marker when a map is moved to encompass the map's bounding box.
in ./server/server.js I have some startup methods:
Meteor.startup(function () {
Meteor.methods({
buildCollections: function() {
Locations = new Meteor.Collection('locations');
Locations._ensureIndex({'geometry.coordinates':'2dsphere'});
},
testStub: function(tst) {
console.log("test stub");
return tst;
},
showBoundingBox: function(mapBox) {
return Locations.find({
'geometry.coordinates': {
$within:{
$box:mapBox
}
}
});
}
});
Meteor.call('buildCollections');
});
The showBoundingBox method is called by the server on publishing the collection:
Meteor.publish('locations', function() {
mapBox= [ [151.190,-33.94]
,[151.2,-33.84]] ;
return Meteor.call('showBoundingBox',mapBox);
});
This all works ok until I want to sent a different bounding box based on the map bounding box when the Leaflet map has been moved:
So in my ./client/client.js I want to call the server method to update the visible markers so I call the server method:
window.map.on('moveend', function(e) {
var b = window.map.getBounds();
var bounds=[[b._southWest.lng,
b._southWest.lat],
[b._northEast.lng,
b._northEast.lat]
];
Meteor.call('testStub',"echoing back to the client",
function(error,result){
if(error)
{
console.log(error.reason);
}else
{
console.log(result);
}
});
Meteor.call('showBoundingBox',bounds,
function(error,result){
if(error)
{
console.log(error.reason);
}else
{
console.log(result);
}
});
});
Now the testStub method returns the string back to the client, but the showBoundingBox method crashes Meteor with the error:
Internal exception while processing message{ msg: 'method',
method: 'showBoundingBox',
params: [ [Object], [Object] ] ],
id: 'n' } Maximum call stack size exceeded undefined
Where n is an incremented numerical index.
I am trying to update the $within query to a new set of coordinates when a map has been moved. Is this a legitimate bug? Is there another way I can achieve this?
Решение