简体   繁体   English

点击时切换标记可见性

[英]Toggle markers visibility on click

I'm trying to toggle my map markers off when I click to turn a heatmap on. 当我单击以打开热图时,我试图关闭地图标记。

My markers object looks like this: 我的标记对象看起来像这样:

var markers = {
  id: id,
  displayId: displayId,
  latitude: job.geolocation.location.latitude,
  longitude: job.geolocation.location.longitude,
  icon: icon,
  options: {
    title: 'ID: ' + displayId,
    visible: showMarkers
  }

I default showMarkers to true: 我默认将showMarkers设置为true:

var showMarkers = true;

Then in my click handler for heatmap I change showMarkers to false: 然后在我的热图点击处理程序中,将showMarkers更改为false:

vm.turnOnHeat = function() {
  vm.showHeat = true;
  showMarkers = false;
};

However, the markers never disappear. 但是,标记永远不会消失。 I'm confused as to why markers.options.visible never picks up this change. 我对为什么markers.options.visible从未接受此更改感到困惑。

Because the object you are creating is only one instance object. 因为您要创建的对象只是一个实例对象。 This object is initialized only on initialization and this object is stored in memory. 仅在初始化时初始化此对象,并且此对象存储在内存中。 Whenever you access object old object instance will be used. 每当您访问对象时,都会使用旧对象实例。

make object like: 使对象像:

var makers = function(){
// code here
}

This approach may help you. 这种方法可能对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM