[英]Leaflet map wont appear
I'm trying to use a map, but it doesn't seem to work it just shows an empty white space.我正在尝试使用地图,但它似乎不起作用,它只显示一个空白区域。 I hard reseted my pc days ago, so I'm not sure if something is missing in my pc or my code is wrong, but here it is:
几天前我硬重置了我的电脑,所以我不确定我的电脑是否缺少某些东西或我的代码有问题,但这里是:
header.php:头文件.php:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/menu_style.css">
<link rel="stylesheet" href="css/index_style.css">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""/>
<link rel="stylesheet" href="css/main.css">
</head>
main.css:主文件:
div.mapa{
height: 420px;
}
footer.php:页脚.php:
</footer>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<script src="js/main.js"></script>
</body>
</html>
main.js:主要.js:
(function(){
"use strict";
document.addEventListener('DOMContentLoaded',function(){
var mapa = document.getElementById('mapa');
if(mapa) {
var map = L.map('mapa').setView([-12.088507, -76.995052], 16);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([-12.088507, -76.995052]).addTo(map)
.bindTooltip('Paris WebCamp 2020<br> Boletos disponibles.')
.openTooltip();
}
});
});
index.php:索引.php:
<div id="mapa" class="mapa"></div>
After everything... it doesnt show, it's just a blank space in my web毕竟......它没有显示,它只是我网络中的一个空白区域
Your IIFE is never invoked:你的 IIFE 永远不会被调用:
(function () {
// some code...
}); // Function is expressed but not invoked
Should be:应该:
(function () {
// some code...
})(); // Make sure to add the final parenthesis pair
Just for completeness, it also works with the calling parenthesis pair just after the braces:为了完整起见,它也适用于大括号后面的调用括号对:
(function () {
// some code...
}());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.