Giter VIP home page Giter VIP logo

yue1123 / vue3-baidu-map-gl Goto Github PK

View Code? Open in Web Editor NEW
337.0 6.0 40.0 37.46 MB

🎉百度地图 GL版 Vue3 组件库,baidu map gl components libary based on Vue3.0

Home Page: https://yue1123.github.io/vue3-baidu-map-gl/

License: MIT License

JavaScript 4.28% Vue 64.14% TypeScript 31.49% Shell 0.09%
baidumap-vue3 baidu-map-gl component-library component-package baidu-map vue3 map typescript vue baidumap

vue3-baidu-map-gl's Introduction

 Vue3 BaiduMap Gl 

易用 & 完整 & 高性能

GitHub package.json version (subfolder of monorepo) npm GitHub Repo stars GitHub issues GitHub closed issues

基于百度地图 JavaScript GL 版(使用了 WebGL 对地图、覆盖物等进行渲染,支持 3D 视角展示地图) API 封装设计的 Vue3 组件/hooks 库,开箱即用。

Star Star

如果喜欢这个项目,右上角给我们点个星星吧,这对我们意义非凡!

Backhand Index Pointing RightGlowing StarBackhand Index Pointing Left

Sparkles 特性

  • 🚀 自动加载百度地图 SDK,将百度地图繁琐的 Api 封装进组件,你只需关注组件本身
  • 📦 20+ 高质量的开箱即用 Vue 3 组件以及 8+ hooks 封装
  • 📐 遵循直觉的、简约的 Api 设计
  • ⚡ Composition Api,更好的性能
  • 🔨 完整的 TypeScript 支持,更好的体验
  • 🧩 tree shaking 支持,模块分包,只打包你想要的的
  • 🌏 基于百度地图 Gl 版 SDK,通过 WebGL 对地图、覆盖物等进行渲染,支持 3D 视角展示地图
  • 🚀 支持 volar,组件提供完善的代码提示

Gear 安装

推荐使用 pnpm 安装

# with pnpm
pnpm add vue3-baidu-map-gl

# or with yarn
yarn add vue3-baidu-map-gl

# or with npm
npm install vue3-baidu-map-gl

Open Book 文档

中文

Red Heart 赞助

此项目使用 MIT 协议,完全免费使用,如果您觉得项目对您有帮助,可以考虑适当的 赞助 支持此项目的开发

Hammer and Wrench 开发参与贡献

# 环境
# pnpm >= 6.0.0
# node >= 12.0.0

# clone
git clone https://github.com/yue1123/vue3-baidu-map-gl
cd ./vue3-baidu-map-gl

# install
pnpm install

# 运行文档站点,用来测试组件,预览文档
pnpm docs:dev

Star Star History

Star History Chart

License

MIT licenses

vue3-baidu-map-gl's People

Contributors

deepsource-io[bot] avatar myjustify avatar myltx avatar wanglei1020 avatar yue1123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vue3-baidu-map-gl's Issues

BInfoWindow组件报错

