提交 ee478d08 编写于 作者: L liyongning

upd: 移除 polygon 的点击事件(兼容微信小程序)

上级 b81b45f1
......@@ -30,7 +30,6 @@ import MapLocation, {
CONTEXT_ID as MAP_LOCATION_CONTEXT_ID,
} from './MapLocation'
import MapPolygon from './map-polygon/index'
import { eventObj } from './map-polygon/event'
import { Polygon } from './map-polygon/interface'
const props = {
......@@ -459,8 +458,6 @@ export default /*#__PURE__*/ defineBuiltInComponent({
'update:scale',
'update:latitude',
'update:longitude',
// MapPolygon 组件对外暴露的事件
...Object.values(eventObj),
],
setup(props, { emit, slots }) {
const rootRef: Ref<HTMLElement | null> = ref(null)
......
import { Maps } from '../maps'
import { QQMaps } from '../maps/qq/types'
import { CustomEventTrigger, EventObj } from './interface'
const { assign, create } = Object
// 事件对象,以腾讯原生事件名为 key,对外暴露的对应事件名为 value
export const eventObj: EventObj = assign(create(null), {
// 点击此多边形后会触发此事件
click: 'polygontap',
})
/**
* 监听事件,当对应事件发生时,将事件暴露给用户
*/
export function listenEvent(
maps: Maps,
polygonIns: HTMLElement,
trigger: CustomEventTrigger
) {
for (let key in eventObj) {
;(maps as QQMaps).event.addDomListener(
polygonIns,
key,
function (e: MouseEvent) {
// 要对外暴露的事件
const eVal = eventObj[key]
e ? trigger(eVal, {} as Event, e) : trigger(eVal, {} as Event)
}
)
}
}
......@@ -11,14 +11,11 @@ import {
} from './interface'
import { Map, Maps } from '../maps'
import { QQMaps } from '../maps/qq/types'
import { eventObj, listenEvent } from './event'
import { hexToRgba } from '../../../../helpers/hexToRgba'
export default defineSystemComponent({
name: 'MapPolygon',
props,
// https://lbs.qq.com/javascript_v2/doc/polygon.html
emits: Object.values(eventObj),
setup(props: Props) {
// polygon 实例
let polygonIns: Polygon
......@@ -104,9 +101,6 @@ export default defineSystemComponent({
// 说明是新增区域
polygonIns = new maps.Polygon(polygonOptions)
// 监听事件,当对应事件发生时,将事件暴露给用户
listenEvent(maps, polygonIns as unknown as HTMLElement, trigger)
}
// 给地图添加区域
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册