Leaflet:TypeError:L.Shapefile不是构造函数

时间:2017-09-18 22:31:03

标签: javascript leaflet

我一直在尝试使用Leaflet构建Web地图。我试图执行的任务之一是添加一个" Shapefile"在底图上。我尝试执行文件时在控制台中收到以下错误。

  

TypeError:L.Shapefile不是构造函数

我已经通过运行它来验证我的shapefile是否没有损坏, http://leaflet.calvinmetcalf.com

我不确定我哪里出错了。我真的很感激一些指导,我是JavaScript和Leaflet的新手,所以我可能错过了一些明显的东西。

代码:

<html>
<head>
  <title>A Leaflet map!</title>
  <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"/>
  <link rel="stylesheet" href="css/bootstrap.css" />

  <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="leaflet/leaflet.js"></script>
  <script src="leaflet/leaflet.shpfile.js"></script>
  <script src="leaflet/shp.js"></script>
  <style>
    #map{ height: 100% }
  </style>
</head>
<body>

  <div id="map"></div>
  <script>
  var map = L.map('map').setView([32.78, -96.80], 11);

  L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
    {
      attribution: 'Tiles by <a href="http://mapc.org">MAPC</a>, Data by <a href="http://mass.gov/mgis">MassGIS</a>',
      maxZoom: 17,
      minZoom: 9
    }).addTo(map);

  var shpfile = new L.Shapefile("DALNEI.zip");
  shpfile.addTo(map);

  </script>
</body>
</html>

非常感谢你!

1 个答案:

答案 0 :(得分:0)

您需要验证您的lealet/shapefile.js是否实际正在加载,因为到目前为止您遇到的每个问题都表明它不在您指定的路径上。检查浏览器控制台是否存在404错误,将验证这一点。

“not an constructor”和“not a function”错误与shapefile的内容无关。他们都在说{you}尝试访问的LshapefileShapefile上的属性,不存在。