2014-06-10 51 views
0

任何人都可以看到这段代码中的内容阻止了我的地图中的工具提示的功能吗?也就是说,它们在法线贴图中运行,但不会在使用切换按钮将图层添加到此贴图时不起作用。我认为它是onclick函数的一些东西,但不能明确地说明,以及可能的解决方法。Mapbox工具提示被代码禁用

谢谢

<style> 
.menu-ui { 
    background:#fff; 
    position:absolute; 
    bottom:10px;left:10px; 
    z-index:1; 
    border-radius:3px; 
    width:120px; 
    border:1px solid rgba(0,0,0,0.4); 
    } 
    .menu-ui a { 
    font-size:13px; 
    color:#404040; 
    display:block; 
    margin:0;padding:0; 
    padding:10px; 
    text-decoration:none; 
    border-bottom:1px solid rgba(0,0,0,0.25); 
    text-align:center; 
    } 
    .menu-ui a:first-child { 
     border-radius:3px 3px 0 0; 
     } 
    .menu-ui a:last-child { 
     border:none; 
     border-radius:0 0 3px 3px; 
     } 
    .menu-ui a:hover { 
     background:#f8f8f8; 
     color:#404040; 
     } 
    .menu-ui a.active { 
     background:#3887BE; 
     color:#FFF; 
     } 
     .menu-ui a.active:hover { 
     background:#3074a4; 
     } 
</style> 
<nav id='menu-ui' class='menu-ui'></nav> 
<div id='map'></div> 

<script> 
var map = L.map('map').setView([10.8229,-84.2116], 12); 
var layers = document.getElementById('menu-ui'); 

addLayer(L.mapbox.tileLayer('XXXX.XXXX'), 'Photo Points', 4); 
addLayer(L.mapbox.tileLayer('XXXX.XXXX'), 'River KMs', 3); 
addLayer(L.mapbox.tileLayer('XXXX.XXXXX'), 'December 2013 (0.5m)', 2); 
addLayer(L.mapbox.tileLayer('XXXXXX.XXXXXX'), 'February 2014 (1.5m)', 1); 


function addLayer(layer, name, zIndex) { 
    layer 
     .setZIndex(zIndex) 
     .addTo(map); 

    // Create a simple layer switcher that 
    // toggles layers on and off. 
    var link = document.createElement('a'); 
     link.href = '#'; 
     link.className = 'active'; 
     link.innerHTML = name; 

    link.onclick = function(e) { 
     e.preventDefault(); 
     e.stopPropagation(); 

     if (map.hasLayer(layer)) { 
      map.removeLayer(layer); 
      this.className = ''; 
     } else { 
      map.addLayer(layer); 
      this.className = 'active'; 
     } 
    }; 

    layers.appendChild(link); 
} 
</script> 

回答