gHupf
gHupf

Reputation: 154

Leaflet openstreetmap loads, but does not appear

I try to make a leaflet map and added Openstreetmap as a background map. But if I load the map, nothing appears. Checking the firefox network analysis all the required tiles are loaded succesfully, but they do not show.

My HTML code :

<!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>

My javascript code :

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);

The div "map" has a higher z-index than "logo", so that should not be the problem.

Upvotes: 0

Views: 974

Answers (1)

kboul
kboul

Reputation: 14600

Where is map style ?

You should give a height and a width to your map in order to be rendered

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

Demo

Upvotes: 2

Related Questions