Skip to content

Commit

Permalink
feat: 优化代码 & 增加地面叠加层覆盖物
Browse files Browse the repository at this point in the history
  • Loading branch information
yue1123 committed Nov 12, 2022
1 parent 3069bb4 commit 60cb9bb
Show file tree
Hide file tree
Showing 15 changed files with 445 additions and 36 deletions.
4 changes: 4 additions & 0 deletions docs/.vitepress/sidebar.config.zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ const sidebarConfig = {
{
text: 'Prism 3d棱柱',
link: '/zh/overlay/prism'
},
{
text: 'GroundOverlay 地面叠加层',
link: '/zh/overlay/ground-overlay'
}
]
},
Expand Down
16 changes: 16 additions & 0 deletions docs/public/bounds.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/cloud.mov
Binary file not shown.
Binary file added docs/public/shouhuimap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
275 changes: 275 additions & 0 deletions docs/zh/overlay/ground-overlay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
# 地面叠加层

在地图底面上叠加覆盖物,覆盖物可以是图片、自定义 Canvas、视频。

```ts
import { GroundOverlay } from 'vue3-baidu-map-gl'
```

## 组件示例

<div>
地面叠加层类型:
<select class="mySelect" name="" id="" v-model="activeKey">
<option value="image">image 图片叠加层</option>
<option value="video">video 视频叠加层</option>
<option value="canvas">canvas 画布叠加层</option>
</select>
<Map
enableScrollWheelZoom
noAnimation
:displayOptions="{
poiText: false, // 隐藏poi标注
poiIcon: false, // 隐藏poi图标
building: false // 隐藏楼块
}"
:tilt="groundOverlay.tilt || 0"
:zoom="groundOverlay.zoom"
>
<Marker
:position="groundOverlay.startPoint"
icon="start"
:offset="{x: 0, y: -16 }"
/>
<Marker
:position="groundOverlay.endPoint"
icon="end"
:offset="{x: 0, y: -16 }"
/>
<GroundOverlay
autoCenter
:type="activeKey"
:startPoint="groundOverlay.startPoint"
:endPoint="groundOverlay.endPoint"
:url="groundOverlay.url"
:opacity="groundOverlay.opacity"
/>
<Label
v-if="activeKey === 'canvas'"
content="日坛公园"
:position="{lng: 116.449921, lat: 39.921324}"
:style="{
color: '#fff',
borderWidth:'1px',
borderRadius: '5px',
borderColor: '#fff',
backgroundColor: '#79a913',
fontSize: '16px',
height: '30px',
lineHeight: '30px'
}"
/>
</Map>
</div>

<script lang="ts" setup>
import { ref, computed } from 'vue'

const activeKey = ref<'image' | 'canvas' | 'video'>('canvas')

const groundOverlays = ref({
canvas: {
zoom: 17,
opacity: 1,
startPoint: { lng: 116.447717, lat: 39.919173 },
endPoint: { lng: 116.453125, lat: 39.923475 },
url: () => {
var textureCanvas = document.createElement('canvas')
textureCanvas.width = textureCanvas.height = 200
var ctx = textureCanvas.getContext('2d')
ctx.fillStyle = '#79a913'
ctx.strokeStyle = 'white'
ctx.lineWidth = 6
ctx.lineCap = 'square'
ctx.fillRect(0, 0, 200, 200)
ctx.moveTo(50, 50)
ctx.lineTo(150, 50)
ctx.lineTo(150, 150)
ctx.lineTo(50, 150)
ctx.lineTo(50, 50)
ctx.stroke()
return textureCanvas
}
},
image: {
tilt: 45,
zoom: 18,
opacity: 1,
startPoint: { lng: 117.19635, lat: 36.24093 },
endPoint: { lng: 117.20350, lat: 36.24764 },
url: '/shouhuimap.png'
},
video: {
zoom: 4,
opacity: 0.5,
startPoint: { lng: 94.582033, lat: -7.989754 },
endPoint: { lng: 145.358572, lat: 30.813867 },
url: '/cloud.mov'
}
})

const groundOverlay = computed(() => {
return groundOverlays.value[activeKey.value]
})
</script>

:::details 点击查看代码

