Mapbox.js飞到位置(工作),然后打开右标记弹出窗口(失败)

时间:2016-10-12 19:35:58

标签: javascript markers

所以我设置了这个简单的地图:

var map = L.mapbox.map('map', 'mapbox.streets')
    .setView([52.15, 5.5], 8);

var myLayer = L.mapbox.featureLayer().addTo(map);


// Add custom popups to each using our custom feature properties
myLayer.on('layeradd', function(e) {
    var marker = e.layer,
        feature = marker.feature;

// (stuff happens)

    marker.bindPopup(popupContent,{
        closeButton: false,
        minWidth: 500
    });
});

// the following is where it all goes wrong:

// Run easings when links are clicked
    var side = document.getElementById('map-ui');
        for (var i = 0; i < features.length; i++) {                 // for all the number of features we have
            var a = side.appendChild(document.createElement('a'));  // add a 'a' child to the side element
            a.onclick = (function(feature, i) {                     // when you click on it
                return function() {     
                    map.setView( [                          // centre the map to the appropriate coordinates
                        feature.geometry.coordinates[1],
                        feature.geometry.coordinates[0]+0.03    // +0.03 puts it a bit to the left, to make room for the tooltip
                    ],12);      

这是我想打开弹出窗口的地方,但我不确定如何触发正确的标记打开。有关现实生活的例子,请访问www.boerenmetwater.nl。以下四个示例不起作用:

                        //marker()[1].openPopup();
                        //map.marker[i].openPopup();
                        //t.openPopup(this);
                        //marker.openPopup();
                    }
            }
            )   
            (features[i], i);
            a.href = '#';
            a.title = 'klik om naar ' + features[i].properties.plaats + ' te gaan';
            a.innerHTML = '<div class = "menu_plaatsnaam">' + features[i].properties.plaats + '</div>';     
            a.innerHTML += '<div class = "menu_titel">' + features[i].properties.titel + '</div>';      
}

0 个答案:

没有答案