Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor google地图显示标记取决于复选框过滤器_Javascript_Google Maps_Meteor - Fatal编程技术网

Javascript Meteor google地图显示标记取决于复选框过滤器

Javascript Meteor google地图显示标记取决于复选框过滤器,javascript,google-maps,meteor,Javascript,Google Maps,Meteor,我有一张当前显示所有标记的地图。我想在单击复选框时更新地图上的标记 要加载标记,我需要 Caves.find({$or: [{ backmount: {$exists: false}},{backmount: true}]}).observe({ 如果选中该复选框,则应将过滤器更改为 Caves.find({ backmount: false}).observe({ 我不知道如何将其放入我的代码中 这是加载标记的代码 Template.map.onCreated(function() {

我有一张当前显示所有标记的地图。我想在单击复选框时更新地图上的标记

要加载标记,我需要

Caves.find({$or: [{ backmount: {$exists: false}},{backmount: true}]}).observe({
如果选中该复选框,则应将过滤器更改为

Caves.find({ backmount: false}).observe({
我不知道如何将其放入我的代码中

这是加载标记的代码

Template.map.onCreated(function() {
  GoogleMaps.loadUtilityLibrary('js/geolocationmarker-compiled.js');
  GoogleMaps.loadUtilityLibrary('js/infobox.js');

  var markers = {};

  GoogleMaps.ready('map', function(map) {
    var latLng = currentPosition();

    Tracker.autorun(function() {
      map.instance.setCenter(new google.maps.LatLng(latLng.lat, latLng.lng));
      var GeoMarker = new GeolocationMarker(map.instance);

    });

    Caves.find({$or: [{ backmount: {$exists: false}},{backmount: true}]}).observe({
      added: function(doc) {
        var infobox = new InfoBox({
          content: $("#infobox")[0],
          disableAutoPan: false,
          pixelOffset: new google.maps.Size(-140,0),
          zIndex: null,
          infoBoxClearance: new google.maps.Size(1,1),
          boxStyle: {
            background: "url('images/tipbox.gif') no-repeat",
            opacity: 0.75,
            width: "280px"
          }
        });

        var marker = new google.maps.Marker({
          draggable: false,
          animation: google.maps.Animation.DROP,
          position: new google.maps.LatLng(doc.location.coordinates.latitude,doc.location.coordinates.longitude),
          id: doc._id,
          map: map.instance
        });

        marker.addListener('click', function() {
          infobox.open(map.instance, this);
        });

        markers[doc._id] = marker;
      },
      changed: function(newDoc, oldDoc) {
        markers[newDoc._id].setPosition({ lat: newDoc.lat, lng: newDoc.lng});
      },
      removed: function(oldDoc) {
        markers[oldDoc._id].setMap(null);

        google.maps.event.clearInstanceListeners(markers[oldDoc._id]);

        delete markers[oldDoc._id];
      }
    });

  });
});
我有一个带有复选框的模板(#sidemountOnly)


  • 仅侧面安装

非常感谢你的帮助

我可以回答我自己的问题。我使用了一个会话变量来更改子描述。一些相关代码:

创建一个事件:

Template.mapFilters.events({
  "change #sidemountOnly": function(event) {
    Session.set("sidemountOnly",event.target.checked);
  }
})
自动运行内传递到订阅

Tracker.autorun(function() {
      getBox();
      Meteor.subscribe("primaryCoordinates", Session.get('box'), Session.get('sidemountOnly'));


      var GeoMarker = new GeolocationMarker(map.instance);

    });
在服务器端的发布中创建筛选器

Meteor.publish('primaryCoordinates', function(box,sidemountOnly) {
  var filter = {};

  if(sidemountOnly) {
    filter = {backmount: false};
  } else {
    filter = {$or: [{ backmount: {$exists: false}},{backmount: true}]};
  }

  var find = { $and: [{
    location: {
      $geoWithin: {
        $box: box
      }
    }},filter]
  };

  return Caves.find(find);
});
Meteor.publish('primaryCoordinates', function(box,sidemountOnly) {
  var filter = {};

  if(sidemountOnly) {
    filter = {backmount: false};
  } else {
    filter = {$or: [{ backmount: {$exists: false}},{backmount: true}]};
  }

  var find = { $and: [{
    location: {
      $geoWithin: {
        $box: box
      }
    }},filter]
  };

  return Caves.find(find);
});