lxw
2020-07-11 9db52f2f2dd3665fe9da1ae5657e0167c3a34d40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var BMapLib = window.BMapLib = BMapLib || {};
(function() {
    var b = BMapLib.AreaRestriction = function() {};
    var a = false;
    var c = null;
    var d = null;
    b.setBounds = function(f, e) {
        if (!f || !e || !(e instanceof BMap.Bounds)) {
            throw "请检查传入参数值的合法性";
            return false;
        }
        if (a) {
            this.clearBounds();
        }
        c = f;
        d = e;
        c.addEventListener("moveend", this._mapMoveendEvent);
        a = true;
        return true;
    };
    b._mapMoveendEvent = function(k) {
        if (d.containsBounds(c.getBounds())) {
            return
        }
        var i = c.getBounds(),
            h = i.getSouthWest(),
            g = i.getNorthEast(),
            m = d.getSouthWest(),
            j = d.getNorthEast();
        var l = {
            n: 0,
            e: 0,
            s: 0,
            w: 0
        };
        l.n = (g.lat < j.lat) ? g.lat : j.lat;
        l.e = (g.lng < j.lng) ? g.lng : j.lng;
        l.s = (h.lat < m.lat) ? m.lat : h.lat;
        l.w = (h.lng < m.lng) ? m.lng : h.lng;
        var f = new BMap.Point(l.w + (l.e - l.w) / 2, l.s + (l.n - l.s) / 2);
        setTimeout(function() {
            c.panTo(f, {
                noAnimation: "no"
            });
        }, 1);
    };
    b.clearBounds = function() {
        if (!a) {
            return
        }
        c.removeEventListener("moveend", this._mapMoveendEvent);
        a = false;
    };
})();