Leaflet openstreetmap加载,但不会出现

问题描述 投票:0回答:1

我尝试制作传单地图并添加Openstreetmap作为背景地图。但如果我加载地图,则不会显示任何内容。检查firefox网络分析成功加载所有必需的磁贴,但它们不显示。

我的HTML代码:

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

    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin=""/>
    <script src="https://unpkg.com/[email protected]/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”高,所以这不应该是问题。

javascript html leaflet openstreetmap
1个回答
2
投票

map style在哪里?

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

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

Demo

© www.soinside.com 2019 - 2024. All rights reserved.