Giter VIP home page Giter VIP logo

vue-baidu-map-3x's Introduction

VUE3 BAIDU MAP

baidu-map组件通过vite构建的vue3版本(支持地图v2.0、v3.0和webGl)

baidu-map组件vue2版本移步(支持地图v2.0、v3.0和webGl)

vue2-baidu-map

基于 VUE 3.x 的百度地图组件

npm

语言

文档

https://yangjianfei.github.io/vue-baidu-map-3x/

开始

安装

npm i --save vue-baidu-map-3x

初始化

import { createApp } from 'vue';
import BaiduMap from 'vue-baidu-map-3x';
// import BaiduMap from 'vue2-baidu-map'; vue2使用

const app = createApp(App);
app.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: 'YOUR_APP_KEY',
  // v:'2.0',  // 默认使用3.0
  // type: 'WebGL' // ||API 默认API  (使用此模式 BMap=BMapGL)
});

使用

<template>
  <baidu-map class="map" :center="{lng: 118.454, lat: 32.955}" :zoom="5" @ready="ready" >
  </baidu-map>
</template>

<script setup>
const ready = ({BMap,map})=>{
  //  对地图进行自定义操作
};
</script>

<style>
/* 地图容器必须设置宽和高属性 */
.map {
  width: 400px;
  height: 300px;
}
</style>

离线地图

安装插件使用npm i vue-baidu-map-offline

全国地区编码坐标点数据集

import AreaCodePoint from 'vue-baidu-map-3x/dist/areaCodePoint.json';

// 示例:
{
  "110000": {
    "lat": 39.91101332265389,
    "lng": 116.413554023728
  }
  // 其他地区。。。
}

废弃

BmView 废弃了BmView组件

协议

MIT 许可证

版权所有 (c) 2016至今, YangJianFei [email protected]

关于我

扫描添加下方的微信(yjf163163)并回复加群,即可加入”前端男海群“。交流学习,及时获取代码最新动态。

如果对你有帮助送我一颗小星星(づ ̄3 ̄)づ╭❤~

任务清单

  • 按需加载
  • treeshaking
  • 箭头绘制,区域划分

更新日志

更新日志

vue-baidu-map-3x's People

Contributors

hx425072624 avatar yangjianfei 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

vue-baidu-map-3x's Issues

自动定位没有回调

<bm-geolocation anchor="BMAP_ANCHOR_ВОТТОМ_LEFT" : showAddressBar="true" :autoLocation='true" @ocationSuccess="locationSuccess" @LocationError="locationError">

这样写之后代码没有回掉

WebGL 使用 bm-polyline 后卡住不能拖拽,不能放大

getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:20 
        
       Uncaught TypeError: Cannot read properties of undefined (reading 'setMinMax')
    at bd.getBoundsIn (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:20:114358)
    at be._initPolyOverLayBasePoint (eval at run (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:122578), <anonymous>:1:183941)
    at be._syncOverlayFromMap (eval at run (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:122578), <anonymous>:1:184899)
    at be._bind (eval at run (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:122578), <anonymous>:1:183569)
    at be._init (eval at run (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:122578), <anonymous>:1:179878)
    at new be (eval at run (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:122578), <anonymous>:1:179824)
    at Array.eval (eval at run (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:122578), <anonymous>:1:183)
    at g0._asyncRegister (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:55351)
    at Array.<anonymous> (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:35238)
    at Function.run (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:122701)
getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:20 
        
       Uncaught TypeError: Cannot read properties of undefined (reading 'setMinMax')
    at bd.getBoundsIn (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:20:114358)
    at be._initPolyOverLayBasePoint (eval at run (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:122578), <anonymous>:1:183941)
    at Proxy.eval (eval at run (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:122578), <anonymous>:1:180337)
    at ev.BaseClass.fire.ev.BaseClass.dispatchEvent (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:2632)
    at Proxy.addOverlay (getscript?type=webgl&v=1.0&ak=IDdZzXKwmNj1aHDPKa0uGuy1dhL88ZiB&services=&t=20220830143644:5:37487)
    at Proxy.load (vue-baidu-map-3x.es.js:1423:11)
    at Proxy.ready (vue-baidu-map-3x.es.js:654:14)
    at E$1.emit (vue-baidu-map-3x.es.js:235:20)
    at Object.$emit (vue-baidu-map-3x.es.js:261:32)
    at g0.<anonymous> (vue-baidu-map-3x.es.js:510:19)
