6

百度地图插件

安装

CDN全局安装

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

插件的引入

Vue.use(VueBaiduMap.default, {
    ak: 'YOUR_APP_KEY',
})

ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apico... */

地图视图

BmView 是用于渲染百度地图实例可视化区域的容器

使用 Bmview 渲染一个地图实例:

<template id="baidu">   
    <baidu-map class="map">
        <bm-view style="position: absolute; top: 60px; bottom: 20px; left: 20px; right: 20px"></bm-view>
    </baidu-map>
</template>

给地图添加一个缩放控件

<bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>

把控件放到我们渲染的地图实例里就可以了

效果如下:

![image](img/baidumap.gif)

完整代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>baidumap</title>
    <script src="https://unpkg.com/vue"></script>
    <script src="https://unpkg.com/vue-baidu-map"></script>
    <style>
        #map{
            width: 1000px;
            height: 500px;
        }
    </style>
</head>
<body>
    <div id="map">
        <baidu></baidu>
    </div>
    <template id="baidu">
            
        <baidu-map class="map">
            <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
            <bm-view style="position: absolute; top: 60px; bottom: 20px; left: 20px; right: 20px"></bm-view>
        </baidu-map>
    
    </template>
    <script>
        Vue.use(VueBaiduMap.default, {
            ak: 'YOUR_APP_KEY',
        })
        Vue.component("baidu",{
            template:'#baidu'
        })
        new Vue({
            el:'#map'
        })
    </script>
</body>
</html>

PureView
440 声望28 粉丝