var map = $('#map'),
m = {};
map.tinyMap({
'center': {'x': '25.04151536540612', 'y': '121.56354904174805'},
'zoom': 14,
'marker': [
{
'addr': ['25.04151536540612', '121.56354904174805'],
'text': '25.04151536540612, 121.56354904174805',
'event': {
'mouseover': function () {
var mm = map.data('tinyMap');
this.infoWindow.open(mm.map, this);
},
'mouseout': function () {
this.infoWindow.close();
}
}
}
],
'event': {
'idle': function () {
// 取得 tinyMap instance
m = map.data('tinyMap');
// 取得 markers 及其 infoWindow
var marker = m._markers[0] || {},
infoWindow = marker.infoWindow || {};
if ('function' === typeof infoWindow.open) {
// 開啟 infoWindow
infoWindow.open(m.map, marker);
}
}
}
});
// Switch button
$('#switch').on('click', function () {
// 取得 tinyMap instance
m = map.data('tinyMap');
// 取得 markers 及其 infoWindow
var marker = m._markers[0] || {},
infoWindow = marker.infoWindow || {};
// 判斷 infoWindow 是否已開啟
if (!infoWindow.getMap()) {
infoWindow.open(m.map, marker); // 開
} else {
infoWindow.close(); // 關
}
});
<button type="button" id="switch">Switch</button>
<div id="map"></div>
#map{width:100%;height:300px}
External resources loaded into this fiddle: