dafrok / vue-baidu-map Goto Github PK
View Code? Open in Web Editor NEWBaidu Map components for Vue 2.x
Home Page: https://dafrok.github.io/vue-baidu-map/
License: MIT License
Baidu Map components for Vue 2.x
Home Page: https://dafrok.github.io/vue-baidu-map/
License: MIT License
Hi,大神如题有计划没?
当我初始化一个display:none的地图时,当我点击显示的时候,可视区域中心点并没有在指定的坐标位置上。通过:center初始化的。并且当我通过@ready方法拿到BMap的核心类和地图实例,也不能通过这个来调用panTo(new BMap.point())方法来移动中心点。
请问下应该怎么做呢?
猜测:marker组件已经出现在地图上,但是没有默认的红色标记点。首次使用,也许有什么遗漏造成的。
html代码:
<template>
<baidu-map class="bm-view" :center="{lng: 116.404, lat: 39.915}" ak="3uqSBTvQbGFsMH7nn10I8aoOWkWDRV7R" @click="click">
<bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"/>
<bm-marker ref="mark" :position="{lng: 116.404, lat: 39.915}">
</bm-marker>
<bm-circle :center="circlePath.center" :radius="circlePath.radius" stroke-color="blue" :stroke-opacity="0.5" :stroke-weight="2" :editing="true"></bm-circle>
</baidu-map>
</template>
js代码:
export default {
data() {
return {
position: {},
circlePath: {
center: {
lng: 116.404,
lat: 39.915
},
radius: 500
}
}
},
methods: {
click(e) {
this.position = {
lng: e.point.lng,
lat: e.point.lat
}
}
}
}
截图:
Uncaught (in promise) TypeError: Cannot read property 'querySelectorAll' of undefined
用了这个插件,PC端可以展示,但是移动端 微信浏览器内无法显示地图
百度地图原生api里面有个 Geocoder()方法,应该怎么复用啊,有什么组件吗,就是我想实现一个功能,点击地图上的地点,然后可以获取到那个位置上的信息。
bm-local-search组件的searchcomplete方法,文档参数是这样的,请问下怎么用啊。
可以给一个demo么?
在定位控件中加入 :autoLocation = "true", 但是第一次打开地图的时候无法获取定位。
自行用geolocation 来获取定位,更新center后地图却不移动,一定要主动点击定位控件才会聚焦到定位地点。
<template>
<baidu-map class="map-container" id="allmap" ref="map">
<map-view
class="map"
:scroll-wheel-zoom="true"
:center="center"
:zoom="zoom"
@moving="syncCenter"
@moveend="syncCenter"
@zoomend="syncZoom" >
</map-view>
</baidu-map>
</template>
//成功获取坐标后调用
findNearby(longitude, latitude) {
let map = new BMap.Map("allmap")
//获取坐标后zoom到一定比例
map.centerAndZoom(new BMap.Point(longitude, latitude), this.zoom);
//获取搜索实例
let local = new BMap.LocalSearch(map, {
renderOptions: {
map: map,
autoViewport: true
}
});
//搜索附近
local.searchNearby(this.$route.params.search_name, new BMap.Point(longitude, latitude));
}
我又来了 :p
有个问题想请教一下 我通过this.$refs.map 获取实例后 不知道如何进行LocalSearch
于是我就new BMap了 但是新创建对象标签里面的syncCenter都失效了 这该如何解决
怎么设置信息窗口,marker 里面只有一个 label 的例子。marker 有 infowindowclose infowindowopen 这两个事件,怎么能触发?能随手写个点和弹框的例子吗?麻烦了!!
<el-form-item label="地图">
<baidu-map class="map" :center="{lng: lng, lat:lat}" :zoom="16" @ready="loadMap">
<bm-view style="position: absolute; top: 0px; bottom: 0px; left: 0px; right: 0px"></bm-view>
<bm-marker :point="{lng:lng, lat:lat}" :dragging="true" animation="BMAP_ANIMATION_BOUNCE" :label="{content: data.name, opts: {offset: {width: 20, height: -10}}}" @dragend="dragend"></bm-marker>
<bm-geolocation anchor="BMAP_ANCHOR_BOTTOM_RIGHT" :showAddressBar="true" :autoLocation="true" />
<bm-navigation anchor="BMAP_ANCHOR_TOP_LEFT" />
</baidu-map>
</el-form-item>
methods: {
searchMap: function() {
},
loadMap: function() {
var map = this.data.location.split(',');
this.lat = map[0];
this.lng = map[1];
},
dragend: function(type, target, pixel, point) {
console.log(type+"----"+target+"----"+pixel+"----"+point);
}
},
© 2017 Baidu - GS(2016)1069号 - Data © 长地万方 & OpenStreetMap & HERE
& OpenStreetMap & HERE
<bm-local-search :keyword="search" :location="center" :nearby="nearby" @searchcomplete="searchcomplete"></bm-local-search>
center是深圳北的{lat,lng}
nearby:{center:center, radius:200}
searchcomplete 这个拿到的数据是龙岗,罗湖等的数据了。
组件内的load的_location值是深圳北的位置。
尝试过用以下代码测试但不能成功实现多点标注。
我爱北京*** <script> export default { mounted() { }, data () { return { show: false, markerPoint1: {lng: 116.404, lat: 39.915}, markerPoint2: {lng: 116.804, lat: 39.415}, } }, methods: { infoWindowClose () { this.show = false }, infoWindowOpen () { this.show = true } } } </script>安装此插件时,警告:npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fseve
[email protected],使用时也总说BMap未定义,是因为此组件不支持window系统吗
您好,我想咨询一下你项目里面的index.js的内容从何而来。我想用腾讯地图做一个vue组件。学习了你的项目,想去实践一下。但是不知道这个index.js的内容从何而来。
想实现这样一个需求
在BMap加载之后 获取用户位置 用户授权后 根据坐标搜周边超市
本想用MapControlGeolocation在加载后自动获取 发现并不会用这个组件 似乎不能通过 enableAutoLocation来自动定位...不知道如何在他自动定位后把相应的值赋给用户的坐标值
后来我用navigator.geolocation.getCurrentPosition来进行获取位置 但是再IOS10上无法正常显示...
想问如何实现和用好控件
[Vue warn]: Error in callback for watcher "icon":
(found in )
TypeError: Cannot read property 'setIcon' of undefined
at VueComponent.handler (eval at (app.js:3479), :1:30612)
at Watcher.run (eval at (app.js:809), :2552:19)
at flushSchedulerQueue (eval at (app.js:809), :2330:13)
at Array.eval (eval at (app.js:809), :506:20)
at nextTickHandler (eval at (app.js:809), :455:16)
测试代码:
<template>
<baidu-map v-bind:style="{
width: '100%',
height: mapHeight + 'px'
}"
:center="{lng: 116.404, lat: 39.915}"
:zoom="15"
:scroll-wheel-zoom="true"
@ready="ready"
>
</baidu-map>
</template>
<script>
export default{
data() {
return{
mapHeight: 400
}
},
mounted() {
this.mapHeight = 500;
},
methods:{
ready(obj){
const { BMap, map } = obj;
map.addTileLayer(new BMap.TrafficLayer);
}
}
}
</script>
文档地址:https://dafrok.github.io/vue-baidu-map/#/overlay/circle
感觉组件参数传的有错误,<map-overlay-circle :center的值应该是个Point对像,例子中传的是个数组,但即便是改成对象也报错,实在没办法了,所以只能求助大神了~
BMap类我在ready事件中拿到了,但map实例却一直拿不到,试了很多方法还是不行,请问该如何拿到?谢谢!
需要添加自定义覆盖物的话,现在支持吗?
marker icon 如何配置,应该传入一个 BMap.Icon, 只传配置参数进去,无法实现icon。
<template>
<baidu-map class="bm-view" id="allmap" :center="center" :zoom="zoom" @ready="mapHandler">
<bm-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_HYBRID_MAP']" anchor="BMAP_ANCHOR_TOP_LEFT"/>
</baidu-map>
</template>
var map = new BMap.Map("allmap");
var startIcon = new BMap.Icon("static/marker_starting.png", new BMap.Size(50, 50), {
imageSize: new BMap.Size(50,50),
imageOffset: new BMap.Size(0, 0)
});
var startPoint = new BMap.Marker(new BMap.Point(113.94199, 22.529346),{icon:startIcon});
map.addOverlay(startPoint);
这样调用就把组件化定义的方法覆盖了,该如何调用百度自带API呢?
如题。现在处于开发的什么阶段?未来会有扩充或者较大的变化吗?
对比了一圈,发现你的vue版本用的2.1.8,我的是2.2.2.webpack你的版本是1.X,我的版本是2.X。不知道会不会是版本引起的返回参数undefined
代码
<template>
<baidu-map v-bind:style="{
width: '100%',
height: mapHeight + 'px'
}"
:center="{lng: 116.404, lat: 39.915}"
:zoom="15"
:scroll-wheel-zoom="true"
@ready="ready">
<bm-scale anchor="BMAP_ANCHOR_TOP_RIGHT" />
<bm-navigation anchor="BMAP_ANCHOR_TOP_LEFT" />
<bm-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_HYBRID_MAP']" anchor="BMAP_ANCHOR_TOP_RIGHT" />
</baidu-map>
</template>
报错如下
TypeError: Cannot read property 'MapTypeControl' of undefined
at VueComponent.addControl (eval at <anonymous> (app.js:981), <anonymous>:1:9263)
at VueComponent.boundFn [as addControl] (eval at <anonymous> (app.js:723), <anonymous>:126:12)
at VueComponent.eval (eval at <anonymous> (app.js:981), <anonymous>:1:9590)
at Array.eval (eval at <anonymous> (app.js:723), <anonymous>:464:20)
at nextTickHandler (eval at <anonymous> (app.js:723), <anonymous>:413:16)
logError @ vue.esm.js?b5dc:426
我又来 我现在想要在检索后清除所有的覆盖物 然后添加检索第一条的数据为marker 然后可以拖动改变位置 没有找到clearOverlays清除覆盖物的方法
如题!!麻烦开发了!
`ERROR in ENOENT: no such file or directory, scandir 'C:\Users\Administrator\Documents\GitHub\vue-baidu-map\node_modules\.4.5.0@node-sass\vendor'
@ ./~/.2.0.3@vue-style-loader!./~/.0.26.4@css-loader!./~/.10.3.0@vue-loader/lib/style-rewriter.js?id=data-v-d29e0346!./~/.4.1.1@sass-loader!./~/.10.3.0@vue-loader/lib/selector.js?type=styles&index=0!./docs/src/components/App.vue 4:14-295 13:3-17:5 14:22-303
ERROR in ENOENT: no such file or directory, scandir 'C:\Users\Administrator\Documents\GitHub\vue-baidu-map\node_modules\.4.5.0@node-sass\vendor'
@ ./~/.2.0.3@vue-style-loader!./~/.0.26.4@css-loader!./~/.10.3.0@vue-loader/lib/style-rewriter.js?id=data-v-0bf43138&scoped=true!./~/.4.1.1@sass-loader!./~/.10.3.0@vue-loader/lib/selector.js?type=styles&index=0!./docs/src/components/DocPreview.vue 4:14-314 13:3-17:5 14:22-322
ERROR in ENOENT: no such file or directory, scandir 'C:\Users\Administrator\Documents\GitHub\vue-baidu-map\node_modules\.4.5.0@node-sass\vendor'
@ ./~/.2.0.3@vue-style-loader!./~/.0.26.4@css-loader!./~/.10.3.0@vue-loader/lib/style-rewriter.js?id=data-v-66e4f9e7&scoped=true!./~/.4.1.1@sass-loader!./~/.10.3.0@vue-loader/lib/selector.js?type=styles&index=0!./docs/src/components/RootFrame.vue 4:14-313 13:3-17:5 14:22-321
ERROR in ENOENT: no such file or directory, scandir 'C:\Users\Administrator\Documents\GitHub\vue-baidu-map\node_modules\.4.5.0@node-sass\vendor'
@ ./~/.2.0.3@vue-style-loader!./~/.0.26.4@css-loader!./~/.10.3.0@vue-loader/lib/style-rewriter.js?id=data-v-0342d071!./~/.4.1.1@sass-loader!./~/.10.3.0@vue-loader/lib/selector.js?type=styles&index=0!./~/.0.6.2@vue-markdown-loader/_cache/bm-local-search-22.vue 4:14-246 13:3-17:5 14:22-254
Child html-webpack-plugin for "index.html":`
请问这些错误如何处理?
下面代码如果放开注释部分浏览器会报错,如果v-for部分的pointList不变化,或者不添加bm-navigation都没问题,两者共存就报错了。
<template lang="html">
<baidu-map :center="BDMap.center" @ready="handler" :zoom="BDMap.zoom" class="bm-view">
<bm-marker
v-for="point in pointList"
:position="{lng: point.lng, lat: point.lat}">
</bm-marker>
<!-- 以下部分放开会报错 -->
<!-- <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT" />
<bm-geolocation anchor="BMAP_ANCHOR_BOTTOM_RIGHT" :showAddressBar="true" :autoLocation="true"/> -->
</baidu-map>
</template>
<script type="text/javascript">
export default {
data() {
return {
BDMap: {
center: {
lng: 116.404,
lat: 39.955
},
zoom: 12
},
pointList: [{
lng: 116.414,
lat: 39.915,
}, {
lng: 116.424,
lat: 39.915,
}]
}
},
methods: {
handler() {
this.pointList.push({
id: 1,
lng: 116.524,
lat: 39.955
})
}
}
}
</script>
<style scoped>
.bm-view {
width: 100%;
height: 300px;
}
</style>
chrome报错如下
vue.esm.js?65d7:467 DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
at Object.insertBefore (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:4407:14)
at insert (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:4713:17)
at createElm (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:4643:7)
at VueComponent.patch [as __patch__] (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:5054:7)
at VueComponent.Vue._update (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:2034:19)
at VueComponent.updateComponent (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:2157:10)
at Watcher.get (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:2468:25)
at new Watcher (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:2451:12)
at mountComponent (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:2161:17)
at init (eval at <anonymous> (http://localhost:2001/app.js:810:1), <anonymous>:2930:13)
logError @ vue.esm.js?65d7:467
首先非常感谢您的开源库,非常感谢,
我在设置 center 属性时遇到点问题:
:center="'杭州市'"
这样是正常的,地区会切换到杭州市。
:center="'New York'"
这样地图是一片空白,打开浏览器控制台提示:
VM48647:1 Uncaught TypeError: Cannot read property 'style' of undefined
at Gg.Ig.VO (eval at yZ xxxx)
center 属性是不能解析国外的地址吗?
我想实现的效果是,有个输入框,输入美国的一些城市或者街区,地区能相应的切换,但是设置 center 属性遇到了这个问题,不知道怎么回事。
开发环境:
"vue-baidu-map": "^0.10.4"
"vue": "^2.2.6",
麻烦您了,再次感谢。
读源码时,不知道作者如何在vue文件里注册全局的_initBaiduMap,以便百度sdk的callback访问,作者可否指点一下。
getMapScript () {
if (!global.BMap) {
const ak = this._BMap().ak
global.BMap = {}
global.BMap._preloader = new Promise((resolve, reject) => {
global._initBaiduMap = function () {
resolve(global.BMap)
global.document.body.removeChild($script)
global.BMap._preloader = null
global._initBaiduMap = null
}
const $script = document.createElement('script')
global.document.body.appendChild($script)
$script.src = `//api.map.baidu.com/api?v=2.0&ak=${ak}&callback=_initBaiduMap`;
})
return global.BMap._preloader
} else if (!global.BMap._preloader) {
return Promise.resolve(global.BMap)
} else {
return global.BMap._preloader
}
}
另外,global.BMap当中global对象,是如何在使用?
谢了!
这个库,有这集成这个吗?
萌新的实习生又来问你问题了(
前后台我都写,有这样一个需求想和您讨论一下
定位前提下,搜索周边保险公司(很多数据都是在本地,没有录入百度地图上),后台返回经纬度和公司信息,能通过geohash去查询附近地址吗,再通过BmMarker去渲染。
标签:
<bm-marker :position="{lng: bmap.longitude, lat: bmap.latitude}" :dragging="true" animation="BMAP_ANIMATION_BOUNCE" :icon="{url: 'http://xxx.xxx.com/images/[email protected]', size: {width: 56, height: 56}}"> </bm-marker>
错误提示:
[Vue warn]: Error in callback for watcher "icon": (found in <BmMarker>)
app.js:4152 TypeError: Cannot read property 'setIcon' of undefined at VueComponent.handler (app.js:12041) at Watcher.run (app.js:5254) at flushSchedulerQueue (app.js:5034) at Array.<anonymous> (app.js:3210) at nextTickHandler (app.js:3159) at <anonymous>
就是说不用webpack,直接在页面中引用script src 这种方式使用这个地图组件呢???
我把index.js加进去,然后
Vue.use(VueBaiduMap , {
ak:"xxx"
});
这样,不起作用....
如果可以,应该怎么做呢?
使用你们的组件,地图用滚轮缩放的时候的体验 比不上 不用组件流畅啊
1)没有缓存的情况下,缩放时少量情况下需要等待1S以上
2)拖动的时候,没有惯性效果
地图不能用鼠标滚轮缩放??
不能用鼠标缩放
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.