javascript - 如何在特定的 div 标签中显示传单地图?
问题描述
我正在尝试显示传单地图,但我需要使用像 document.getElementById("map") 这样的 id 在特定的 div 标签中显示地图,我在下面给出了代码,我正在使用 vuejs。
下面是我渲染地图的 div 标签
<div id="map">
</div>
下面是我的脚本
mounted () {
// L.Icon.Default.imagePath = 'assets/vendor/leaflet' TODO: make it work with webpack
Leaflet.Icon.Default.imagePath = 'https://unpkg.com/leaflet@1.0.3/dist/images'
let map = Leaflet.map(this.$el).setView([51.505, -0.09], 13)
Leaflet.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://osm.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map)
Leaflet.marker([51.5, -0.09]).addTo(map)
.bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
.openPopup()
},
解决方案
I don't know Vue, but normally you don't need to make a document.getElementById ("map"). you just have to pass the id in L.map like that
let map = Leaflet.map("map").setView([51.505, -0.09], 13)
And you have to give a height to your div "map", for example
<div id="map" height="500px">
</div>
Edit
What's wrong ? on my codesandbox you can see an example in html and javascrip which is displayed normally. Here is a link to a tutorial that uses Leaflet and Vuejs
推荐阅读
- python - 在 matplotlib 图中自定义 xticks
- php - 我怎样才能正确计算这个?
- python - 如何在 python 中通过两列合并两个 DataFrame?
- etl - ODI12c 中每个映射的最大用户数
- javascript - 在“SQLite”数据库中存储多边形类型的数据
- excel - 从整个外部工作表复制到主簿中的工作表
- javascript - Moment.js 比较总是返回 false
- symfony - 在symfony中插入ManyToMany关系时无法识别的字段
- android - 如何在firebase官方Friendly eats应用程序中特别在firestore中实现分页?
- python - VS 集成服务:平面文件源到 OLE DB 目标 - 检测文件中的新数据列,将列添加到表中,自动导入列?