当前位置: 首页 > news >正文

使用leaflet库加载服务器离线地图瓦片(这边以本地nginx服务器为例)

1,下载nginx并配置nginx配置文件(nginx.conf中配置跨域和本地服务图片地址)


#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       1995;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {#root   html;root   D:/gmaps; #瓦片地址add_header 'Access-Control-Allow-Origin' '*';index  index.html index.htm;}#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;#    }#}}

2,leaflet中使用

<!DOCTYPE html>
<html>
<head><title>本地显示谷歌地图瓦片</title><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="leaflet.css" /><script src="leaflet.js"></script><link rel="stylesheet" href="L.Control.Zoominfo.css" /><script src="L.Control.Zoominfo.js" ></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script><script src="leaflet-tilelayer-colorizr.js"></script>
<script src="https://unpkg.com/proj4leaflet@1.4.2/lib/proj4js-compressed.js"></script>
<script src="https://unpkg.com/proj4leaflet@1.4.2/lib/proj4leaflet-compressed.js"></script>
<script src="https://unpkg.com/leaflet-google-layer/dist/leaflet-google-layer.js"></script><style>body {padding: 0;margin: 0;}html, body, #map {height: 100%;}
#map {}
#mapp{webkit-filter: invert(1) saturate(0.4) brightness(1.6)!important;-moz-filter: invert(1) saturate(0.4) brightness(1.6)!important;filter: invert(1) saturate(1) brightness(0.6)!important; filter: invert(90%) hue-rotate(180deg);filter: brightness(0.6)contrast(1.2)grayscale(0.3);-webkit-filter: invert(50%) grayscale(0) saturate(0.5) brightness(1.6) opacity(1) hue-rotate(334deg) sepia(10%) !important;-ms-filter: invert(1) grayscale(0) saturate(0.5) brightness(1.6) opacity(1) hue-rotate(334deg) sepia(10%) !important;-moz-filter: invert(1) grayscale(0) saturate(0.5) brightness(1.6) opacity(1) hue-rotate(334deg) sepia(10%) !important;filter: invert(1) grayscale(0) saturate(0.5) brightness(1.6) opacity(1) hue-rotate(334deg) sepia(1%) !important;
}
.leaflet-zoom-animated img {} </style>
</head>
<body><div id="map"></div><script>var map = L.map('map', {zoominfoControl: true,zoomControl: false,zoom: 5, //center: [31.22, 121.48], attributionControl: true }).setView([23.3725, 116.4238], 5);//var map = L.map('map').setView([23.1291, 113.2644], 13);/*L.tileLayer('gmaps/{z}/{x}/{y}.png', {maxZoom: 15,attribution: 'Map data &copy; GoogleMap,Support by <a href="http://rovertang.com/">RoverTang</a>'}).addTo(map);*/L.tileLayer.colorizr('http://192.168.2.25:1995/{z}/{x}/{y}.png', {maxZoom: 6,crossOrigin: "Anonymous",attribution: 'Map data &copy; GoogleMap,Support by <a href="http://rovertang.com/">RoverTang</a>',colorize: function (pixel) {// 这个方法用来调整所有的图片上的rgb值,pixel是图片原有的rgb值pixel.r += 24;pixel.g += 24;pixel.b += 24;// pixel.a+=0.1;return pixel;}}).addTo(map);var marker = L.marker([22.7457, 113.9454]).addTo(map).bindPopup("这是一个标注点").openPopup();var marker = L.marker([35.86, 99.66]).addTo(map).bindPopup("这是二个标注点").openPopup();var marker = L.marker([23.6673527777777, 104.385552777777]).addTo(map).bindPopup("这是二个标注点").openPopup();</script>
</body>
</html>

http://www.dtcms.com/a/494462.html

相关文章:

  • 无状态协议HTTP/HTTPS (笔记)
  • 模式识别与机器学习课程笔记(8):特征提取与选择
  • python+uniapp基于微信美食点餐系统小程序
  • 【邀请函】锐成信息 × Sectigo | CLM - SSL 证书自动化运维解决方案发布会
  • 基于MATLAB实现基于距离的离群点检测算法
  • 冠县网站建设电话wordpress插件 电商
  • 【Android】RecyclerView LayoutManager 重写方法详解
  • 数据流通合规新基建 隐私计算平台的三重安全防线
  • MySQL-2--数据库的查询
  • 微信公众号商城网站开发wordpress 留言板制作
  • 虚幻基础:角色旋转控制角色视角控制
  • 【轨物方案】智慧供暖全景运营物联网解决方案
  • 超越“接收端”:解析视频推拉流EasyDSS在RTMP推流生态中的核心价值与中流砥柱作用
  • 自助建站上建的网站免费吗信息技术网站建设专业
  • 融合SpringBoot3和Vue3工程
  • 怎么学做网站制作商水县住房城乡建设网站
  • 16-机器学习与大模型开发数学教程-第1章 1-8 泰勒展开与高阶近似
  • 【学习系列】SAP RAP 6:行为定义-Concurrency Control
  • docker 运行容器限制 CPU
  • Python自动化从入门到实战(24)如何高效的备份mysql数据库,数据备份datadir目录直接复制可行吗?一篇给小白的完全指南
  • 个人可以备案网站的内容国外直播平台tiktok
  • C语言也能干大事网站开发pdf企业网站管理系统多站多语言版
  • 清理页面缓存
  • YD925输出5V,高性价比的非隔离电源方案详细介绍
  • 零基础新手小白快速了解掌握服务集群与自动化运维(十二)Python编程之常用模块
  • SQL注入完全攻略:从手工注入到自动化工具的渗透实战
  • 做网站的价格是多少临沂网站域名
  • 深入理解 HTML `<label>` 的 `for` 属性:提升表单可访问性与用户体验
  • 大型语言模型(LLM)文本中提取结构化信息:LangExtract(一)
  • Flask应用改用Waitress运行