mapLevel.js 1.58 KB

var mapLevel = {
    loadLevelControl:function (map) {
        var level = map.getZoom();
        // var html = '<div style=\'position:fixed; z-index:9999;bottom: 20px;right: 10px;\'>' +
        //     '<table border="1" style="width: 55px;height: 58px;text-align: center;">' +
        //     '<tr>' +
        //     '<td colspan="2" style="background: #707070;color: #FFFFFF" id="map_level">'+level+'</td>' +
        //     '</tr><tr>' +
        //     '<td style="background: #FFFFFF" id="level_minus"><img src="src/image/btn5.png"></td>' +
        //     '<td style="background: #FFFFFF" id="level_plus"><img src="src/image/btn4.png"></td>' +
        //     '</tr>' +
        //     '</table>' +
        //     '</div>';

        var html = '<div style="position:absolute; z-index:9999;bottom: 10%;left: 2%;">' +
            '<div id="level_plus"><img src="src/image/btn4.png"></div>' +
            '<div style="margin-top: 10px;" id="level_minus"><img src="src/image/btn5.png"></div>' +
            '</div>';

        $('body').append(html);
        $('#level_minus').click(function () {
            var zoom = map.getZoom();
            if (zoom>0 && zoom<18){
                zoom --;
            }
            map.zoomTo(zoom);
            // $('#map_level').html(zoom);
        });
        $('#level_plus').click(function () {
            var zoom = map.getZoom();
            if (zoom>0 && zoom<18){
                zoom ++;
            }
            map.zoomTo(zoom);
            // $('#map_level').html(zoom);
        });
    },
    setLevel:function (level) {
        $('#map_level').html(level);
    }
}