From ffccbccc2d64a0f015f1889fe1eb018d4d58738b Mon Sep 17 00:00:00 2001
From: yue1123 <2572468699@qq.com>
Date: Tue, 20 Jun 2023 00:56:15 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20scale=20=E6=94=AF=E6=8C=81visible?=
=?UTF-8?q?=E5=B1=9E=E6=80=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/zh-CN/components/control/scale.md | 9 +++----
packages/components/control/scale/index.vue | 27 +++++++++++++++------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/docs/zh-CN/components/control/scale.md b/docs/zh-CN/components/control/scale.md
index 9e684cb4..a5124f4a 100644
--- a/docs/zh-CN/components/control/scale.md
+++ b/docs/zh-CN/components/control/scale.md
@@ -21,11 +21,10 @@ control/scale
## 动态组件 Props
-动态绑定的值变更,会自动更新到地图中
-
-| 属性 | 说明 | 类型 | 可选值 | 默认值 |
-| ---- | ------------ | -------- | ------------- | ------------------ |
-| unit | 比例尺单位制 | `string` | [unit](#unit) | `BMAP_UNIT_METRIC` |
+| 属性 | 说明 | 类型 | 可选值 | 默认值 | 版本 |
+| ------- | ------------ | --------- | ------------- | ------------------ | ---------------------------------- |
+| unit | 比例尺单位制 | `string` | [unit](#unit) | `BMAP_UNIT_METRIC` | |
+| visible | 是否显示 | `boolean` | - | `true` | |
## anchor
diff --git a/packages/components/control/scale/index.vue b/packages/components/control/scale/index.vue
index c44e768b..e20470bc 100644
--- a/packages/components/control/scale/index.vue
+++ b/packages/components/control/scale/index.vue
@@ -21,34 +21,47 @@
* 比例尺单位制
*/
unit?: LengthUnit
+ /**
+ * 是否可见
+ */
+ visible?: boolean
}
const { ready } = useLifeCycle()
const props = withDefaults(defineProps(), {
anchor: 'BMAP_ANCHOR_BOTTOM_LEFT',
offset: () => ({ x: 83, y: 18 }),
- unit: 'BMAP_UNIT_METRIC'
+ unit: 'BMAP_UNIT_METRIC',
+ visible: true
})
let scaleCtrl: BMapGL.ScaleControl
defineEmits(['initd', 'unload'])
useBaseMapEffect((map) => {
+ const { visible, offset, anchor } = props
scaleCtrl = new BMapGL.ScaleControl({
- offset: new BMapGL.Size(props.offset.x, props.offset.y),
- anchor: window[props.anchor]
+ offset: new BMapGL.Size(offset.x, offset.y),
+ anchor: window[anchor]
})
+ visible && map.addControl(scaleCtrl)
setUnit()
- map.addControl(scaleCtrl)
ready(map, scaleCtrl)
+ watch(
+ () => props.visible,
+ (n) => {
+ map[n ? 'addControl' : 'removeControl'](scaleCtrl)
+ }
+ )
return () => map.removeControl(scaleCtrl)
})
// 监听比例尺单位变化
watch(() => props.unit, setUnit)
+ defineOptions({
+ name: 'BScale'
+ })
+
/**
* 设置比例尺单位制
*/
function setUnit() {
scaleCtrl.setUnit(window[props.unit])
}
- defineOptions({
- name: 'BScale'
- })