BMapGL marker 设置那么
时间: 2024-01-18 07:04:08 浏览: 193
BMapGL 的 marker 可以通过以下的方式进行设置:
1. 创建 marker 对象:
```javascript
var marker = new BMapGL.Marker(point);
```
其中,`point` 是一个 BMapGL 的地理坐标点对象。
2. 设置 marker 的属性:
```javascript
marker.setIcon(icon); // 设置 marker 的图标
marker.setLabel(label); // 设置 marker 的标签
marker.setTitle(title); // 设置 marker 的标题
marker.setAnimation(animation); // 设置 marker 的动画效果
```
其中,`icon` 是一个 BMapGL 的 icon 对象,`label` 是一个 BMapGL 的 label 对象,`title` 是一个字符串,`animation` 是一个枚举值,用于指定 marker 的动画效果。
3. 将 marker 添加到地图上:
```javascript
map.addOverlay(marker);
```
其中,`map` 是一个 BMapGL 的地图对象。
以上是 BMapGL marker 的基本设置方法,具体的使用可以根据实际情况进行调整。
相关问题
BMapGL marker 设置Name
BMapGL 的 Marker 类并没有直接提供设置 name 属性的方法,但可以通过自定义覆盖物来实现。
具体实现步骤如下:
1. 创建一个自定义的覆盖物类,继承自 BMapGL.Overlay 类:
```javascript
function CustomMarker(point, name) {
this._point = point;
this._name = name;
}
CustomMarker.prototype = new BMapGL.Overlay();
// 实现 initialize 方法和 draw 方法
CustomMarker.prototype.initialize = function(map) {
this._map = map;
var div = document.createElement("div");
div.style.position = "absolute";
div.style.width = "60px";
div.style.height = "60px";
div.style.lineHeight = "60px";
div.style.textAlign = "center";
div.style.backgroundColor = "red";
div.style.color = "white";
div.style.fontSize = "20px";
div.style.borderRadius = "50%";
div.innerHTML = this._name;
map.getPanes().labelPane.appendChild(div);
this._div = div;
return div;
};
CustomMarker.prototype.draw = function() {
var position = this._map.pointToOverlayPixel(this._point);
this._div.style.left = position.x - 30 + "px";
this._div.style.top = position.y - 30 + "px";
};
```
在自定义的覆盖物类中,通过传入的 `name` 参数来设置 marker 的名称。
2. 在地图上添加自定义的覆盖物:
```javascript
var point = new BMapGL.Point(116.404, 39.915);
var customMarker = new CustomMarker(point, "MarkerName");
map.addOverlay(customMarker);
```
通过以上方式,就可以在地图上添加一个自定义的 marker,并且设置其名称。
var marker = new BMapGL.Marker 设置name、
您可以在创建 `BMapGL.Marker` 实例时,通过传入 `options` 参数来设置 `name` 属性,示例代码如下:
```javascript
var marker = new BMapGL.Marker(point, {
name: 'marker1'
});
```
其中,`point` 参数为标注点的位置信息。通过这种方式,您可以为标注点设置 `name` 属性,并在后续的操作中使用该属性来标识不同的标注点。
阅读全文
相关推荐

















