BIGEMPA Js API示例中心
<!DOCTYPE html> <html> <head> <meta charset='UTF-8' /> <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> <!-- 以下CSS地址請在安裝軟件了替換成本地的地址 CSS地址請使用: http://localhost:9000/bigemap.js/v2.1.0/bigemap.css 軟件下載地址 http://www.bt68f.cn/reader/download/detail201802017.html --> <link href='http://www.bt68f.cn:9000/bigemap.js/v2.1.0/bigemap.css' rel='stylesheet' /> <!-- JS地址請使用: http://localhost:9000/bigemap.js/v2.1.0/bigemap.js --> <script src='http://www.bt68f.cn:9000/bigemap.js/v2.1.0/bigemap.js'></script> <!--引入對應(yīng)的JS+CSS 相關(guān)下載地址 http://www.bt68f.cn/Public/offline/marker_cluster/cluster.zip--> <link rel="stylesheet" href="/Public/offline/marker_cluster/MarkerCluster.Default.css" /> <script src="/Public/offline/marker_cluster/bm.markercluster-src.js"></script> <style type="text/css"> *{ padding: 0; margin: 0; } html,body,#map{ width: 100%; height: 100%; } </style> </head> <body> <div id='map'></div> <script> BM.Config.HTTP_URL = 'http://www.bt68f.cn:9000'; var map = BM.map('map', 'bigemap.zhongkexingtu', { center: [30.6, 104.5], zoom: 7, zoomControl: true, attributionControl: false }); //登陸聚合對象 var markers = new BM.MarkerClusterGroup({ showCoverageOnHover: false, //不顯示邊界 zoomToBoundsOnClick: true,//點擊放大到對應(yīng)位置 removeOutsideVisibleBounds: false, animate: true,//動畫 maxClusterRadius: 100,//縮放半徑, disableClusteringAtZoom:null,//在指定級別以下禁用縮放 //使用定義的圖標(biāo)來顯示 // iconCreateFunction: function (cluster) { // var markers = cluster.getAllChildMarkers(); // // BM.icon({iconUrl:'http://www.bt68f.cn/mapoffline/marker/2.png'}) // return BM.divIcon({ // html: `<div class="icon">${markers.length}</div>`, // iconSize: BM.point(40, 40) // }); // } }) // BM.marker([i*5,j*5],{icon:BM.icon({iconUrl:'http://www.bt68f.cn/mapoffline/marker/'+20+'.png'})}).addTo(map); var markersList = []; //生成2000個點推入標(biāo)記數(shù)組 function populate() { for (let i = 0; i < 2000; i++) { let m = new BM.marker(getRandomLatLng(map), { icon: BM.icon({ iconUrl: 'http://www.bt68f.cn/mapoffline/marker/' + 2 + '.png' }) }) markersList.push(m); markers.addLayer(m); } return false } //根據(jù)當(dāng)前的范圍生成隨機(jī)的點 function getRandomLatLng(map) { let bounds = map.getBounds(), southWest = bounds.getSouthWest(), northEast = bounds.getNorthEast(), lngSpan = northEast.lng - southWest.lng, latSpan = northEast.lat - southWest.lat; return new BM.LatLng( southWest.lat + latSpan * Math.random(), southWest.lng + lngSpan * Math.random()); } //對聚合的實例添加點擊事件 markers.on('clusterclick', function (a) { console.log('cluster' + a.layer.getAllChildMarkers().length); }) //對標(biāo)注添加一個點擊事件 markers.on('click', function (a) { alert('marker ' + a.layer); }); populate(); map.addLayer(markers); </script> </body> </html>