getBounds for current viewport

by essoduke chang

HTML

<script src="//maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://app.essoduke.org/tinyMap/jquery.tinyMap-2.9.9.min.js?ver=2.9.9"></script>
<div id="map"></div>

CSS

#map{width:100%;height:360px}

JavaScript

var map = $('#map');

// 在地圖可視範圍四角建立標記
// 可拉住地圖移動確認標記位置

map.tinyMap({
    'center': ['25.037160575899154', '121.55350685119629'],
    'zoom': 13,
    'event': {
        'idle': function () {
            var bounds = this.getBounds(),
                ne = bounds.getNorthEast(),
                sw = bounds.getSouthWest(),
                nw = [ne.lat(), sw.lng()],
                se = [sw.lat(), ne.lng()];
            map.tinyMap('modify', {
                'marker': [
                    {'addr': [ne.lat(), ne.lng()], 'text': 'NE', 'id': 'NE'},
                    {'addr': [sw.lat(), sw.lng()], 'text': 'SW', 'id': 'SW'},
                    {'addr': nw, 'text': 'NW', 'id': 'NW'},
                    {'addr': se, 'text': 'SE', 'id': 'SE'}
                ]
            });
        }
    }
});