From 7d39fd63518686b6586e8265a3d63d4cc94f9ce7 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Sun, 4 Sep 2022 01:08:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(h5=20map=20control):=20=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E6=B7=BB=E5=8A=A0=E6=96=B9=E5=BC=8F=E5=8F=8A=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=B7=BB=E5=8A=A0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/view/components/map/MapControl.tsx | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/uni-h5/src/view/components/map/MapControl.tsx b/packages/uni-h5/src/view/components/map/MapControl.tsx index f7081cceb..258e0b964 100644 --- a/packages/uni-h5/src/view/components/map/MapControl.tsx +++ b/packages/uni-h5/src/view/components/map/MapControl.tsx @@ -1,10 +1,7 @@ import { inject, onUnmounted, watch, PropType } from 'vue' import { getRealPath } from '@dcloudio/uni-platform' import { defineSystemComponent, useCustomEvent } from '@dcloudio/uni-components' -import { Maps, Map, QQMap, GoogleMap } from './maps' -import { getIsAMap } from '../../../helpers/location' -import { QQMaps } from './maps/qq/types' -import { GoogleMaps } from './maps/google/types' +import { Maps, Map } from './maps' interface Position { left: number | string @@ -41,27 +38,27 @@ export default /*#__PURE__*/ defineSystemComponent({ control.remove() } } - onMapReady((map, maps, trigger) => { + onMapReady((_, __, trigger) => { function updateControl(option: Props) { removeControl() addControl(option) } function addControl(option: Props) { - const position = option.position || {} control = document.createElement('div') - const img = new Image() - control.appendChild(img) const style = control.style style.position = 'absolute' style.width = '0' style.height = '0' style.top = '0' style.left = '0' + const img = new Image() + img.src = getRealPath(option.iconPath) img.onload = () => { - if (option.position.width) { + const position = option.position || {} + if (position.width) { img.width = option.position.width } - if (option.position.height) { + if (position.height) { img.height = option.position.height } const style = img.style @@ -69,8 +66,10 @@ export default /*#__PURE__*/ defineSystemComponent({ style.left = (position.left || 0) + 'px' style.top = (position.top || 0) + 'px' style.maxWidth = 'initial' + + control.appendChild(img) + props.rootRef.value && props.rootRef.value.appendChild(control) } - img.src = getRealPath(option.iconPath) img.onclick = function ($event) { if (option.clickable) { trigger('controltap', $event, { @@ -78,13 +77,6 @@ export default /*#__PURE__*/ defineSystemComponent({ }) } } - if (getIsAMap()) { - props.rootRef.value && props.rootRef.value.appendChild(control) - } else { - ;(map as QQMap | GoogleMap).controls[ - (maps as QQMaps | GoogleMaps).ControlPosition.TOP_LEFT - ].push(control) - } } addControl(props as Props) watch(props, updateControl) -- GitLab