YY. Marker
Marker标注,一般用于地图上标注文字,图表(Ecahrts, D3等),HTML模块,甚至视频等HTML内容
警告
注意与覆盖物区分,这个不属于覆盖物, 其是加到地图上的,不是图层上
creation
- constructor(lnglat, content, [options])
- lnglat {Array||YY. LngLat}经纬度
- content {String|Dom} 内容,Html内容
- options {Object} 基本配置
js
var marker = new YY.Marker([120, 31], 'hello world');
marker.addTo(map);
marker.on('click', function(e) {
console.log(e);
})
events
mousedown
鼠标mousedown。
mouseup
鼠标mouseup。
mouseover
鼠标mouseover。
mouseout
鼠标mouseout
mouseenter
鼠标mouseenter。
mouseleave
鼠标mouseleave。
mousemove
鼠标mousemove。
click
鼠标click。
dblclick
鼠标dblclick。
contextmenu
上下文菜单时触发。
keypress
键盘事件。
touchstart
触摸 touchstart。
touchmove
触摸 touchmove。
touchend
触摸 touchend。
positionchange
位置改变时。
contentchange
文本内容改变时。
dragstart
拖拽开始。
dragging
拖拽ing
dragend
拖拽结束。
example
js
var mk = new YY.Marker([121, 36], '<div class="markerDiv">hello world</div>');
mk.addTo(map); //将 marker 添加到地图上
method
getLngLat()
- 获取经纬度
- 返回值: YY. LngLat](./yylnglat)]
setLngLat(lnglat)
- 设置经纬度
- 参数
- {YY.LngLat}
lnglat
:
- {YY.LngLat}
- 返回值:
this
getContent()
- 获取文本内容
- 返回值:
String
setContent(content)
- 设置文本内容
- 参数
- {String||Dom}
content
:
- {String||Dom}
- 返回值:
this
show()
- 显示
- 返回值:
this
hide()
- 隐藏
- 返回值:
this
isVisible()
- 是否可见
- 返回值:
Bolean
remove()
- 从地图上移除
- 返回值:
this
bindTooltip(content, [options])
- 绑定提示消息组件
- 参数
- {String}
content
: - {Object}
options
:
- {String}
- 返回值:
this
removeTooltip()
- 移除提示消息组件
- 返回值:
this
bindPopup(content, options)
- 绑定气泡窗口,弹出框
- 参数
- {String}
content
: 文本内容 - {Object}
options
: 气泡基本配置
- {String}
- 返回值:
this
getPopup()
- 获取气泡对象
- 返回值: YY. Popup
openPoup([lnglat])
- 打开泡窗口,弹出框
- 参数
- {YY.LngLat}
lnglat
: 经纬度
- {YY.LngLat}
- 返回值:
this
closePopup()
- 关闭气泡对象
- 返回值:
this
removePopup()
- 移除气泡对象
- 返回值:
this
getMap()
- 获取地图对象
- 返回值: YY. Map
on(events, handler, [context])
事件监听
参数
- {String}
events
:click, ...... - {function}
handler
:处理函数 - {context}
context
:上下文,默认this
- {String}
返回值:
this
once(events, handler, [context])
事件监听只有一次
参数
- {String}
events
:click, ...... - {function}
handler
:处理函数 - {context}
context
:上下文,默认this
- {String}
返回值:
this
off(events, handler, [context])
移除事件监听
参数
- {String}
events
:click, ...... - {function}
handler
:处理函数 - {context}
context
:上下文,默认this
- {String}
返回值:
this
fire(eventType, param)
派发事件
参数
- {String}
eventType
:click, ...... - {Object}
param
:传递的参数
- {String}
返回值:
this