Leaflet:显示形状所需的Shapefile?

时间:2014-12-11 08:12:49

标签: javascript leaflet openstreetmap shapefile esri

我在Leaflet上加载shapefile时遇到了问题。 Internet上的许多示例都使用包含这些文件的压缩shapefile(.zip):

  • 的.shp
  • 的.shx
  • 的.dbf
  • .PRJ
  • .sbn
  • .sbx
  • .shp.xml类型

许多人说只有.shp,.shx和.dbf是强制性的,所以Leaflet可以在地图上显示形状。可以找到一个工作shapefile的示例here。它由shp,shx,dbf和prj组成。

然后我尝试在this page使用另一个shapefile(单击示例数据)。 .zip文件不仅包含shapefile,还包含其他文件,因此我只使用shapefile文件夹(包含shp,shx,dbf和prj)并压缩它们以形成新的压缩文件。然后,我将文件名作为参数放到L.Shapefile

<html>
<head>
<link rel="stylesheet" href="leaflet/leaflet.css" />
<link rel="stylesheet" href="leaflet/leaflet.label.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="leaflet/leaflet.js"></script>
<script src="leaflet/leaflet.label.js"></script>
<script src="leaflet/leaflet.sprite.js"></script>
<script src="leaflet/leaflet.shpfile.js"></script>
<script src="leaflet/shp.js"></script>
</head>

<div id="map">
<script>
    var map = L.map('map').setView([-6.2398088,106.8152522], 10);   
    L.tileLayer('http://10.99.3.132/osm_tiles/{z}/{x}/{y}.png', {
        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>',
        maxZoom: 18
    }).addTo(map);
    var shpfile = new L.Shapefile("Shapefile.zip");
    shpfile.addTo(map);
</script>
</div>

</body>
</html>

注意:我使用自己的磁贴服务器并执行chmod +xShapefile.zip(我使用Mac OSX 10.9.2和Leaflet 0.7.3,leaflet.labelleaflet.sprite,和Leaflet.Shapefile插件)

为什么会这样?第一个工作的shapefile和由我自己压缩的第二个shapefile包含相同数量的文件,并且两个必需文件(shp,shx和dbf)都包含在它们中。我错过了一些基本或重要的东西吗?

任何想法都会受到赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

在Mac上压缩它们添加了一个名为__MACOSX的文件夹,其中有一个文件,其中包含与其他文件相同的名称,但是后面有一个点,它认为这是一个shapefile,修复了你的shapefile应该工作http://leaflet.calvinmetcalf.com/

相关问题