UMarker triggerEvent
triggerEvent可以讓你直接觸發marker上自定義的監聽事件,通常會做一個地標列表列出所有的marker,當點選列表時觸發原本榜定在marker上的事件。
var map = new UMap(document.getElementById('map'));
map.setControlType(U_FULL_CONTROL);
map.centerAndZoom(new ULatLng(25.035405, 121.520255), 9);
// 函式:用來產生一個會顯示指定號碼在訊息視窗中的地標
function createMarker(point, number) {
var marker = new UMarker(point);
marker.setMouseonInfo('label:'+number, 'desc:'+number);
var html = '地標 #<b>' + number + '';
marker.addListener('click', function() {
marker.openInfoWindow(html);
});
return marker;
}
// 加入十個隨機產生的地標
var bounds = map.getBounds();
var width = bounds.getNorthEast().lng() - bounds.getSouthWest().lng();
var height = bounds.getNorthEast().lat() - bounds.getSouthWest().lat();
for (var i = 0; i < 10; i++) {
var point = new ULatLng(bounds.getSouthWest().lat() + height * Math.random(), bounds.getSouthWest().lng() + width * Math.random());
var marker = createMarker(point, i+1);
map.addOverlay(marker);
var a = document.createElement('a');
a.href='#';
a.innerHTML = marker.label;
a.onclick = (function(m){
return function(){
m.triggerEvent('click');
};
})(marker);
document.getElementById('list').appendChild(a);
document.getElementById('list').appendChild(document.createTextNode(' '));
觀看範例: http://www.urmap.com/SearchEngine/api/documentation/marker_triggerEvent.html