<template>
    <bm-marker :position="{lng: point.lng, lat: point.lat}" :dragging="false" lable="{{point.id}}"
        @click="marker_click(point.user_id)">
        <bm-polyline :show="show" :path="paths"></bm-polyline>
    </bm-marker>
</template>

<script setup lang="ts">
import { Point } from '../models/Point';
import { Location } from '../models/Location';
import { BmMarker, BmPolyline } from "vue-baidu-map-3x";
import { Ref } from 'vue';
import Storage from '../service/Storage'

const show = ref(false)
const paths: Ref<Location[]> = ref([])

const marker_click = async (user_id: string) => {
    if (!show.value) {
        paths.value = await Storage.user_all(user_id);
        console.log(paths.value);

        show.value = true;
    }
    else {
        show.value = false;
    }
}

defineProps<{ point: Point }>()
</script>

vue__WEBPACK_IMPORTED_MODULE_34__.createElementVNode) is not a function

app.js:2680 Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_34__.createElementVNode) is not a function
    at eval (vue-baidu-map-3x.es.js?de10:2973:1)
    at ./node_modules/vue-baidu-map-3x/dist/vue-baidu-map-3x.es.js (chunk-vendors.js:1352:1)
    at __webpack_require__ (app.js:2677:33)
    at fn (app.js:2945:21)
    at eval (main.js:19:75)
    at ./src/main.js (app.js:1855:1)
    at __webpack_require__ (app.js:2677:33)
    at app.js:3870:109
    at __webpack_require__.O (app.js:2726:23)
    at app.js:3871:53

3D地图的数据双向绑定会死循环卡死

我想用这个组件,搭配MapV Three进行三维地图场景的开发
MapV-three的文档
然后我在main.js中将type设置为WebGL

app.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: 'xxx',
  // v:'2.0',  // 默认使用3.0
  type: 'WebGL', // ||API 默认API  (使用此模式 BMap=BMapGL)
})

之后在组件中使用示例的双向数据绑定,会出现循环很多次,导致地图很慢,操作也会有些卡住失效,不像默认的type那样流畅,我debug后查看发现好像是进入循环了,好像是requestAnimationFrame的时候也触发了事件,具体因为能力有限,没有找到解决方案

<template>
  <input v-model.number="center.lng" />
  <input v-model.number="center.lat" />
  <input v-model.number="zoom" />
  <baidu-map
    class="map"
    :center="center"
    :zoom="zoom"
    @ready="ready"
    :scroll-wheel-zoom="true"
    @zoomend="syncCenterAndZoom"
    @dragend="syncCenterAndZoom"
  ></baidu-map>
</template>

<script setup>
//这里没有引入ref,nextTick是因为用了vite插件自动导入
const center = ref({
  lng: 114.298572,
  lat: 30.584355,
})

const zoom = ref(15)
const ready = ({ BMap, map }) => {
  //  对地图进行自定义操作
}
const syncCenterAndZoom = (e) => {
  //   console.log(e)
  const { lng, lat } = e.target.getCenter()
  zoom.value = e.target.getZoom()
  //   console.log(lng, lat, zoom.value)
  nextTick(() => {
    center.value.lng = lng
    center.value.lat = lat
  })
}
</script>

用不了百度路书组件么

Failed to resolve component: bml-lushu
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.

BmGeolocation 组件失效

后台报错:
VM503:1 Uncaught TypeError: Cannot read properties of null (reading 'address')
at Geolocation.eval (eval at z_ (getscript?v=3.0&ak=Yp57V71dkOPiXjiN8VdcFRsVELzlVNKK&services=&t=20220816154130:1:81032), :1:778)
at c (eval at z_ (getscript?v=3.0&ak=Yp57V71dkOPiXjiN8VdcFRsVELzlVNKK&services=&t=20220816154130:1:81032), :1:1789)
at eval (eval at z_ (getscript?v=3.0&ak=Yp57V71dkOPiXjiN8VdcFRsVELzlVNKK&services=&t=20220816154130:1:81032), :1:2566)

地图Maker使用v-for加入InfoWindow时会报错

报错截图

image

只会出现一个点,且点击时报错
image

去掉infoWindow不报错,Maker使用v-for正常

