javascript - 尝试传单教程我得到一张破损的 map

标签 javascript html css maps leaflet

我已遵循传单“get started”教程

但我的 map 看起来破损了,多边形不在 map 上,就像示例中那样:

例子: enter image description here

我的 map html:

enter image description here

我的html

<html>

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

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

  <script src="http://cdn.leafletjs.com/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.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">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);

}

最佳答案

有几件事会导致这种情况,它们都与 CSS 相关。请通过检查开发者工具中的网络选项卡来确保加载了 Leaflet 的 CSS:

enter image description here

如果它加载正确,那么你有其他 CSS 规则 (elad_map.css) 会干扰 Leaflet 的 CSS 规则。

关于javascript - 尝试传单教程我得到一张破损的 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35063186/

相关文章:

javascript - 如何继续添加到 JS 变量?

html - 为什么第二个元素不会在 div 中居中?

css - 无法让页面特定的 CSS 仅在 Rails 中的一个指定页面上工作

javascript - jquery 插件 history.js 在 html4 浏览器中不能正常工作

javascript apply() 函数、jQuery 和 'this' 指针

javascript - jQuery 从事件中获取标签

html - 使 4 个 div 每个占据 1/4 空间并具有 1 像素重叠边框的 CSS/HTML 逻辑

html - 如何将 "social-media"div 放在页眉的右上角?

javascript - 如何使用 angularJS 自定义服务从 REST API 获取数据

html - 使用 Flex 防止 sibling 被插入