最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JVectorMap Set Scale Below 1 - Stack Overflow

programmeradmin1浏览0评论

I am creating a web page which requires a full size map, for which I am using JVectorMap. The map has a width and height of 100%. However, this makes the map extend right to the very edges of the page when fully zoomed out, which is undesirable. Ideally, there would be a border around the map when fully zoomed out, but when zoomed in the map would still extend to the edge of the page. Essentially, I want to begin with the map more zoomed out than seems to be allowed.

In this case, HTML borders and padding cannot be used, as although they do create the desired effect on page load, the border persists when the map is zoomed in. The only idea I had was to attempt to set the 'scale' variable near the end of the following code to a value below zero:

<script>
    $(function(){
        $('#map').vectorMap({
            map: 'world_mill',
            focusOn: {
                x: 0.5,
                y: 0.5,
                scale: 0.8
            }
        });
    });
</script>

This had no effect, as any value for 'scale' below 1 seems to be ignored. I have included screenshots below to illustrate the problem.

Current Page (Map extends to edge)

Ideal Page (Map has border

Any help would be much appreciated!

I am creating a web page which requires a full size map, for which I am using JVectorMap. The map has a width and height of 100%. However, this makes the map extend right to the very edges of the page when fully zoomed out, which is undesirable. Ideally, there would be a border around the map when fully zoomed out, but when zoomed in the map would still extend to the edge of the page. Essentially, I want to begin with the map more zoomed out than seems to be allowed.

In this case, HTML borders and padding cannot be used, as although they do create the desired effect on page load, the border persists when the map is zoomed in. The only idea I had was to attempt to set the 'scale' variable near the end of the following code to a value below zero:

<script>
    $(function(){
        $('#map').vectorMap({
            map: 'world_mill',
            focusOn: {
                x: 0.5,
                y: 0.5,
                scale: 0.8
            }
        });
    });
</script>

This had no effect, as any value for 'scale' below 1 seems to be ignored. I have included screenshots below to illustrate the problem.

Current Page (Map extends to edge)

Ideal Page (Map has border

Any help would be much appreciated!

Share Improve this question edited Aug 18, 2016 at 14:54 warunapww 1,0064 gold badges19 silver badges39 bronze badges asked Aug 18, 2016 at 0:33 DanDan 1212 silver badges9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

I'm going to post the answer to my own question, just in case anyone stumbles upon this in the future. It seems that setScale can only set the zoom to values between the zoomMin and zoomMax parameters, therefore by lowering zoomMin to 0.9 I was able to successfully use setScale to reduce the zoom to 0.9 also.

Therefore the final code I ended up with was:

$(function(){
    $('#map').vectorMap({
        map: 'world_mill',
        zoomMin: 0.9,
        focusOn: {
            x: 0.5,
            y: 0.5,
            scale: 0.9
        },
    });
});
发布评论

评论列表(0)

  1. 暂无评论