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://ua.bigemap.com:30081/bmsdk/bigemap.js/v2.1.0/bigemap.css" rel="stylesheet"/>
<!--
JS地址請使用:
http://localhost:9000/bigemap.js/v2.1.0/bigemap.js
-->
<script src="http://ua.bigemap.com:30081/bmsdk/bigemap.js/v2.1.0/bigemap.js"></script>
<script src="http://www.bt68f.cn/offline_data/newjunbiao/turf.min.js"></script>
<script src="http://www.bt68f.cn/offline_data/newjunbiao/bm-plot.min.js"></script>
<script src="http://www.bt68f.cn/offline_data/newjunbiao/jquery.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
.tools {
width: 400px;
height: 40px;
display: flex;
position: absolute;
top: 20px;
right: 60px;
align-items: center;
z-index: 99;
justify-content: space-around;
}
.item {
width: 100px;
/* height: 30px; */
text-align: center;
/* line-height: 30px; */
background-color: #59acff;
color: antiquewhite;
padding: 8px;
border-radius: 4px;
}
</style>
<title>Google Map Streets</title>
</head>
<body>
<div id="map">
<div class="tools">
<h3 class="item">清除所有點</h3>
<h3 class="item one">添加數(shù)據(jù)</h3>
<h3 class="item two">導(dǎo)出圖片</h3>
</div>
<a download="" style="display: none" id="download"></a>
</div>
<script>
// 軟件配置信息地址,軟件安裝完成之后使用本地地址,如:http://localhost:9000
BM.Config.HTTP_URL = "http://ua.bigemap.com:30081/bmsdk/"
// 在ID為map的元素中實例化一個地圖,并設(shè)置地圖的ID、中心點,默認的級別和顯示級別控件
var map = BM.map("map", "bigemap.dc-tian-w-satellite", {
center: [30.593173722573788, 104.02184485690668],
zoom: 10,
zoomControl: true,
attributionControl: false,
});
window.lastMarker = null;
window.svg = new BM.Plot.SvgLayer({
pane: "tooltipPane",
}).addTo(map);
// 創(chuàng)建導(dǎo)出圖片對象
let exportObj = new BM.Plot.Export(map);
//監(jiān)聽事件
exportObj.on("export_index", (e) => {
// console.log("eee",e);
if (e.detail.index == e.detail.sum) {
console.log(e);
}
});
// console.log(svg, "sss");
let all1 = [];
var iconData = BM.icon({
iconUrl: "/offline_data/newjunbiao/2.png",
iconSize: BM.point(30, 30),
iconAnchor: BM.point(15, 30),
});
var points = null;
// 生成200個隨機點
points = turf.randomPoint(200, {
bbox: [102.991, 31.438, 104.895, 30.092],
});
var fs = points.features;
fs.forEach((v, i) => {
let pos = v.geometry.coordinates;
var ss22 = new BM.Plot.IconOverlay(iconData, [pos[1], pos[0]], {
size: { x: 30, y: 30 },
// 設(shè)置5小于5級的時候是0.5的大小,大于16級時放大2倍
zoomScale: new BM.Plot.ZoomScale(5, 0.5, 16, 2),
// 設(shè)置tooltip,這個是一直顯示的 默認在標簽下方
// 文本內(nèi)容
text: `${i + 1}`,
// 文本顏色
color: "red",
// 文本字體,大小
font: "20px 楷體",
// 文本偏移量
textOffset: BM.point(2, 2),
backgroundColor: "aqua",
});
all1.push(ss22);
});
window.svg.addLayers(all1);
// console.log(points);
// // 鼠標左鍵點擊事件
svg.addOnClickListener(function (e) {
console.log(e.layer);
});
// // 鼠標右鍵點擊事件
svg.addOnContextMenuListener(function (e) {
console.log(e.layer);
});
// // console.log(svg);
document
.querySelector(".item")
.addEventListener("click", function (e) {
svg.clearLayers();
});
document.querySelector(".one").addEventListener("click", (e) => {
var points = null;
points = turf.randomPoint(Math.floor(Math.random() * 200 + 1), {
bbox: [102.991, 31.438, 104.895, 30.092],
});
var fs = points.features;
svg.clearLayers();
fs.forEach((v, i) => {
let pos = v.geometry.coordinates;
var ss22 = new BM.Plot.IconOverlay(
iconData,
[pos[1], pos[0]],
{
size: { x: 30, y: 30 },
// 設(shè)置5小于5級的時候是0.5的大小,大于16級時放大2倍
zoomScale: new BM.Plot.ZoomScale(5, 0.5, 16, 2),
// 設(shè)置tooltip,這個是一直顯示的 默認在標簽下方
// 文本內(nèi)容
text: `${i + 1}`,
// 文本顏色
color: "red",
// 文本字體,大小
font: "20px 楷體",
// 文本偏移量
textOffset: BM.point(2, 2),
backgroundColor: "aqua",
}
);
all1.push(ss22);
});
window.svg.addLayers(all1);
});
document.querySelector(".two").addEventListener("click", (e) => {
console.log("er");
exportObj
.export(map.getBounds(), {
zoom: map.getZoom(),
needTileLayer: true,
})
.then((result) => {
console.log("result", result);
let data = result.data;
let mm = new Image();
mm.src = data;
mm.onload = function(){
let c = document.createElement("canvas");
c.width = mm.width;
c.height = mm.height;
c.getContext("2d").drawImage(mm,0,0,mm.width,mm.height);
let a = document.createElement("a");
a.download = `demo`
a.href = c.toDataURL("image/png");
a.click();
}
})
.catch((err) => {});
});
</script>
</body>
</html>