【发布时间】:2016-06-17 20:40:48
【问题描述】:
我正在尝试对存储在 mongoDB 中的 5m 点进行聚类。 1 个查询的最大结果目前只有 1m 左右,所以我决定使用:PruneCluster 作为第一个视觉效果。点存储为 geoJSON 对象,并有一个 2dsphere 索引。
我使用本机 node.js 驱动程序连接到 mongodb 并查询以查找多边形内的点,这只会从集合和路由结果中返回 loc 字段以供预览:
router.get('/map', function(resq,res) {
var MongoClient = mongodb.MongoClient;
var url = 'mongodb://localhost:27017/airboost';
MongoClient.connect(url, function(err, db) {
if(err){
console.log('Unable to connect to db ', err);
} else {
console.log('Connected!!!');
var collection = db.collection('listingsF');
collection.find({
loc: {
$geoWithin: {
$geometry: {
type : "Polygon" ,
coordinates: [[[121.48521363894814,31.41360430073249],[...],[121.48865692654915,31.41168940543709]]]
}
}
}
},{loc:1}).toArray(function(err, result){
if (err) {
res.send(err);
} else if (result.length) {
res.send(result);
} else {
res.send('Nothing found');
}
db.close();
});
}
});
});
我得到一个这样的对象列表:
[
{
"_id": "567f972bad55ac0797baa75b",
"loc": {
"type": "Point",
"coordinates": [
-85.84556526181,
10.29620625503
]
}
},
{
"_id": "567f972bad55ac0797baa75c",
"loc": {
"type": "Point",
"coordinates": [
-54.943878777465,
-34.964002797642
]
}
}
]
然后我需要以某种方式传递该结果以在 /public 文件夹中的脚本中运行,这样我就可以在传单地图上显示集群:
var pruneCluster = new PruneClusterForLeaflet();
...
var marker = new PruneCluster.Marker(latitude, longitude);
pruneCluster.RegisterMarker(marker);
...
leafletMap.addLayer(pruneCluster);
我可以以任何我想要的方式用玉打印内容,但我不知道如何将所有 mongodb 数据作为标记传递给 PruneCluster。我不需要完整的代码,只是指向一个方向。有人可以帮我吗?
【问题讨论】:
标签: javascript node.js mongodb express pug