我无法使用聚合管道限制组函数中推送元素的数量.这可能吗?小例子:
数据:
[
{
"submitted": date,
"loc": {
"lng": 13.739251,
"lat": 51.049893
},
"name": "first",
"preview": "my first"
},
{
"submitted": date,
"loc": {
"lng": 13.639241,
"lat": 51.149883
},
"name": "second",
"preview": "my second"
},
{
"submitted": date,
"loc": {
"lng": 13.715422,
"lat": 51.056384
},
"name": "nearpoint2",
"preview": "my nearpoint2"
}
]
Run Code Online (Sandbox Code Playgroud)
这是我的聚合管道:
var pipeline = [{
//I want to limit the data to a certain area
$match: {
loc: {
$geoWithin: {
$box: [
[locBottomLeft.lng, locBottomLeft.lat],
[locUpperRight.lng, locUpperRight.lat]
] …
Run Code Online (Sandbox Code Playgroud) 我已经将地图api包含在我的项目中.现在我想在我的地图上显示一些标记.我在启动函数中初始化我的地图:
Meteor.startup(function() {
...
var mapOptions = {
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
Map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
Run Code Online (Sandbox Code Playgroud)
比我在渲染时设置地图的中心
Template.mapPostsList.rendered = function() {
var p2 = Session.get('location');
Map.setCenter(new google.maps.LatLng(p2.lat, p2.lng));
var marker = new google.maps.Marker({
position: new google.maps.LatLng(p2.lat, p2.lng),
title:'Meine Position'
});
marker.setMap(Map);
Run Code Online (Sandbox Code Playgroud)
直到现在一切正常.尽管我有一个PostCollection,其中包含一些坐标.我有一个发布和订阅功能.现在我想通过地图上的标记显示我的帖子.
我的第一个想法是在我的渲染函数中执行此操作.问题是在初始加载时没有显示帖子,因为我的localcollection(clientside)不包含任何帖子.从服务器加载帖子需要一些时间.
这就是我试图建立一个辅助功能的原因.因为如果帖子中的某些内容发生变化,帮助程序会自动显示.
Template.mapPostsList.helpers({
posts: function() {
var allPosts = Posts.find();
allPosts.foreach(function(post) {
create marker and attach it to the map
....
marker.setMap(Map);
})
Run Code Online (Sandbox Code Playgroud)
问题是,我的地图变量没有定义.有没有办法在全球范围内定义它?为什么我可以在渲染函数中使用Map变量?尽管我不喜欢我的方法用辅助功能注射我的标记,还是通常的方式?
有人能给我提示如何解决我的问题吗?
我正在使用带有MarkerClustererPlus的Google Maps v3.点击文档
如果群集包含特定标记,我想为群集设置动画.如果标记不在群集内,则动画非常容易.
marker.setAnimation(google.maps.Animation.BOUNCE);
Run Code Online (Sandbox Code Playgroud)
但我想反弹整个群集图标.我可以通过以下方式获得群集:
markerCluster.getClusters();
Run Code Online (Sandbox Code Playgroud)
但是我如何将cluster-div与我的getClusters() - Array相关联?我不知道哪个div属于getClusters()函数中的哪个集群.
我想知道,WebRTC在通过数据通道发送数据时会产生多少开销.我知道Websockets每帧的开销为2-14个字节.WebRTC是否使用更多的开销?我在网上找不到一些有用的信息.对我来说很清楚,Datachannels目前还不能使用.Mediastreams使用了多少开销?
谢谢
对于我的项目,我需要谷歌地图API.我只是可以通过脚本标签服务api,所以我尝试了类似的东西.
我的HTML:
<head>
<title>app</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<div id="map-canvas"/>
</template>
Run Code Online (Sandbox Code Playgroud)
我的js:
if (Meteor.isClient) {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
Run Code Online (Sandbox Code Playgroud)
执行时错误是:未捕获的ReferenceError:未定义谷歌
我怎样才能使这个工作?