admin管理员组

文章数量:1291505

I have followed leaflet "get started" tutorial

but my map looks broken and the polygons are not on the map like in the example:

example:

my map html:

my html

<html>

<head>
  <title></title>
  <link rel="stylesheet" href="elad_map.css" />
  <link rel="stylesheet" href=".7.7/leaflet.css" />
</head>

<body>
  <div id="map"></div>

  <script src=".7.7/leaflet.js"></script>
  <script type="text/javascript" src="elad_map.js"></script>
</body>

</html>

I have followed leaflet "get started" tutorial

but my map looks broken and the polygons are not on the map like in the example:

example:

my map html:

my html

<html>

<head>
  <title></title>
  <link rel="stylesheet" href="elad_map.css" />
  <link rel="stylesheet" href="http://cdn.leafletjs./leaflet/v0.7.7/leaflet.css" />
</head>

<body>
  <div id="map"></div>

  <script src="http://cdn.leafletjs./leaflet/v0.7.7/leaflet.js"></script>
  <script type="text/javascript" src="elad_map.js"></script>
</body>

</html>

document.onload = loadMap();

function loadMap() {
  var map = L.map('map').setView([51.505, -0.09], 13);


  L.tileLayer('https://api.tiles.mapbox./v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
    attribution: 'Map data &copy; <a href="http://openstreetmap">OpenStreetMap</a> contributors, <a href="http://creativemons/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.">Mapbox</a>',
    maxZoom: 18,
    id: 'your.mapbox.project.id',
    accessToken: 'your.mapbox.public.access.token'
  }).addTo(map);


  var circle = L.circle([51.508, -0.11], 500, {
    color: 'red',
    fillColor: '#f03',
    fillOpacity: 0.5
  }).addTo(map);

  var polygon = L.polygon([
    [51.509, -0.08],
    [51.503, -0.06],
    [51.51, -0.047]
  ]).addTo(map);

}

Share asked Jan 28, 2016 at 13:44 Elad BendaElad Benda 36.7k91 gold badges283 silver badges493 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 11

There are a few things that would cause this and they are all related to CSS. Please make sure Leaflet's CSS is loaded by checking the networktab in your developer tools:

If it's loaded correctly than you have other CSS rules in place (elad_map.css) which interfere with Leaflet's CSS rules.

For React

Here is what you need to paste to import the leaflet css -> import "leaflet/dist/leaflet.css";

For angular devlopers, add to angular.json the following line as shown in the screenshot

本文标签: javascripttrying leaflet tutorial I get a broken mapStack Overflow