Leaflet.js setMaxBounds忽略南边界 [英] Leaflet.js setMaxBounds ignores southern bound

查看:1311
本文介绍了Leaflet.js setMaxBounds忽略南边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Leaflet.js 获取开源地图项目,但我需要设置特定范围用户无法超越。地图对象的maxBounds属性在北,东和西方向上按预期工作 - 但它可以让我永远向南滚动。

Using Leaflet.js for an open-source map project, but I need to set specific bounds the user can't move beyond. The maxBounds property of the map object works as expected on the north, east and west directions- but it lets me scroll forever southward.

在小提琴中,绿色背景显示绑定的应该结束,并且我添加了一个纬度的点击警告进行检查。

In the fiddle, the green background reveals where the bound should end, and I've added an on-click alert of the latitude for checking.

http://jsfiddle.net/7m7n7/

var map = L.map('map', {
maxZoom: 4,
minZoom: 1,
maxBounds: [
    //south west
    [-85.07815906717186, -179.97802734374997],
    //north east
    [-60.413852350464914, 39.8583984375]
]
}).setView([-72.5, -110], 1);

L.tileLayer(
    'http://{s}.tile.cloudmade.com/{API}/998/256/{z}/{x}/{y}.png', 
    { maxZoom: 18 }).addTo(map);


推荐答案

当你使用 setBounds 然后传单名为 L.Map.panInsideBounds 你的边界,你在哪里得到投影: viewSw = this.project(viewBounds.getSouthWest()),使用下一代码

When you use setBounds then leaflet called L.Map.panInsideBounds with your bounds, where are you trying get projection: viewSw = this.project(viewBounds.getSouthWest()), which use next code for default projection:

project: function (latlng) { // (LatLng) -> Point
    var d = L.LatLng.DEG_TO_RAD,
    max = this.MAX_LATITUDE,
    lat = Math.max(Math.min(max, latlng.lat), -max),
    x = latlng.lng * d,
    y = lat * d;

    y = Math.log(Math.tan((Math.PI / 4) + (y / 2)));

    return new L.Point(x, y);
}

所以有 Math.max(Math.min) (max,latlng.lat), - max)不能超过最大值或最小值, viewSw 等于最大值和真实值边界未修复。

So there are Math.max(Math.min(max, latlng.lat), -max) can't be more then max or min value and viewSw became equal to max value and real bounds not fixed.

此问题已修复 。您可以使用来自主人的版本,或等待下次实现的时候。

This issue was fixed. You can use version from master or wait when next realise will be come.

这篇关于Leaflet.js setMaxBounds忽略南边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