Leaflet openstreetmap 加载,但没有出现

Leaflet openstreetmap loads, but does not appear

我尝试制作传单地图并添加Openstreetmap作为背景地图。但是,如果我加载地图,则什么也不会出现。检查 firefox 网络分析,所有需要的图块都已成功加载,但它们没有显示。

我的HTML代码:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">

    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin=""/>
    <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js" integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg==" crossorigin=""></script>

    <link rel="stylesheet" href="main.css">

    <title>title</title>
</head>
<body>
    <div id="map">
    </div>
    <div id="logo">
        <!--- a logo will appear here --->
    </div>
    <script src="map.js"></script>
</body>

我的javascript代码:

var map = L.map('map', {
    center: [51.505, -0.09],
    zoom: 13
});

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

div "map" 的 z-index 比 "logo" 高,所以这应该不是问题。

map style 在哪里?

您应该为地图指定高度和宽度以便进行渲染

<div id="map" style="width: 600px; height: 400px;">

Demo