gpt4 book ai didi

javascript - 基本传单示例未在浏览器中显示任何内容

转载 作者:行者123 更新时间:2023-11-30 11:39:33 26 4
gpt4 key购买 nike

我无法让基本的 LeafletJS 示例正常工作。我的日志表明正在导入 LeafletJS,并且某些内容已绑定(bind)到我的 #map div。我的调试器中的网络选项卡也确认正在加载 leaflet.js 和 leaflet.css。

谁能告诉我我错过了什么?我所看到的只是一个空白的白色浏览器窗口。

谢谢!

<!doctype html>
<html>
<head>
<title>A Leaflet map!</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
<style>
#map{ height: 100% }
</style>
</head>
<body>

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

<script>
console.log('L', L)

const position = [51.505, -0.09];
const map = L.map('map').setView(position, 13);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

console.log('map', map)
</script>
</body

最佳答案

问题不在传单代码中,而是在 css 中。您指定了 #map div的高度为100% , 但未设置其父级的高度 ( <body> )。此外,您需要设置 #map 的宽度

引用这个稍微修改过的jsFiddle:https://jsfiddle.net/k16r8s9g/

关于javascript - 基本传单示例未在浏览器中显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43217637/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com