南昌市物联网技防平台-前端
liuyg
2021-05-09 f389a84ecf9c846b81a7d0006d74fd15bada8b4f
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function beginJuheMap(map, data) {
    map = L.map('map', { //初始化地图
        center: [31.87, 120.54],
        zoom: 12,
        // crs: L.CRS.EPSG4326, //设置坐标系4326
        attributionControl: false, //去掉右下角
        zoomControl: false, //去掉缩放
    });
    L.tileLayer( //添加切片图层
        "http://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}", {
        subdomains: ["1", "2", "3", "4"],
        attribution: "高德"
    }
    ).addTo(map);
    var markers = L.markerClusterGroup();
 
    var transportIcon = L.Icon.extend({ //图标初始化
        options: {
            iconSize: [30, 30], // 图标尺寸
            // iconAnchor: [30, 30], // 图标偏移量
            // popupAnchor: [-20, -20] // 弹出框偏移量
        }
    });
    var carIcon = new transportIcon({ //引入图标
        iconUrl: './img/gray.png'
    }),
        planeIcon = new transportIcon({
            iconUrl: './img/green.png'
        }),
        busIcon = new transportIcon({
            iconUrl: './img/red.png'
        });
    console.log(data, 43545343)
    var setData = (a) => {//定义图标
        marker = L.marker([a.jd, a.wd], {
            icon: a.state == 0 ? carIcon : a.state == 1 ? planeIcon : a.state == 2 ? busIcon : '',
            title: title,
            myData: {//自定义数据
                ...a
            }
        });
    }
    for (var i = 0; i < data.length; i++) {
        var a = data[i];
        var title = a.title;
        if (a.state == 0) {
            setData(a);
        } else if (a.state == 1) {
            setData(a);
        } else if (a.state == 2) {
            setData(a);
        }
        // marker.bindPopup(title);
        markers.addLayer(marker);
    }
    map.addLayer(markers);
 
    markers.on('click', function (a) {
        var data = JSON.stringify(a.layer.options.myData);
        layui.use('layer', function () {//弹窗
            layuiLayer = layui.layer;
            // layuiLayer.config({
            //   extend: 'myskin/FlareClusterLayer.css'
            // });
            // layuiLayer.close(layuiLayer.index);
 
            layuiLayer.open({
                title: '',
                type: 2,
                shadeClose: true,
                shade: false,
                skin: 'demo-class',
                id: 'onelyTwo',
                maxmin: false, //开启最大化最小化按钮
                area: ['250px', '250px'],
                // area: 'auto',
                //   offset: winSize,
                offset: 'b',
                skin: 'flare',
                isOutAnim: false,
                closeBtn: 2, //关闭按钮,可通过配置1和2来展示,0关闭
                content: ['./popup/user.html'],
                resize: false,
                scrollbar: false,
                // tipsMore: true, //允许多个tipe
                // content: num,
                success: function (layero, index) { //成功后添加全局点击关闭
                    console.log(data, 53413541)
                    $("#layui-layer-iframe" + index).contents().find("#user").val(data);
                    // layuiLayer.close(index)
                },
            })
        })
    });
}