2

已经为此工作了一周,并且可以提供一些指导:

需要使用两列复选框来过滤地图上的标记。
第 1 列是:data.ConType
第 2 列是:data.Operator

我需要它来检查复选框并仅返回与勾选框的两列标准匹配的标记。

我已经让它在第一列上工作,并尝试使用 && 函数让它读取第二列并匹配,但到目前为止它不起作用。
这是 show 函数的工作部分:

// === Store the category and name info as a marker properties ===
      marker.mycategory = data.ConType;
      marker.myname = data.Name;
      marker.myoperator = data.Operator,
      gmarkers.push(marker);
      // end Looping through the JSON data
      <!-- Map traffic begin -->
      (function (marker, data) {
          // Attaching a click event to the current marker
          google.maps.event.addListener(marker, 'click', function(e) {}); // end Attaching a click event to the current marker
          })(marker, data); // end Creating a closure

      }
} // end of initialize function

// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(category) {
  for (var i=0; i<gmarkers.length; i++) {
    if (gmarkers[i].mycategory == category) {
      gmarkers[i].setVisible(true);
    }
  }
  // == check the checkbox ==
  document.getElementById(category+"box").checked = true;
}

// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(category) {
  for (var i=0; i<gmarkers.length; i++) {
    if (gmarkers[i].mycategory == category) {
      gmarkers[i].setVisible(false);
    }
  }
  // == clear the checkbox ==
  document.getElementById(category+"box").checked = false;
  // == close the info window, in case its open on a marker that we just hid
  infoBubble.close();
}

// == a checkbox has been clicked ==
function boxclick(box,category) {
  if (box.checked) {
    show(category);
  } else {
    hide(category);
  }
  // == rebuild the side bar
  makeSidebar();
}

function myclick(i) {
  google.maps.event.trigger(gmarkers[i],"click");
}

有没有人有这种工作标准的任何指针或工作网页/jsfiddle/GitHub?

4

0 回答 0