-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<Map enable-scroll-wheel-zoom :zoom="9"> | ||
<DistrictLayer | ||
@mouseover="handleMouseover" | ||
@mouseout="handleMouseout" | ||
viewport | ||
:kind="DistrictType['AREA']" | ||
name="北京市" | ||
/> | ||
</Map> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { DistrictType } from 'vue3-baidu-map-gl' | ||
function handleMouseover(e) { | ||
e.currentTarget.setFillColor('#9169db') | ||
} | ||
function handleMouseout(e) { | ||
e.currentTarget.setFillColor(e.currentTarget.style.fillColor) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# DistrictLayer 行政区图层 <Badge type="tip" text="^1.1.2" /> | ||
|
||
在地图上显示行政区划分 | ||
|
||
```ts | ||
import { DistrictLayer } from 'vue3-baidu-map-gl' | ||
``` | ||
|
||
## 组件示例 | ||
|
||
:::demo 渲染北京市行政区划分,绑定鼠标事件 | ||
layer/districtLayer | ||
::: | ||
|
||
## 静态组件 Props | ||
|
||
| 属性 | 说明 | 类型 | 可选值 | 默认值 | | ||
| ----------- | ---------------- | ------------------------------- | ------ | ---------------------- | | ||
| name | 行政区名字 | `string` | - | `required` | | ||
| kind | 行政区类型 | [`DistrictType`](#districttype) | - | `DistrictType['AREA']` | | ||
| fillColor | 填充颜色 | `string` | - | `#fdfd27` | | ||
| fillOpacity | 填充透明度 | `number` | - | `1` | | ||
| strokeColor | 线条颜色 | `string` | - | `#231cf8` | | ||
| viewport | 自动聚焦地图中心 | `boolean` | - | `false` | | ||
|
||
## DistrictType | ||
|
||
| 值 | 说明 | | ||
| -------- | ------- | | ||
| PROVINCE | 省级 | | ||
| CITY | 市级 | | ||
| AREA | 县/区级 | | ||
|
||
## 组件事件 | ||
|
||
| 事件名 | 说明 | 类型 | | ||
| --------- | ------------------------------------------ | --------------------------- | | ||
| initd | 组件初始化后,调用的方法,返回一个地图实例 | `{ map, BmapGL, instance }` | | ||
| unload | 组件卸载时会调用此方法 | - | | ||
| mouseover | 鼠标移入行政区域时触发此事件 | `{type, target}` | | ||
| mouseout | 鼠标移出行政区域时触发此事件 | `{type, target}` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as DistrictLayer } from './index.vue' | ||
export * from './index.vue' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<template></template> | ||
|
||
<script setup lang="ts"> | ||
import { defineProps, withDefaults } from 'vue' | ||
import useLifeCycle from '../../../hooks/useLifeCycle' | ||
import useBaseMapEffect from '../../../hooks/useBaseMapEffect' | ||
import { warn, type Callback, type DistrictType, bindEvents } from '../../../utils' | ||
export interface DistrictLayerProps { | ||
/** | ||
* 行政区名字 | ||
*/ | ||
name: string | ||
/** | ||
* @default 0 | ||
* 行政区类型 | ||
*/ | ||
kind?: DistrictType | ||
/** | ||
* @default #fdfd27 | ||
* 填充颜色 | ||
*/ | ||
fillColor?: string | ||
/** | ||
* @default 1 | ||
* 填充透明度 | ||
*/ | ||
fillOpacity?: number | ||
/** | ||
* @default #231cf8 | ||
* 线条颜色 | ||
*/ | ||
strokeColor?: string | ||
/** | ||
* @default false | ||
* 自动聚焦地图中心 | ||
*/ | ||
viewport?: boolean | ||
onClick?: Callback | ||
onDblclick?: Callback | ||
onRightclick?: Callback | ||
onRightdblclick?: Callback | ||
onMousemove?: Callback | ||
onMouseover?: Callback | ||
onMouseout?: Callback | ||
} | ||
const { ready } = useLifeCycle() | ||
const props = withDefaults(defineProps<DistrictLayerProps>(), { | ||
kind: 0, | ||
fillColor: '#fdfd27', | ||
fillOpacity: 1, | ||
strokeColor: '#231cf8', | ||
viewport: false | ||
}) | ||
let districtLayer: BMapGL.DistrictLayer | ||
const vueEmits = defineEmits(['initd', 'unload', 'mouseover', 'mouseout', 'click']) | ||
useBaseMapEffect((map) => { | ||
if (!props.name) return warn('DistrictLayer props.name is required') | ||
const { name, kind, fillColor, fillOpacity, strokeColor, viewport } = props | ||
districtLayer = new BMapGL.DistrictLayer({ | ||
name: `(${name})`, | ||
kind, | ||
fillColor, | ||
fillOpacity, | ||
strokeColor, | ||
viewport | ||
}) | ||
map.addDistrictLayer(districtLayer) | ||
bindEvents(props, vueEmits, districtLayer) | ||
ready(map, districtLayer) | ||
return () => map.removeDistrictLayer(districtLayer) | ||
}) | ||
</script> | ||
<script lang="ts"> | ||
export default { | ||
name: 'BDistrictLayer' | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters