百度地图android海量点卡顿,百度地图加载海量点颜色问题

这篇博客展示了如何使用百度地图API在网页中绘制海量点,并为这些点添加点击事件。通过创建PointCollection对象,实现了不同颜色和样式的点分布,同时在点击点时弹出坐标信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

加载海量点

html,body{

margin:0;

width:100%;

height:100%;

background:#ffffff;

}

#map{

width:100%;

height:100%;

}

#panel {

position: absolute;

top:30px;

left:10px;

z-index: 999;

color: #fff;

}

#login{

position:absolute;

width:300px;

height:40px;

left:50%;

top:50%;

margin:-40px 0 0 -150px;

}

#login input[type=password]{

width:200px;

height:30px;

padding:3px;

line-height:30px;

border:1px solid #000;

}

#login input[type=submit]{

width:80px;

height:38px;

display:inline-block;

line-height:38px;

}

var map = new BMap.Map("map", {}); // 创建Map实例

map.centerAndZoom(new BMap.Point(105.000, 38.000), 5); // 初始化地图,设置中心点坐标和地图级别

map.enableScrollWheelZoom(); //启用滚轮放大缩小

if (document.createElement('canvas').getContext) { // 判断当前浏览器是否支持绘制海量点

var points = []; // 添加海量点数据

for (var i = 0; i < 1000; i++) {

points.push(new BMap.Point(data.data[i][0], data.data[i][1]));

}

var options = {

size: BMAP_POINT_SIZE_SMALL,

shape: BMAP_POINT_SHAPE_STAR,

color: '#d340c3'

}

var pointCollection = new BMap.PointCollection(points, options); // 初始化PointCollection

pointCollection.addEventListener('click', function (e) {

alert('单击点的坐标为:' + e.point.lng + ',' + e.point.lat); // 监听点击事件

});

map.addOverlay(pointCollection); // 添加Overlay

var points2 = []; // 添加海量点数据

for (var i = 1000; i < data.data.length; i++) {

points2.push(new BMap.Point(data.data[i][0], data.data[i][1]));

}

var options2 = {

size: BMAP_POINT_SIZE_SMALL,

shape: BMAP_POINT_SHAPE_STAR,

color: '#d34011'

}

var pointCollection2 = new BMap.PointCollection(points2, options2); // 初始化PointCollection

pointCollection2.addEventListener('click', function (e) {

alert('单击点的坐标为:' + e.point.lng + ',' + e.point.lat); // 监听点击事件

});

map.addOverlay(pointCollection2); // 添加Overlay

} else {

alert('请在chrome、safari、IE8+以上浏览器查看本示例');

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值