<!-- prettier-ignore -->
```html
<div>
地面叠加层类型:
<select class="mySelect" name="" id="" v-model="activeKey">
<option value="image">image 图片叠加层</option>
<option value="video">video 视频叠加层</option>
<option value="canvas">canvas 画布叠加层</option>
</select>
<Map
enableScrollWheelZoom
noAnimation
:displayOptions="{
poiText: false, // 隐藏poi标注
poiIcon: false, // 隐藏poi图标
building: false // 隐藏楼块
}"
:tilt="groundOverlay.tilt || 0"
:zoom="groundOverlay.zoom"
>
<Marker
:position="groundOverlay.startPoint"
icon="start"
:offset="{x: 0, y: -16 }"
/>
<Marker
:position="groundOverlay.endPoint"
icon="end"
:offset="{x: 0, y: -16 }"
/>
<GroundOverlay
autoCenter
:type="activeKey"
:startPoint="groundOverlay.startPoint"
:endPoint="groundOverlay.endPoint"
:url="groundOverlay.url"
:opacity="groundOverlay.opacity"
/>
<Label
v-if="activeKey === 'canvas'"
content="日坛公园"
:position="{lng: 116.449921, lat: 39.921324}"
:style="{
color: '#fff',
borderWidth:'1px',
borderRadius: '5px',
borderColor: '#fff',
backgroundColor: '#79a913',
fontSize: '16px',
height: '30px',
lineHeight: '30px'
}"
/>
</Map>
</div>

<script lang="ts" setup>
import { ref, computed } from 'vue'
import { GroundOverlay } from 'vue3-baidu-map-gl'
const activeKey = ref<'image' | 'canvas' | 'video'>('image')
const groundOverlays = ref({
canvas: {
zoom: 17,
opacity: 1,
startPoint: { lng: 116.447717, lat: 39.919173 },
endPoint: { lng: 116.453125, lat: 39.923475 },
url: () => {
var textureCanvas = document.createElement('canvas')
textureCanvas.width = textureCanvas.height = 200
var ctx = textureCanvas.getContext('2d')
ctx.fillStyle = '#79a913'
ctx.strokeStyle = 'white'
ctx.lineWidth = 6
ctx.lineCap = 'square'
ctx.fillRect(0, 0, 200, 200)
ctx.moveTo(50, 50)
ctx.lineTo(150, 50)
ctx.lineTo(150, 150)
ctx.lineTo(50, 150)
ctx.lineTo(50, 50)
ctx.font = '148px serif'
ctx.fillText('Hello world', 50, 50)
// ctx.stroke()
return textureCanvas
}
},
image: {
tilt: 45,
zoom: 18,
opacity: 1,
startPoint: { lng: 117.19635, lat: 36.24093 },
endPoint: { lng: 117.2035, lat: 36.24764 },
url: '/shouhuimap.png'
},
video: {
zoom: 4,
opacity: 0.5,
startPoint: { lng: 94.582033, lat: -7.989754 },
endPoint: { lng: 145.358572, lat: 30.813867 },
url: '/cloud.mov'
}
})
const groundOverlay = computed(() => {
return groundOverlays.value[activeKey.value]
})
</script>
```

:::

## 动态组件 Props