报错信息
`runtime-core.esm-bundler.js:41 [Vue warn]: Unhandled error during execution of watcher callback
at <BInfoWindow modelValue=true onUpdate:modelValue=fn enableMaximize="" ... >
at <BMap zoom=16 ak="cwHsf5i2fAQAlijOyELx5COtkFhItaSm" height="100vh" ... >
at
warn2 @ runtime-core.esm-bundler.js:41
runtime-core.esm-bundler.js:41 [Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core
at <BInfoWindow modelValue=true onUpdate:modelValue=fn enableMaximize="" ... >
at <BMap zoom=16 ak="cwHsf5i2fAQAlijOyELx5COtkFhItaSm" height="100vh" ... >
at
warn2 @ runtime-core.esm-bundler.js:41
Show 1 more frame
VM190:1 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'config')
at d2.setPosition (eval at run (getscript?type=webgl&v=1.0&ak=cwHsf5i2fAQAlijOyELx5COtkFhItaSm&services=&t=20230613170744:5:126869), :1:11263)
at setPosition (index.vue.js?v=43191f0d:174:24)
at index.vue.js?v=43191f0d:99:17
at helper.js?v=43191f0d:9:13
at callWithErrorHandling (runtime-core.esm-bundler.js:158:18)
at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:166:17)
at job (runtime-core.esm-bundler.js:1756:9)
at flushPreFlushCbs (runtime-core.esm-bundler.js:304:7)
at updateComponentPreRender (runtime-core.esm-bundler.js:5832:5)
at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5750:11)
client.ts:447

    GET http://localhost:5173/src/assets/main.css?t=1687321637195 net::ERR_ABORTED 404 (Not Found)

fetchUpdate @ client.ts:447
(anonymous) @ client.ts:159
handleMessage @ client.ts:157
(anonymous) @ client.ts:90
Show 4 more frames
client.ts:114 [hmr] Failed to reload /src/assets/main.css. This could be due to syntax errors or importing non-existent modules. (see errors above)
warnFailedFetch @ client.ts:114
fetchUpdate @ client.ts:453
await in fetchUpdate (async)
(anonymous) @ client.ts:159
handleMessage @ client.ts:157
(anonymous) @ client.ts:90
Show 5 more frames
client.ts:447

    GET http://localhost:5173/src/assets/main.css?t=1687321637196 net::ERR_ABORTED 404 (Not Found)

fetchUpdate @ client.ts:447
(anonymous) @ client.ts:159
handleMessage @ client.ts:157
(anonymous) @ client.ts:90
Show 4 more frames
client.ts:114 [hmr] Failed to reload /src/assets/main.css. This could be due to syntax errors or importing non-existent modules. (see errors above)`
目前我的临时解决方法是在BInfoWindow的setPosition中添加open()
复现demo
vue-project.zip

和elementPlus同时使用

和elementPlus同时使用时控制台会出现一堆警告,如果项目部引入地图或者不适用ElementPlus时就不会出现警告

zoomend无法对zoom进行监听

我这边会通过代码的方式修改地图的zoom,比如

zoom.value = 18
//或者
    map.value.getMapInstance().setZoom(18)

假如我目前的zoom是10,点击按钮后将zoom修改为18,地图可以正常修改zoom,但是zoomend中无法监听到18的状态。

    console.log(map.value.getMapInstance().getZoom())

目前我想实现当zoom动画结束后,如果zoom大于12,则tilt为45,否则为0
目前由于无法监听zoom,没法实现这个效果。

请问这是BUG还是我的代码有问题?

BInfoWindow的信息窗口 投射的阴影想问下怎么去除

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

离线api

内网使用百度地图一般是直接在index.html引入api,没有ak,应该怎么配

自定义加载如何实现?

按照文档说明,我的代码大致如下:

<BMap :heading="mapOpts.heading" :tilt="mapOpts.tilt" :center="center" @initd="initd">

  <template #loading="{ isLoading }">
    <a-spin v-if="isLoading"></a-spin>
  </template>
</BMap>

const isLoading = ref(false);

function initd(){
isLoading.value = true;
}

不能成功。报错:runtime-dom.esm-bundler.js:10 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'insertBefore')。请指教。

我引用这个插件,但是一直报一个错,大佬有空帮忙看看吗?以下是代码和贴图

报错
image

代码
` <BMap
enableScrollWheelZoom
ref="map"
:center="location.point || undefined"
@initd="get"
>



。。。。。
import { BMap } from 'vue3-baidu-map-gl'
import { useIpLocation } from 'vue3-baidu-map-gl'
const isLoading = ref()
const map = ref()
const { get, location } = useIpLocation(() => {
map.value.resetCenter()
})
。。。。
import { createApp } from 'vue'
import baiduMap from 'vue3-baidu-map-gl'
import App from './App.vue'
import router from './router'

import './assets/style/main.scss'
import { globalRegister } from '@/global/register'

const app = createApp(App)
globalRegister(app)
app.use(router)
app.use(baiduMap, {
ak: 'b9ZvWgXRS45HNLXcAPPOGi0zG7fp7Mzc',
plugins: ['TrackAnimation']
})
app.mount('#app')
`

