BMapGL marker 设置那么
时间: 2024-01-18 16:04:08 浏览: 50
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,并且设置其名称。
new BMapGL.Marker 如何设置ID
在百度地图 JavaScript API 中,可以通过 `Marker` 构造函数的第二个参数 `opts` 来设置标记物体的属性,其中包括 `id` 属性,如下所示:
```javascript
var marker = new BMapGL.Marker(point, {
id: 'marker_1', // 设置标记物体的ID为'marker_1'
icon: icon // 设置标记物体的图标
});
```
这样,创建的标记物体就会具有 ID 为 `marker_1` 的属性。需要注意的是,每个标记物体的 ID 必须是唯一的。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)