惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - 疯子110

Vue3 + Vite + Ts 报错:Property ‘ ‘ does not exist on type ‘never‘ activiti部署流程后act_re_procdef表中无流程定义信息 【转】openEuler欧拉系统重置密码 【转】nginx开启https导致springboot无法获取正确浏览器请求地址问题 【转】SLF4J(W): No SLF4J providers were found. 解决方法 vue项目放在springboot项目里后,刷新页面会显示whitelabel error page Vue3 echarts tooltip添加点击事件(最简版) Vue3富文本编辑器wangEditor 5使用总结【转载】 解决 vue3 中 Proxy(Object) 对象无法直接读取或使用 centos7-分区2T以上大硬盘[转】 关于mybatis进行sql查询字段值为null而不显示问题解决办法 Vue3 - 项目中使用 debugger 在 chrome 谷歌浏览器中失效 vue项目error Unexpected ‘debugger‘ statement no-debugger报错 vue项目中 报错 error ‘xxx‘ is assigned a value but never used 无法加载文件 D:\Program Files\xxxxx\vue.ps1,因为在此系统上禁止运行脚本”的解决方法 - 疯子110 Vue3安装配置+VSCode开发环境搭建,超详细保姆级教程(图文) 【转】将postgresql表名和字段名统一转换为小写 【cesium重新梳理】1.cesium知识整理 【cesium】修改底图颜色为蓝色科技范儿
在vue中使用leaflet加载地图【转载】
疯子110 · 2025-03-11 · via 博客园 - 疯子110

之前碰到局域网中搭建地图需求,用leaflet进行操作(vue2项目),以此记录:

一.安装引入

1

npm install leaflet --save

在main.js中引入(也可以在所需页面引入,由于leftlet很小,只有38K,就直接全局了)

1

2

import L from "leaflet"

import "leaflet/dist/leaflet.css" 

二.在vue中使用

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

<template>

  <div class="mapBox">

    <div>在vue2中使用leaflet</div>

    <!-- 地图容器 -->

    <div id="map"></div>

  </div>

</template>

<script>

  export default {

    name: 'LeafletMap',

    data() {

      return {

        map: null

      }

    },

    mounted() {

      this.initMap()

    },

    methods: {

      initMap() {

        let map = L.map("map", {

          center: [24.485666, 118.095498], 

          zoom: 12, 

          attributionControl: true

          zoomControl: true 

        });

        this.map = map; 

        L.tileLayer(

          "http://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}"

        ).addTo(map) 

      }

    }

  }

</script>

<style scoped>

  #map {

    width: 800px;

    height: 500px;

    margin: 50px auto;

  }

</style>

  效果如下:

 初始化的时候还有一些别的参数可配置:地图状态:minZoom,maxZoom,crs,交互选项:dragging等,

官方文档地址:  https://leafletjs.com/reference.html,

木遥翻译中文版地址:链接:https://pan.baidu.com/s/143LMcNA9leTWuscplaf3JQ提取码:g7i2

1

tileLayer底图用的是高德的,地址参考:  https:

复制代码

高德路网:
https://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=2&style=8&ltype=11
高德影像:
https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}
高德矢量:
http://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}
谷歌矢量:
http://mt2.google.cn/vt/lyrs=m&scale=2&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}
谷歌路网:
https://mt1.google.com/vt/lyrs=h&x={x}&y={y}&z={z}
谷歌影像:
http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}
谷歌影像带注记:
https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}
谷歌地形:
https://mt1.google.com/vt/lyrs=t&x={x}&y={y}&z={z}
谷歌地图矢量带地形渲染:
https://mt1.google.com/vt/lyrs=r&x={x}&y={y}&z={z}
街景地图:
https://tile.openstreetmap.org/{z}/{x}/{y}.png
天地图影像:
http://t7.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=e3b434f191257368fc43c5b011ab5911
天地图影像注记:
http://t7.tianditu.gov.cn/cia_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=e3b434f191257368fc43c5b011ab5911
天地图矢量:
http://t7.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=e3b434f191257368fc43c5b011ab5911

天地图矢量注记:
http://t7.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=e3b434f191257368fc43c5b011ab5911

天地图地形:
http://t7.tianditu.gov.cn/ter_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=ter&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=e3b434f191257368fc43c5b011ab5911
天地图地形注记:
http://t7.tianditu.gov.cn/cta_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cta&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=e3b434f191257368fc43c5b011ab5911

腾讯地图矢量:
http://rt0.map.gtimg.com/realtimerender?z={z}&x={x}&y={-y}&type=vector&style=0

复制代码

多说一句,本来想在高德官网找类似的地址,结果没找到.问过客服说是暂时不对外提供三方渲染引擎使用,所以如果商用,慎重,可以找开放的.

github也有大神把leaflet进行了封装,github地址:  https://github.com/vue-leaflet/Vue2Leaflet

当然,还有地图标点,划线,划区域我们下次再说