| 属性 | 说明 | 类型 | 默认值 |
| ---------- | ---------------------------------------------------- | ----------------------------- | ---------- |
| type | 地面叠加物类型 | `video \| canvas \| image` | `required` |
| url | 叠加物 image url、video url 或者自定义的 canvas 对象 | [`urlType` ](#urltype) | `required` |
| startPoint | 显示区域开始点,见[图示](#bounds-图示) | `{ lng: number, lat: number}` | `required` |
| endPoint | 显示区域结束点,见[图示](#bounds-图示) | `{ lng: number, lat: number}` | `required` |
| autoCenter | 是否自动根据地面叠加物显示区域居中地图 | `boolean ` | `true` |
| opacity | 透明度,范围 0-1 | `RangeOf2<0, 1>` | |

### bounds 图示

<br />
<div class="bounds-image">
<img src="/bounds.svg" alt="">
</div>

<style>
.dark .bounds-image{
width: 60%;
background: var(--vp-c-text-1);
}
</style>

### urlType

```ts
type url =
| string
| HTMLCanvasElement
| Ref<HTMLCanvasElement | string>
| (() => HTMLCanvasElement | Ref<HTMLCanvasElement | string>)
```
## 组件事件
| 事件名 | 说明 | 类型 |
| --------- | -------------------------------------------------------------------------------------- | --------------------------- |
| initd | 组件初始化后,调用的方法,返回一个地图实例 | `{ map, BmapGL, instance }` |
| unload | 组件卸载时会调用此方法 | - |
| click | 鼠标左键单击事件的回调函数。 当双击时,产生的事件序列为: `click -> click -> dblclick` | ` ((e: Event) => void)` |
| dblclick | 鼠标左键双击事件的回调函数 | ` ((e: Event) => void)` |
| mouseout | 鼠标指针移出该覆盖物事件的回调函数 | ` ((e: Event) => void)` |
| mouseover | 鼠标指针移入该覆盖物事件的回调函数 | ` ((e: Event) => void)` |
| mousemove | 鼠标指针在该覆盖物移动的事件的回调函数 | ` ((e: Event) => void)` |
2 changes: 1 addition & 1 deletion docs/zh/overlay/label.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { Label } from 'vue3-baidu-map-gl'
<!-- prettier-ignore -->
```html
<Map :minZoom="3" >
<label
<Label
content="欢迎使用百度地图GL版Vue3组件库"
:position="{lng: 116.404, lat: 39.915 }"
:style="{
Expand Down
27 changes: 14 additions & 13 deletions docs/zh/overlay/polygon.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { Polygon } from 'vue3-baidu-map-gl'
:minZoom="3"
:zoom="zoom"
enableScrollWheelZoom
@initd="handleInitd"
>
<Control style="border-radius:4px;box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);color: #666;background:#fff;padding:10px;" :offset="{ x: 15, y: 15 }">
<span> 地区:</span>
Expand All @@ -74,7 +75,6 @@ import { Polygon } from 'vue3-baidu-map-gl'
</Control>
<Polygon
:key="area"
@initd="handleInitd"
isBoundary
:path="point"
stroke-color="#000"
Expand Down Expand Up @@ -160,6 +160,7 @@ import { Polygon } from 'vue3-baidu-map-gl'
})

function handleInitd(){
console.log(11)
get(area.value)
}
watch(() => area.value, get)
Expand Down Expand Up @@ -191,15 +192,15 @@ import { Polygon } from 'vue3-baidu-map-gl'

## 组件事件

| 事件名 | 说明 | 类型 |
| ---------- | --------------------------------------------------------------------------------------- | ---------------------- |
| initd | 组件初始化后,调用的方法,返回一个地图实例 | `{ map, BmapGL, instance }` |
| unload | 组件卸载时会调用此方法 | - |
| click | 鼠标左键单击事件的回调函数。 当双击时,产生的事件序列为: `click -> click -> dblclick ` | `((e: Event) => void)` |
| dblclick | 鼠标左键双击事件的回调函数 | `((e: Event) => void)` |
| mousedown | 鼠标左键在该覆盖物上按下的回调函数 | `((e: Event) => void)` |
| mouseup | 鼠标左键在该覆盖物上抬起的回调函数 | `((e: Event) => void)` |
| mouseout | 鼠标指针移出该覆盖物事件的回调函数 | `((e: Event) => void)` |
| mouseover | 鼠标指针移入该覆盖物事件的回调函数 | `((e: Event) => void)` |
| remove | 该覆盖物被移除的回调函数 | `((e: Event) => void)` |
| lineupdate | 覆盖物被编辑后的回调函数 | `((e: Event) => void)` |
| 事件名 | 说明 | 类型 |
| ---------- | --------------------------------------------------------------------------------------- | --------------------------- |
| initd | 组件初始化后,调用的方法,返回一个地图实例 | `{ map, BmapGL, instance }` |
| unload | 组件卸载时会调用此方法 | - |
| click | 鼠标左键单击事件的回调函数。 当双击时,产生的事件序列为: `click -> click -> dblclick ` | `((e: Event) => void)` |
| dblclick | 鼠标左键双击事件的回调函数 | `((e: Event) => void)` |
| mousedown | 鼠标左键在该覆盖物上按下的回调函数 | `((e: Event) => void)` |
| mouseup | 鼠标左键在该覆盖物上抬起的回调函数 | `((e: Event) => void)` |
| mouseout | 鼠标指针移出该覆盖物事件的回调函数 | `((e: Event) => void)` |
| mouseover | 鼠标指针移入该覆盖物事件的回调函数 | `((e: Event) => void)` |
| remove | 该覆盖物被移除的回调函数 | `((e: Event) => void)` |
| lineupdate | 覆盖物被编辑后的回调函数 | `((e: Event) => void)` |
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@rollup/plugin-commonjs": "^21.0.3",
"@rollup/plugin-node-resolve": "^14.1.0",
"@rollup/plugin-replace": "^4.0.0",
"@types/node": "^18.11.9",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
Expand Down
Loading

0 comments on commit 60cb9bb

Please sign in to comment.