[.WebGL-0x11c08b8a300] GL_INVALID_FRAMEBUFFER_OPERATION

[.WebGL-0x11c08b8a300] GL_INVALID_FRAMEBUFFER_OPERATION: Framebuffer is incomplete: Attachment has zero size.
:5175/app-dev/#/page/drugstore:1 [.WebGL-0x11c08b8a300] GL_INVALID_FRAMEBUFFER_OPERATION: Draw framebuffer is incomplete

console 里 报了一长串的这个错误,你知道是怎么回事吗,用的router,进到地图页面就会出现这个,刷新地图页面,不会有!

更新marker数据报错

Map.vue:46  [Vue warn]: Unhandled error during execution of watcher callback 
  at <BInfoWindow modelValue=false onUpdate:modelValue=fn<onUpdate:modelValue> position= {lat: 39.915185, lng: 50.400901}  ... > 
  at <BMap enableScrollWheelZoom="" center= {lat: 39.915185, lng: 116.400901} zoom=16  ... > 
  at <Map> 
  at <App>
warn2 @ runtime-core.esm-bundler.js:41
logError @ runtime-core.esm-bundler.js:216
handleError @ runtime-core.esm-bundler.js:208
callWithErrorHandling @ runtime-core.esm-bundler.js:160
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:166
job @ runtime-core.esm-bundler.js:1756
flushPreFlushCbs @ runtime-core.esm-bundler.js:304
updateComponentPreRender @ runtime-core.esm-bundler.js:5832
componentUpdateFn @ runtime-core.esm-bundler.js:5750
run @ reactivity.esm-bundler.js:178
instance.update @ runtime-core.esm-bundler.js:5814
updateComponent @ runtime-core.esm-bundler.js:5641
processComponent @ runtime-core.esm-bundler.js:5576
patch @ runtime-core.esm-bundler.js:5040
patchBlockChildren @ runtime-core.esm-bundler.js:5427
processFragment @ runtime-core.esm-bundler.js:5513
patch @ runtime-core.esm-bundler.js:5014
patchKeyedChildren @ runtime-core.esm-bundler.js:5965
patchChildren @ runtime-core.esm-bundler.js:5842
processFragment @ runtime-core.esm-bundler.js:5539
patch @ runtime-core.esm-bundler.js:5014
patchBlockChildren @ runtime-core.esm-bundler.js:5427
processFragment @ runtime-core.esm-bundler.js:5513
patch @ runtime-core.esm-bundler.js:5014
patchBlockChildren @ runtime-core.esm-bundler.js:5427
processFragment @ runtime-core.esm-bundler.js:5513
patch @ runtime-core.esm-bundler.js:5014
componentUpdateFn @ runtime-core.esm-bundler.js:5773
run @ reactivity.esm-bundler.js:178
instance.update @ runtime-core.esm-bundler.js:5814
callWithErrorHandling @ runtime-core.esm-bundler.js:158
flushJobs @ runtime-core.esm-bundler.js:357
Promise.then (async)
queueFlush @ runtime-core.esm-bundler.js:270
queueJob @ runtime-core.esm-bundler.js:264
(anonymous) @ runtime-core.esm-bundler.js:5810
triggerEffect @ reactivity.esm-bundler.js:373
triggerEffects @ reactivity.esm-bundler.js:363
triggerRefValue @ reactivity.esm-bundler.js:974
set value @ reactivity.esm-bundler.js:1018
on_click @ Map.vue:46
callWithErrorHandling @ runtime-core.esm-bundler.js:158
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:166
invoker @ runtime-dom.esm-bundler.js:278
Show 42 more frames
Map.vue:46  [Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core 
  at <BInfoWindow modelValue=false onUpdate:modelValue=fn<onUpdate:modelValue> position= {lat: 39.915185, lng: 50.400901}  ... > 
  at <BMap enableScrollWheelZoom="" center= {lat: 39.915185, lng: 116.400901} zoom=16  ... > 
  at <Map> 
  at <App>
warn2 @ runtime-core.esm-bundler.js:41
logError @ runtime-core.esm-bundler.js:216
handleError @ runtime-core.esm-bundler.js:208
callWithErrorHandling @ runtime-core.esm-bundler.js:160
flushJobs @ runtime-core.esm-bundler.js:357
Promise.then (async)
queueFlush @ runtime-core.esm-bundler.js:270
queueJob @ runtime-core.esm-bundler.js:264
(anonymous) @ runtime-core.esm-bundler.js:5810
triggerEffect @ reactivity.esm-bundler.js:373
triggerEffects @ reactivity.esm-bundler.js:363
triggerRefValue @ reactivity.esm-bundler.js:974
set value @ reactivity.esm-bundler.js:1018
on_click @ Map.vue:46
callWithErrorHandling @ runtime-core.esm-bundler.js:158
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:166
invoker @ runtime-dom.esm-bundler.js:278
Show 15 more frames
VM563:1  Uncaught (in promise) TypeError: Cannot read properties of null (reading 'config')
    at d2.setPosition (eval at run (getscript?type=webgl&v=1.0&ak=YmrAaBGDvnakP8kOoVwX1O4FX0w3g1yZ&services=&t=20230613170744:5:126869), <anonymous>:1:11263)
    at setPosition (index.vue.js?v=c6480c8b:173:24)
    at index.vue.js?v=c6480c8b:98:17
    at helper.js?v=c6480c8b:9:13
    at callWithErrorHandling (runtime-core.esm-bundler.js:158:18)
    at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:166:17)
    at job (runtime-core.esm-bundler.js:1756:9)
    at flushPreFlushCbs (runtime-core.esm-bundler.js:304:7)
    at updateComponentPreRender (runtime-core.esm-bundler.js:5832:5)
    at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5750:11)

