[英]Leaflet map wont appear
我正在嘗試使用地圖,但它似乎不起作用,它只顯示一個空白區域。 幾天前我硬重置了我的電腦,所以我不確定我的電腦是否缺少某些東西或我的代碼有問題,但這里是:
頭文件.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>
主文件:
div.mapa{
height: 420px;
}
頁腳.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>
主要.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();
}
});
});
索引.php:
<div id="mapa" class="mapa"></div>
畢竟......它沒有顯示,它只是我網絡中的一個空白區域
你的 IIFE 永遠不會被調用:
(function () {
// some code...
}); // Function is expressed but not invoked
應該:
(function () {
// some code...
})(); // Make sure to add the final parenthesis pair
為了完整起見,它也適用於大括號后面的調用括號對:
(function () {
// some code...
}());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.