根据传单js基本地图选择显示div元素

时间:2019-02-08 18:52:11

标签: javascript jquery leaflet

我的传单地图上有多个基本图层。我还创建了与每个​​图层对应的div元素。我需要根据实际使用的基本层来显示和隐藏那些div元素。我不希望页面上的所有div元素都模拟。

我尝试使用jQuery .show()和.hide()和.toggle(),但无法使其正常工作。我需要默认隐藏我的.cuomoinfo和.nixoninfo,然后根据正在使用的基本层进行显示。

var baselayers = {
    "Andrew Cuomo Votes": CuomoLayer,
    "Cynthia Nixon Votes": NixonLayer,
    "Total Votes Cast": totalvotecountlayer,
  };

var overlays = {
  "NYS Assembly Districts": AssemblyOverlay,
  "NYC Council Districts": CouncilOverlay,
};

L.control.layers(baselayers, overlays).addTo(mymap);

// creating a custom div that changes the ed information within it based on mouseover
var cuomoinfo = L.control();

  cuomoinfo.onAdd = function (cuomomap) {
    this._div = L.DomUtil.create('div', 'cuomoinfo'); // create a div with a class "info"
    this.update();
    return this._div;
  };

// method that we will use to update the control based on feature properties passed
  cuomoinfo.update = function (cuomoprops) {
    this._div.innerHTML = '<h4>Votes for Andrew M. Cuomo</h4>' +  (cuomoprops ?
        '<b>' + cuomoprops.ElectDist + '</b><br/>' + cuomoprops.QueensCountyGovernorDemocraticPrimarySept2018_Cuomo + ' votes cast'
        : 'Hover over an Electrion District to see voting results');
  };

cuomoinfo.addTo(mymap);

$('.cuomoinfo').hide()

0 个答案:

没有答案