【问题标题】:Generating leaflet markers with forEach in Meteor.js在 Meteor.js 中使用 forEach 生成传单标记
【发布时间】:2014-01-15 23:44:00
【问题描述】:

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

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

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
  })};

如果有人可以提供帮助,将不胜感激!谢谢!!

【问题讨论】:

    标签: javascript mongodb meteor leaflet meteorite


    【解决方案1】:

    cursor.forEach 的回调参数应该使用文档作为参数。此外,如果您的 Geoposts 集合不是静态的,请考虑使用 observing 您的光标以反应方式添加/删除/更改地图标记,而不是使用 forEach

    【讨论】:

      猜你喜欢
      • 2014-02-16
      • 1970-01-01
      • 2014-09-06
      • 1970-01-01
      • 2020-12-14
      • 2014-10-22
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      相关资源
      最近更新 更多