D
D
Denis Plus2019-08-23 08:29:55
leaflet
Denis Plus, 2019-08-23 08:29:55

How to make Leaflet Map work?

I just found this lib, I'm trying to do it according to the tutorial, but instead of a map I see a gray square.
Here is the source:

<!DOCTYPE html> 
<html> 
<head>  
<meta charset="utf-8">  
<title>Leaflet JS MAp Library</title> 
<meta name="viewport" content="width=device-width, initial-scale=1" > 

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
   integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
   crossorigin=""/>
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
crossorigin=""></script>   
<link rel="stylesheet" type="text/css" href="style.css"> 
<style>
    #mapid {
        width: 600px;
        height: 600px; }
</style>
</head>
<body> 
    
    <div id="mapid"></div>    
    <script>
        var mymap = L.map('mapid').setView([10, 10], 10);
    
    </script>
</body> 
</html>

Tried to run both locally and hosted. Maybe I'm missing out on something?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Lyskov, 2019-08-23
@nikstormr

var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
        osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
        osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
        map = new L.Map('map', {center: new L.LatLng(40, -100), zoom: 7}),
        drawnItems = L.featureGroup().addTo(map);
        osm.addTo(map);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question