gpt4 book ai didi

javascript - 在 Meteor.js 中使用 forEach 生成传单标记

转载 作者:行者123 更新时间:2023-11-28 08:38:18 26 4
gpt4 key购买 nike

我正在尝试使用我通过 Meteorite 添加的 Meteor 和 leaflet 包为数据库中的每个地理标记生成一个标记。

我一直在弄乱以下代码,但似乎没有任何效果:

Geoposts = new Meteor.Collection("geoposts");

Geoposts.insert(
{"location":
{"latitude": "40.4417",
"longitude": "-80.000"},
"message": "Hi, I am a message."}
);

if (Meteor.isClient) {
Template.sites.rendered = function() {
// create a map in the "map" div, set the view to a given place and zoom
var map = L.map('map').setView([40.4417, -80.0000], 13);

// add an OpenStreetMap tile layer
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

// add a marker in the given location, attach some popup content to it and open the popup
var myIcon = L.icon({
iconUrl: 'packages/leaflet/images/marker-icon.png',
shadowUrl: 'packages/leaflet/images/marker-shadow.png',
});

var coordForPin = Geoposts.find({location:{latitude:{}}, longitude:{}});
coordForPin.forEach(function(){
L.marker([coordForPin], {icon: myIcon}).addTo(map);
});
}};

if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
})};

如果有人能提供帮助,我们将不胜感激!谢谢!!

最佳答案

cursor.forEach 的回调参数应该采用并使用该文档作为参数。另外,如果您的 Geoposts 集合不是静态的,请考虑 observing您的光标可以 react 性地添加/删除/更改 map 标记,而不是使用 forEach

关于javascript - 在 Meteor.js 中使用 forEach 生成传单标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20816673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com