前言:在leaflet的官方文档只有静态的HTML演示并没有结合VUE的demo  虽然也有一些封装好的leaflet库例如Vue-Leaflet,但是总感觉用起来不是那么顺手,有些业务操作还是得用leaflet的API好用

步骤1:npm install leaflet  (搭建vue项目就跳过了)

页面中先下载好npm包  下一步就是在vue用引用了(以下方法都是网上教程自己整理出来的)

Main.js (也可以在入口的 .vue 页面)

import L from "leaflet";
import "leaflet/dist/leaflet.css";

步骤2:leaflet初始化

HTML

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

JS (注意哦:需要在页面渲染完成后才能执行不然会报错)

initMap() {
let map = L.map("map", {
minZoom: 3,
maxZoom: 14,
center: [39.550339, 116.114129],
zoom: 12,
zoomControl: false,
attributionControl: false,
crs: L.CRS.EPSG3857
});
this.map = map;    //data上需要挂载
window.map = map;
L.tileLayer(
"http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}"
).addTo(map);
},

最后补充: div样式需要设置宽高100% 不然会报错

#map {

  width:100%;

  height:100vh;

}

最新文章

  1. Publishing failed with multiple errors 异常
  2. 日期时间组件 - layui.laydate
  3. NK3C程序资源占用分析
  4. 9月19日下午JavaScript数组冒泡排列和二分法
  5. Arduino101学习笔记(十)&mdash;&mdash; 串口通信
  6. django1.9 创建项目和app并初始化项目
  7. 可视化数据包分析工具-CapAnalysis
  8. 区分jquery中的offset和position
  9. css3选择符使用个人理解。
  10. 把Orchard部署到Windows Azure Web Sites
  11. win10操作系统上,wireshark抓取https。
  12. elementUi模态框使用baiduMap错误记录
  13. 我了解到的新知识之---Cylance Protect是干吗的?
  14. Fragment中启动一个新的Activity
  15. Delphi7如何实现让Tedit显示文字垂直居中(上下居中)
  16. 整合Struts2框架和Spring框架
  17. android studio 引用aar
  18. 马哥 Linux运维基础进阶和shell入门
  19. Linux知识总汇
  20. 【Python】如何取到input中的value值?

热门文章

  1. CodeForces 778B - Bitwise Formula
  2. docker使用 Flannel(etcd+flannel)网络
  3. Spring中 bean的生命周期
  4. jmeter 5.0,http请求登录返回的cookie在头部处理方法
  5. javaScript高级程序设计第3版笔记
  6. Word:英文从“单词”中间断行
  7. 【BZOJ4671】 异或图
  8. HDU 5884 Sort ——(K叉哈夫曼树)
  9. triplet
  10. cmake 工具使用