vue加载百度离线地图V3.0瓦片数据,瓦片数据做nginx代理

news/2025/3/13 17:50:00/

1:资源准备

1.1百度离线文件

链接: https://pan.baidu.com/s/1-3tZ6eZvp2vdCsWLi-9MAg
提取码: vjxa

1.2瓦片数据下载器

链接: https://pan.baidu.com/s/1MZjWobc1DQGX_ApYBNtROg
提取码: pxd1

2:构建vue的空项目

此步直接略过,不会的自行解决

3:在vue2.x中使用

3.1 把下载的1.1中的百度离线文件解压到 public/static下,static文件夹自己新建一个

解压到public/static下

3.2 在index.html中引入mao_load.js 文件

记住文件路径不要用相对路径 会报 Uncaught SyntaxError: Unexpected token < 错误
注意写法

<script src="<%= BASE_URL %>static/map_load.js"></script>
3.3 完了之后就新建文件,开始在页面上使用,这里我直接在HelloWorld.vue组件中使用的,做的demo
<template><div class="hello"><h1>{{ msg }}</h1><p>For a guide and recipes on how to configure / customize this project,<br />check out the<ahref="https://cli.vuejs.org"target="_blank"rel="noopener">vue-cli documentation</a>.</p><div class="wrap"><div id="container"></div><div id="container2"></div></div></div>
</template><script>
export default {name: "HelloWorld",props: {msg: String},mounted() {this.builmap();},methods: {builmap() {let map = new window.BMap.Map("container");let point = new window.BMap.Point(114.28398, 30.601327);map.centerAndZoom(point, 12);map.enableScrollWheelZoom(true);map.addEventListener("click", function(e) {console.log(e.point.lng + "," + e.point.lat);});let map2 = new window.BMap.Map("container2");let point2 = new window.BMap.Point(114.28398, 30.601327);map2.centerAndZoom(point2, 12);map2.enableScrollWheelZoom(true);map2.addEventListener("click", function(e) {console.log(e.point.lng + "," + e.point.lat);});}}
};
</script><!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>ul {list-style-type: none;padding: 0;
}
li {display: inline-block;margin: 0 10px;
}
a {color: #42b983;
}
.wrap {display: flex;justify-content: space-around;
}
#container {width: 500px;height: 500px;border: 1px solid red;
}
#container2 {width: 500px;height: 500px;border: 3px solid pink;
}
</style>
直接把代码贴出来了

4:瓦片做nginx代理

4.1 先下载nginx,博主直接放到桌面解压出来的,进入conf文件夹,直接用vscode打开nginx.conf文件,修改如下:

nginx配置
别的不用做修改,第36行是监听你的端口号,根据自己的实际情况做对应的修改


#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   E:/IMChenng/download/bmap_offline_demo/tiles; #瓦片地址}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}
4.2 打开 bmap_offline_api_v3.0_min.js 文件 ,定位到 6518 行,根据自己实际情况,做如下的修改:

在这里插入图片描述

4.3 启动nginx,启动vue这个项目,就会发现,离线地图加载出来了,

在这里插入图片描述
控制台也不会报错,只要你下载了对应的瓦片数据。

4.3 贴上 github项目地址 打开即可
4.4 有什么不懂的,就留言评论或者私信吧。我也不是很懂。大家互相交流~

http://www.ppmy.cn/news/412841.html

相关文章

dB、dBm、dBw、dBμV、dBmV、dBV、dBv等单位介绍

前言 我们常常遇到有关信号电平的单位(dBμV、dBmV、dBV、dBm、dBW)&#xff0c;很多人对这些单位模糊不清。我刚刚接触时也懵圈了半天&#xff0c;也是查了一些资料才搞明白。下面我们就它们之间的关系做一下简单论述。 单位dB 我们先来认识dB:dB是国标符号,是英文decibel或…

MapBox Android sdk v9.6.2加载矢量切片,栅格瓦片

MapBox Android sdk v9.6.2加载矢量切片&#xff0c;栅格瓦片 注&#xff1a;看文章之前先要了解source和layer的概念 1.栅格瓦片 栅格的不在多写看代码&#xff0c;比较简单,style的api里边有添加在某个图层之上和之下等 val tileSet TileSet("hubei","http…

百度地图API V2.0 离线版本

百度地图API V2.0 离线版本&#xff0c;支持IE。 发布于 2016-8-22 &#xff0c;基于此日期前的最新百度地图API V2.0。 感谢 于忠达博客 提供的方法。 更新日志&#xff1a; 2016-09-21 删除IE下不支持的console.log&#xff0c;修改部分DEMO。 下载地址&#xff1a;baid…

ZJS-415/DC220V中间继电器

ZJS-415/DC220V中间继电器 品牌&#xff1a;JOSEF约瑟 名称&#xff1a;中间继电器 型号&#xff1a;ZJS-415&#xff1b;ZJY-620 触点容量&#xff1a;5A/250V 功率消耗&#xff1a;≤1.5W&#xff0c;≤3W&#xff0c;≥5W&#xff0c;≤7W&#xff0c;≤3VA&#xff0c;≤7V…

18V转5V低功率LDO大电流降压芯片

15V和18V的电源供电&#xff0c;要输出转5V的降压电路时&#xff0c;需要注意输入拔插和开关时的浪涌尖峰电压&#xff0c;时常我们需要加TVS管&#xff0c;或者电解电容等等来吸收尖峰高压&#xff0c;同时我们在芯片IC的选择上&#xff0c;也需要把注意输入电压的范围提供留有…

毫安时mAh与瓦时Wh的计算

毫安时mAh与瓦时Wh的计算 毫安时&#xff08;mAh&#xff09;---&#xff08;q&#xff09; 瓦时&#xff08;Wh&#xff09;-------&#xff08;W&#xff09; 电压&#xff08;V&#xff09;----------&#xff08;U&#xff09; 公式&#xff1a;WqU 举例&#xff1a;8…

380伏电压一安是多少瓦?

"伏"是电压单位. "安"是电流单位. "瓦"是电功单位. "度"是电能单位. 其间有关系,但不能相互相等. 380V电压,1A的电流,其电功是380*1380W,其电能是(按上小时计算): 380V*1A*1H0.38KV*1A*1H0.38KWHBN 也就是0.38度. 当然,上面是按照纯电…

【Spring Cloud系列】- Eureka使用详解

【Spring Cloud系列】- Eureka使用详解 文章目录 【Spring Cloud系列】- Eureka使用详解一、概述二、Eureka简介三、Eureka结构与作用Eureka结构图Eureka采用CS&#xff08;Client/Server,客户端/服务器&#xff09;架构&#xff0c;它包括以下两大组件 四、Eureka集群及与应用…