<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
html {
height:100%
}
body {
height:100%;
margin:0px;
padding:0px
}
#main {
height:100%
}
.circle-marker {
position: absolute;
width: 90px;
height: 90px;
background: #c00;
border-radius: 50%;
opacity: .7
}
</style>
<script src="http://api.map.baidu.com/api?v=2.0&ak=Ls1zIpQI8SB8bi46cSGieAYLHYeyHzfW"></script>
</head>
<body>
<div id="main"></div>
<script>
var map = new BMap.Map("main", {enableMapClick: false}); // 创建地图实例
var point = new BMap.Point(116.400551, 39.893524); // 创建点坐标
map.centerAndZoom(point, 12); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom()
map.addControl(new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT}))
// 圆形覆盖物
function customOverlay(point) {
this.point = point
}
customOverlay.prototype = new BMap.Overlay()
// 初始化,设置覆盖物形状
customOverlay.prototype.initialize = function() {
var div = this.div = document.createElement('div')
div.className = 'circle-marker'
map.getPanes().labelPane.appendChild(div)
}
// 覆盖物的位置
customOverlay.prototype.draw = function () {
var p = map.pointToOverlayPixel(this.point)
this.div.style.left = p.x - 45 + 'px'
this.div.style.top = p.y - 45 + 'px'
}
var marker = new BMap.Marker(point) // 这个可以清除
map.addOverlay(marker)
var marker2 = new customOverlay(point) // 这个清除不了?
map.addOverlay(marker2)
map.addEventListener('click', function(e) {
map.clearOverlays()
})
</script>
</body>
</html>
1
opengps 2017-10-13 10:04:36 +08:00
两个点干嘛要重叠在一起?
|
3
ie88 2017-10-13 10:31:09 +08:00
customOverlay'用 removeOverlay()可以清除
|
5
ie88 2017-10-13 10:32:55 +08:00
另外,初始化 marker 时,增加 enableMassClear(),该方法 允许覆盖物在 map.clearOverlays 方法中被清除
|
6
cnbdas 2017-10-13 10:35:12 +08:00 1
@yantianqi customOverlay.prototype.initialize = function() {
var div = this.div = document.createElement('div') div.className = 'circle-marker' map.getPanes().labelPane.appendChild(div) return div } 少了 return |
8
ioth 2017-10-13 12:05:53 +08:00
web 地图 js,要细心,没办法跟踪的。
|