报错信息和[#32]的报错信息一样

  <template :key="i" v-for="(item, i) of table">
      <BMarker
        :position="item.position"
        icon="blue1"
        v-on:click="item.show = true"
        enableClicking
      />
      <BInfoWindow
        v-model="item.show"
        :position="item.position"
        title="停车场信息"
        enableAutoPan
        enableCloseOnClick
      >
        {{ item.title }}
      </BInfoWindow>
    </template>

用template包裹marker和infoWindow更新tableList会报错

复现demo如下
vue-project.zip

【BUG】Marker的position属性不会自动更新,需要强制重新渲染

需要完成的Feature

点击地图某处,获取到点击事件和坐标,重新设置marker的坐标,使之与点击处重合

问题

实际上点击以后ref的值已经刷新,model内的值也已经刷新并且同步到了BMarker,但是显示并没有刷新,并且,如果不使用 :position="{ lat: singlePoint.lat, lng: singlePoint.lng }" 这样的操作而是直接 :position="singlePoint"的话,Marker会失效

代码

<template>
    <BMap 
        width="100%" 
        :height="parentHeight" 
        :ak="mapAk" 
        enableScrollWheelZoom 
        ref="map"
        :center="location.point || undefined" @initd="get" :mapType="mapType"
        @click="handleMapClick"
    >
        <BMarker :position="{ lat: singlePoint.lat, lng: singlePoint.lng }" icon="simple_red" />
    </BMap>
</template>
<script setup lang="ts">
import { onMounted, ref, PropType, watch, computed } from 'vue'
import {
    BMap,
    BZoom,
    BScale,
    BNavigation3d,
    BControl,
    BMarker,
    useBrowserLocation,
    MapType,
    BLocation,
} from 'vue3-baidu-map-gl'

const mapAk = ref((import.meta as any).env.VITE_APP_BMAP_AK)
const map = ref()
const { get, location, isLoading, isError, status } = useBrowserLocation(null, () => {
    map.value.resetCenter()
})

const parentHeight = ref(550)

onMounted(() => {
    // get parent element through map instance
    const parent = map.value.$el.parentElement
    parentHeight.value = parent.clientHeight
})

type MapCoordinatePoint = {
    lng: number
    lat: number
}

const singlePoint = defineModel<MapCoordinatePoint>('point', {
    required: false,
    default: {
        lng: 0,
        lat: 0,
    },
})

const handleMapClick = ({
    target, latlng
}: {
    target: HTMLDivElement,
    latlng: { lat: number, lng: number }
}) => {
    singlePoint.value.lat = latlng.lat
    singlePoint.value.lng = latlng.lng
}
</script>

环境

  • OS: MacOS M2 OSX 13.5 (22G74)
  • Browser: Edge 117.0.2045.40
  • Version: 2.3.0

使用mapvgl创建three.js图层报错

function handlePluginReady(map) {
const threeLayer = new mapvgl.ThreeLayer();
}
执行上面函数,使用mapvgl,版本1.0.0-beta.185,创建three.js图层报错,错误如下:
[Vue3 BaiduMap GL/BMap]: plugins load error: TypeError: mapvgl.ThreeLayer is not a constructor

BInfoWindow组件关闭后无法再显示。

大佬您好:smile:,我最近在使用vue3-baidu-map-gl时,遇到了点小问题。

官方示例

百度地图JS API官方示例中,信息窗口默认关闭,点击红色标注点后信息窗口显示,点击其他地方信息窗口关闭。再次点击该红色标注点时,信息窗口能再次打开。

问题复现

vue3-baidu-map-gl示例中,如 #23 中代码,信息窗口默认打开,点击其他地方信息窗口关闭。
点击其他点可以正常显示信息窗口,但是刚刚关闭的信息窗口无法再次打开,如下图:
issue

Prism能否增加空心的区域

坐标济南,高新区很多飞地,被其他区包围。
可以理解为意大利里面包着个梵蒂冈。
Prism目前好像不支持空心区域,导致飞地与原有区域重合。

比如选择梵蒂冈的时候,也会选到意大利,还有就是由于颜色叠加,梵蒂冈和意大利的颜色无法统一。
请问未来Prism有支持空心区域的计划么?

如何创建一个Point类型的点

想问下作者有提供方法,创建Point类型的点么,在做跳转其他经纬度点的时候发现,不能通过new BMap.Point创建点,有提供类似方法吗?

BLabel 支持自定义 class

<BLabel
  :content="text"
  :position="{ lng: coordinates[0], lat: coordinates[1] }"
  class="mark-label">
</BLabel>

<style scoped>
.mark-label {
  color: #000;
  background-color: rgb(255 197 109);
  padding: 2px;
  font-size: 12px;
  border: 0px;
  border-radius: 3px;
  transform: translate(-50%, 14px);
  cursor: pointer;
}
</style>

渲染后可将自定义的 class 合并进来

<label class=" BMapLabel mark-label" unselectable="on" style="...>我的标签</label>

怎么实现 拖动地图实现定位功能?

怎么实现 拖动地图实现定位功能? 就类似京东中 的地址的定位地址, 点击右下按钮出现红色气泡, 此时拖动地图, 中心红色气泡还位于地图的中心, 实现了拖动地图, 把中心红色气泡挪到自己想要的位置,
我绑定了BMap地图的 dragging事件, 但是事件拿到四个参数{type, target, pixel, point} 其中point打印控制台很奇怪point: cD{"lng": 13432583.183799399,"lat": 3553216.716987373}, 有什么思路可以提供吗

feat: point-collection

vue-baidu-map 这个库有个 BmPointCollection 海量点,我的项目中也需要这个,目前想把项目转为vue3,但是在您的文档中未发现这个功能,还是说可以换其他的方式实现 BmPointCollection ?

useTrackAnimation hooks 若 options.delay > 0 则导致 status 更新失败

代码

const { setPath, start, cancel, stop, proceed, status } = useTrackAnimation(map, {
  duration: 30000,
  delay: 300, // >0 
  tilt: 55,
  overallView: true,
  zoom: 14,
})

watch(status, (newVal, oldVal) => {
  // 不会调用
  console.log(oldVal ,'->', newVal)
})

错误提示

useTrackAnimation.js:40 Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener')
    at useTrackAnimation.js:40:35

原因
instance.start() 之后, 会延迟 options.delay 之后初始化 instance._viewAni

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.