引入百度地图api不显示地图

来源:8-1 (上)销售大盘地图组件开发

慕神4213171

2024-09-16

输入正文

https://img1.sycdn.imooc.com/szimg/66ce9e5c091664ed28480950.jpg

https://img1.sycdn.imooc.com/szimg/66ce9e5d09076d2925920950.jpg

index.html

<!DOCTYPE html>

<html lang="">

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width,initial-scale=1.0">

<link rel="icon" href="<%= BASE_URL %>favicon.ico">

<title><%= htmlWebpackPlugin.options.title %></title>

</head>

<body>

<noscript>

<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>

</noscript>

<div id="app"></div>

<!-- built files will be auto injected -->

<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ"></script>

</body>

</html>


BMap.vue

<template>

<v-chart :options="options" style="width: 500px; height: 500px;"></v-chart>

</template>


<script>

import 'echarts/extension/bmap/bmap'


export default {

data() {

return {

options: {}

}

},

mounted() {

/* eslint-disable */

this.options = {

bmap: {

key: 'G1LFyjrNGIkns5OfpZnrCGAKxpycPLwb',

center: [104.114129, 37.550339],

zoom: 5,

roam: false,

mapStyle: {

styleJson: [{

'featureType': 'water',

'elementType': 'all',

'stylers': {

'color': '#d1d1d1'

}

}, {

'featureType': 'land',

'elementType': 'all',

'stylers': {

'color': '#f3f3f3'

}

}, {

'featureType': 'railway',

'elementType': 'all',

'stylers': {

'visibility': 'off'

}

}, {

'featureType': 'highway',

'elementType': 'all',

'stylers': {

'color': '#fdfdfd'

}

}, {

'featureType': 'highway',

'elementType': 'labels',

'stylers': {

'visibility': 'off'

}

}, {

'featureType': 'arterial',

'elementType': 'geometry',

'stylers': {

'color': '#fefefe'

}

}, {

'featureType': 'arterial',

'elementType': 'geometry.fill',

'stylers': {

'color': '#fefefe'

}

}, {

'featureType': 'poi',

'elementType': 'all',

'stylers': {

'visibility': 'off'

}

}, {

'featureType': 'green',

'elementType': 'all',

'stylers': {

'visibility': 'off'

}

}, {

'featureType': 'subway',

'elementType': 'all',

'stylers': {

'visibility': 'off'

}

}, {

'featureType': 'manmade',

'elementType': 'all',

'stylers': {

'color': '#d1d1d1'

}

}, {

'featureType': 'local',

'elementType': 'all',

'stylers': {

'color': '#d1d1d1'

}

}, {

'featureType': 'arterial',

'elementType': 'labels',

'stylers': {

'visibility': 'off'

}

}, {

'featureType': 'boundary',

'elementType': 'all',

'stylers': {

'color': '#fefefe'

}

}, {

'featureType': 'building',

'elementType': 'all',

'stylers': {

'color': '#d1d1d1'

}

}, {

'featureType': 'label',

'elementType': 'labels.text.fill',

'stylers': {

'color': '#999999'

}

}]

}

}

}

}

}

</script>


<style lang="scss">

</style>



写回答

2回答

扬_灵

2024-09-21

同学你好,地图没有显示是因为代码配置出现问题, 是option,你可以修改看下
https://img1.sycdn.imooc.com/szimg/66eedd0309b0834623781824.jpghttps://img1.sycdn.imooc.com/szimg/66eedd1209d173ff18301100.jpg

0
1
慕神4213171
终于好了!感谢!卡在这里好多天了,终于解决!
2024-09-23
共1条回复

扬_灵

2024-09-17

同学你好,使用上述代码是可以正常显示的,麻烦把完整的项目代码上传到github或是码云这些代码托管平台,把地址发我一下我在本地帮你测试定位一下问题。
https://img1.sycdn.imooc.com/szimg/66e97665097e001531861434.jpg

0
1
慕神4213171
你好,这是我的项目地址:https://gitee.com/missing_nancy_tan/datav-report.git
2024-09-21
共1条回复

数据可视化入门到精通-打造前端差异化竞争力

同级别前端,掌握数据可视化薪资更高

1520 学习 · 1043 问题

查看课程