wangrong
2025-09-23 40634ebaf5863a599bba8ca2c0575ca079fb8e15
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>区域船展示</title>
    <script src="https://api.shipxy.com/h5s/api/3.5/plugins/jquery/jquery.min.js"></script>
    <script src="https://api.shipxy.com/h5s/api/3.5/?k=4d7a0667a74d45e491d9fda4a86e2ba9"></script>
    <style>
        .my-map {
            position: absolute;
            left: 0px;
            top: 0px;
            width: 100%;
            height: 100%;
            overflow: hidden;
            outline: none;
            background-color: #A3CCFF;
        }
        .div_btn {
            position: relative;
            top: 10px;
            left: 80px;
            z-index: 888;
        }
 
        .div_btn input[type="button"] {
            cursor: pointer;
        }
        .count_span{
            color: red;
            background-color: #fff;
            text-align: left;
            width: 120px;
            font-weight: bolder;
            padding: 0 5px;
            border: 1px solid #000000;
        }
        .leaflet-popup-tip-container{
            display: none;
        }
        .leaflet-popup{
            color:black;
            margin: 0;
            bottom: -600px !important;
            left: 604px !important;
           
        }
        .leaflet-popup-content-wrapper{
            background-color: rgba(0, 0, 0, 0) !important;
            box-shadow: 0 0 0 rgba(0, 0, 0, 0);
        }
        .shipxy_popup .box {
            color: #000000 !important;
            background-color: rgba(0, 0, 0, 0) !important;
        }
    </style>
</head>
<body>
<div id="map"
     class="my-map">
    <!-- <div class="div_btn count_span">
        <label>当前船舶数:</label>
        <span id="txt_drawships_count"></span>
    </div> -->
</div>
<script>
    window.addEventListener('message', function(event) { 
console.log(event,"eeeee")
        let data_lat = event.data.cxw_lat
        let data_lng = event.data.cxw_lng
        _map.setView([data_lat,data_lng],15);
     },false)
    // 创建地图示例
    var _map = new ShipxyAPI.Map("map",{ak:"4d7a0667a74d45e491d9fda4a86e2ba9"});
    console.log(_map)
    var ship_data = []
    // 开启区域船服务
    var canvasShips = ShipxyAPI.ShipService(_map, {
        enableAreaShip:true,// 区域船
        enableFleetShip:false,// 船队船
        // resetShipColorCallBack:function(ship){
        //     //重设区域船颜色
        //     //ship,区域船单船信息,
        //     return "red";//当前船将被绘制成红色
        // },
        drawShipsEndCallBack:function(data){
            for(let i=0;i<canvasShips._drawLables.length;i++){
                let item = canvasShips._drawLables[i]
                console.log(item,"item")
                ship_data.push({id:item.symbol.mmsi,name:item.lableText,lat:item.symbol.lat,lng:item.symbol.lng,time:item.symbol._ship.lastdyn})
                console.log(JSON.stringify(ship_data))
            }
            console.log(canvasShips,"data")
 
            // 绘制完区域船后回调
            $("#txt_drawships_count").html(data.count);
        },
        lableFont: ["600 12px Arial", "600 13px 宋体"],// 船舶名称,文字字体,默认值:["600 12px Arial", "500 12px Arial"]
        lableTxtColor: ["#000", "#000"],   // 船舶名称,文字颜色,默认值:["#000","#fff"]
        lableLineColor: ["rgba(1, 30, 62, 1)", "rgba(1, 30, 62, 1)"],   //  边框颜色,默认值:["#000","#000"]
        lableLinefillColor: ["rgba(1, 30, 62, 0.0)", "rgba(1, 30, 62, 0.0)"],// 框内填充颜色,默认值:[null,null]
        obliqueLineColor: ["#000", "#000"],  // 船舶名称,斜线颜色,默认值:[null,null]
        dShipColor: "#FF6437",   // D+船颜色,默认:#ff6347
 
    });
    
    // setInterval(function(){
    //     console.log(canvasShips,"canvasShips")
    // },1000)
    canvasShips.addSelectedListener(function (ship) {
        // 选中船监听
        console.log("ship:" + ship.mmsi);
    });
    //
   // _map.setView([31.067789,121.476388],16); //31.137222,121.533889     31.065589,121.476388  
    //
    var ship_arr = [];
   
    // ship_arr.push(ship1);
    var marker_icon_1 = L.icon({
        iconUrl: "./dingweidian.png",
        iconAnchor: [0, 0],//图标锚点
        // iconSize:[32,32]//图标大小
    });
    // 添加标记,到地图
    var marker = ShipxyAPI.marker([31.063613, 121.480387], {
        icon: marker_icon_1,
        label:'杜丰通感'
    }).addTo(_map);
var marker2 = ShipxyAPI.marker([31.222,121.51], {
        icon: marker_icon_1,
        label:'宬苑通感'
    }).addTo(_map);
    var popup_options = {
        className: "shipxy_popup",
        closeButton: false,
    };
    //
    marker.bindPopup(function (layer) {
        var html = "";
        html += "<div class='box'>杜丰通感";
        html += "</div>";
        return html;
    }, popup_options).openPopup();
    // 添加区域船
    _map.shipsService.addShips(ship_arr);
    // 设置选中船
    _map.shipsService.setSelectedShip('888888888');
    // 取消选中船
    setTimeout(function () {
        _map.shipsService.cancelSelectedShip();
    },2000);
    // 删除指定区域船
    setTimeout(function () {
        _map.shipsService.deleteShipByShipID('999999999');
    },3000);
</script>
</body>
</html>