使用版本 "vue-baidu-map-3x": "^1.0.21",

html

<baidu-map class="map" :center="{lng: location.lng, lat: location.lat}"
		         :zoom="15" style="height: 800px;">
	<div v-for="item in locationInfo">
		<bm-marker :position="{lng: item.location.lng, lat: item.location.lat}"
				         :dragging="false" @click="item.open = true">
			<bm-info-window :show="item.open" @close="item.open=false" @open="item.open = true">
				{{ item }}
			</bm-info-window>
		</bm-marker>
	</div>
</baidu-map>

数据结构

[
    {
        "name": "十梅庵风景区",
        "location": {
            "lat": 36.204773,
            "lng": 120.426173
        },
        "address": "山东省青岛市李沧区老虎山北麓山坡上",
        "province": "山东省",
        "city": "青岛市",
        "area": "李沧区",
        "street_id": "1020060f20f8aba71894c635",
        "telephone": null,
        "detail": 1,
        "uid": "1020060f20f8aba71894c635",
        "open": false
    },
    {
        "name": "牛毛山公园",
        "location": {
            "lat": 36.1875,
            "lng": 120.404987
        },
        "address": "安国路与文安路交叉口北150米",
        "province": "山东省",
        "city": "青岛市",
        "area": "李沧区",
        "street_id": "341c35decb82b3bfe6073835",
        "telephone": null,
        "detail": 1,
        "uid": "341c35decb82b3bfe6073835",
        "open": false
    }
]

类型提示问题

这个地方可不可以加上types
image

这样就不报错了:

image

否则会这样:
image

bm-info-window出现抖动

<bm-info-window :closeOnClick="false" :show="infoWindow.show" :position="infoWindow.info"
@close="infoWindowClose(infoWindow)" @OPEN="infoWindowOpen()" :width="400" :height="400">




车牌:{{infoWindow.name}}


车辆状态:
离线
在线
休眠


运输单位:




最后上传时间:{{parseTime(infoWindow.lasttime) }}


位置:{{infoWindow.address}}




没有司机信息




机主:{{infoWindow.owner}}


终端类型:
主设备
副设备


电话号码:{{infoWindow.phoneNumber}}


设备图片:






<el-button class="elbutton" :icon="View" @click="dianji(infoWindow)">预览

        </bm-info-window>``

tabs切换会出现页面抖动

getPointByAddress希望能添加city参数

这个函数可以批量进行坐标转换,但是地址前面如果没有加上城市,会找到别的城市去
看了下baidu的api有city参数,希望能在这个函数里面也添加上城市

2k屏行政区划范围不渲染

我用了两个屏,一个是笔记本自带的1080的可以展示区划, 但是当把浏览器移动到外接的2k屏,再刷新就没了.

多个海量点组件触发多次事件

我想在地图上添加不同颜色的海量点,于是就使用多个海量点组件, 我发现每次悬浮到点上都会触发三次方法,正常来说应该只是触发一次对应的方法

        <bm-point-collection :points="attrs.data.fenshao" shape="BMAP_POINT_SHAPE_CIRCLE" color="blue"
            size="BMAP_POINT_SIZE_SMALL" @click="(e, r) => { click_points(e, r, 'fenshao') }"
            @mouseover="(e, r) => { over_points(e, r, 'fenshao') }"
            @mouseout="(e, r) => { out_points(e, r, 'fenshao') }">
        </bm-point-collection>
        <bm-point-collection :points="attrs.data.jianzhu" shape="BMAP_POINT_SHAPE_CIRCLE" color="yellow"
            size="BMAP_POINT_SIZE_SMALL" @click="(e, r) => { click_points(e, r, 'jianzhu') }"
            @mouseover="(e, r) => { over_points(e, r, 'jianzhu') }"
            @mouseout="(e, r) => { out_points(e, r, 'jianzhu') }">
        </bm-point-collection>
        <bm-point-collection :points="attrs.data.tianmai" shape="BMAP_POINT_SHAPE_CIRCLE" color="pink"
            size="BMAP_POINT_SIZE_SMALL" @click="(e, r) => { click_points(e, r, 'jianzhu') }"
            @mouseover="(e, r) => { over_points(e, r, 'jianzhu') }"
            @mouseout="(e, r) => { out_points(e, r, 'jianzhu') }">
        </bm-point-collection>

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.