百度地图的使用(定点搜索、放大缩小,比例尺,地图定点)

安装

npm install vue-baidu-map --save

CDN

<script src="https://unpkg.com/vue-baidu-map"></script> 

使用

全局注册

全局注册将一次性引入百度地图组件库的所有组件。

import Vue from 'vue'
import BaiduMap from 'vue-baidu-map'

Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: 'YOUR_APP_KEY'
})
<template>
  <baidu-map class="bm-view">
  </baidu-map>
</template>

<style>
.bm-view {
  width: 100%;
  height: 300px;
}
</style>

局部注册

如果有按需引入组件的需要,可以选择局部注册百度地图组件,这将减少工程打包后的容量尺寸。局部注册的 BaiduMap 组件必须声明 ak 属性。 所有的独立组件均存放在 vue-baidu-map/components 文件夹下,按需引用即可。 由于未编译的 ES 模块不能在大多数浏览器中直接运行,如果引入组件时发生运行时错误,请检查 webpack 的 loader 配置,确认 include 和 exclude 选项命中了组件库。

<template>
  <baidu-map class="bm-view" ak="YOUR_APP_KEY">
  </baidu-map>
</template>

<script>
import BaiduMap from 'vue-baidu-map/components/map/Map.vue'
export default {
  components: {
    BaiduMap
  }
}
</script>

<style>
.bm-view {
  width: 100%;
  height: 300px;
}
</style>

CDN 全局注册

<script>
Vue.use(VueBaiduMap.default, {
  ak: 'YOUR_APP_KEY'
})
</script>

常见问题

  • BaiduMap 组件
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 安装 ECharts 和 Vue-ECharts ```bash npm install echarts vue-echarts ``` 2. 在 Vue 组件中使用 ECharts ```vue <template> <div ref="map" style="height: 500px"></div> </template> <script> import ECharts from 'vue-echarts/components/ECharts' import 'echarts/map/js/china' export default { components: { 'v-chart': ECharts }, mounted() { const chart = this.$refs.map.echarts chart.setOption({ tooltip: { trigger: 'item' }, visualMap: { min: 0, max: 2500, left: 'left', top: 'bottom', text: ['High', 'Low'], calculable: true }, series: [ { name: '地图', type: 'map', mapType: 'china', roam: false, itemStyle: { normal: { label: { show: true } }, emphasis: { label: { show: true } } }, data: [ { name: '北京', value: 500 }, { name: '上海', value: 700 }, { name: '广州', value: 1000 }, { name: '重庆', value: 1500 }, { name: '成都', value: 2500 } ] } ] }) } } </script> ``` 3. 在地图上添加定点 ```vue <template> <div ref="map" style="height: 500px"></div> </template> <script> import ECharts from 'vue-echarts/components/ECharts' import 'echarts/map/js/china' export default { components: { 'v-chart': ECharts }, mounted() { const chart = this.$refs.map.echarts chart.setOption({ tooltip: { trigger: 'item' }, visualMap: { min: 0, max: 2500, left: 'left', top: 'bottom', text: ['High', 'Low'], calculable: true }, series: [ { name: '地图', type: 'map', mapType: 'china', roam: false, itemStyle: { normal: { label: { show: true } }, emphasis: { label: { show: true } } }, data: [ { name: '北京', value: 500 }, { name: '上海', value: 700 }, { name: '广州', value: 1000 }, { name: '重庆', value: 1500 }, { name: '成都', value: 2500 } ] }, { name: '定点', type: 'scatter', coordinateSystem: 'geo', data: [ { name: '北京', value: [116.46, 39.92] }, { name: '上海', value: [121.48, 31.22] }, { name: '广州', value: [113.23, 23.16] }, { name: '重庆', value: [106.54, 29.59] }, { name: '成都', value: [104.06, 30.67] } ], symbolSize: 10, label: { normal: { formatter: '{b}', position: 'right', show: true } } } ] }) } } </script> ``` 以上代码中,我们通过添加一个新的 `series` 来实现在地图上添加定点。`type` 属性设置为 `scatter`,表示散点图。`coordinateSystem` 属性设置为 `geo`,表示使用地理坐标系。`data` 属性设置为一个数组,每个元素表示一个定点,包括名字、经纬度等信息。`symbolSize` 属性表示定点的大小,`label` 属性表示在定点旁边显示名字。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值