如何实现Javascript Leaflet演示代码来显示简单的地图和点? (返回空白页)

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

我尝试模仿Leaflet(https://leafletjs.com/index.html)最简单的示例代码,如下所示。但不知怎的,我只得到了空白页。有人能发现哪里出了问题吗?非常感谢!

<html>
<head>
<title>Map view with Leaflet</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>    
</head>

<body>    
    <div id="map"></div>
    <script>
        var map = L.map('map').setView([51.505, -0.09], 13);
        L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
        L.marker([51.505, -0.09]).addTo(map);
    </script>
</body>
</html>
javascript leaflet openstreetmap
1个回答
0
投票

这个

<div id="map"></div>
的高度是0px所以它是折叠的,设置一些高度,100%固定。 例如:

<style>
    #map {
        height: 100%;
    }
</style>
© www.soinside.com 2019 - 2024. All rights reserved.