Skip to content

方法

addClassName(className)

向标记元素添加一个CSS类。

参数说明类型可选值默认值
className非空字符串,带有要添加到标记元素的CSS类名stringstring-

示例:

html
<script>
  let marker = new EhhGisGl.Marker()
  marker.addClassName('some-class')
</script>

addTo(map)

将标记附加到地图对象上

参数说明类型可选值默认值
map要添加标记的 MapLibre GL JS 地图MapMap-

return:this 本身

示例:

html
<script>
  let marker = new EhhGisGl.Marker().setLngLat([30.5, 50.5]).addTo(map)
</script>

getElement()

返回标记的HTML元素

getLngLat()

获取标记的地理位置。
由于标记会将锚点经度包裹在世界地图的多个副本上来保持标记在屏幕上可见,因此返回结果的经度可能与通过 setLngLat 之前设置的经度相差 360 度的整数倍。

示例:

html
<script>
  let lngLat = marker.getLngLat()
  console.log('Longitude: ' + lngLat.lng + ', Latitude: ' + lngLat.lat)
</script>

getOffset()

获取标记的偏移量 (屏幕坐标(单位:像素))

getPitchAlignment()

返回标记的当前pitchAlignment属性

getRotation()

返回标记的当前旋转角度(以度为单位)

getRotationAlignment()

返回标记的当前rotationAlignment属性

isDraggable()

如果标记可以拖动,则返回 true

listens(type)

如果此 Evented 实例或任何被转发的 Evented 实例对指定类型有监听器,则返回 true

参数说明类型可选值默认值
type事件类型stringstring-

如果指定事件类型至少有一个已注册的监听器则为真,否则为假

off(type,listener)

移除先前注册的事件监听器

参数说明类型可选值默认值
type要移除监听器的事件类型stringstring-
listener要移除的监听函数ListenerListener

return:Marker

on(type,listener)

添加指定事件类型的监听器

参数说明类型可选值默认值
type要添加监听的事件类型stringstring-
listener事件触发时调用的函数。监听器函数将接收传递给 fire 的数据对象,并扩展以包含 target 和 type 属性。ListenerListener

return:Subscription

once(type,listener)

添加一个仅调用一次的监听器到指定的事件类型。 该监听器将在注册后,事件首次触发时被调用。

参数说明类型可选值默认值
type要监听的事件类型stringstring-
listener?事件首次触发时要调用的函数ListenerListener

remove()

从地图上移除标记

示例:

html
<script>
  let marker = new EhhGisGl.Marker().addTo(map)
  marker.remove()
</script>

removeClassName(className)

从标记元素中移除一个CSS类

参数说明类型可选值默认值
className从标记元素中移除带有CSS类名的非空字符串stringstring-

示例:

html
<script>
  let marker = new EhhGisGl.Marker()
  marker.removeClassName('some-class')
</script>

setDraggable(shouldBeDraggable)

设置标记的可拖动属性和功能

参数说明类型可选值默认值
shouldBeDraggable?开启/关闭拖拽功能booleanboolean-

setEventedParent(parent,data)

将此 Evented 实例触发的所有事件冒泡到此父级 Evented 实例

参数说明类型可选值默认值
parent?EventedEvented-
data?anyany

setLngLat(lnglat)

设置标记的地理位置并移动它

参数说明类型可选值默认值
lnglat描述标记应位于何处的经纬度LngLatLikeLngLatLike-

return:this 本身

示例: 创建一个新标记,设置经度和纬度,并将其添加到地图中

html
<script>
  new EhhGisGl.Marker().setLngLat([-65.017, -16.457]).addTo(map)
</script>

setOffset(offset)

设置标记的偏移量;offset

setOpacity(opacity,opacityWhenCovered)

设置标记的不透明度(opacity)和被覆盖时不透明度(opacityWhenCovered)属性。

参数说明类型可选值默认值
opacity?设置标记的不透明度属性stringstring-
opacityWhenCovered?设置标记的被覆盖时的不透明度属性stringstring

setRotation(rotation)

设置标记的旋转属性 rotation

toggleClassName(className)

根据标记元素当前是否具有该类,添加或移除给定的CSS类

参数说明类型可选值默认值
className带有要添加/移除的 CSS 类名的非空字符串stringstring-

return:boolean 如果类被移除则返回 false,如果类被添加则返回 true

示例:

html
<script>
  let marker = new EhhGisGl.Marker()
  marker.toggleClassName('toggleClass')
</script>