Reputation: 3
I am facing a problem in loading shapefiles on Leaflet. Many examples on the Internet use a compressed shapefiles (.zip) containing these files:
Many said that only .shp, .shx, and .dbf are mandatory so that Leaflet can show the shape on the map. One example working shapefiles can be found here. It consists of shp, shx, dbf, and prj.
Then I tried to use another shapefiles at this page (click the sample data). The .zip file contains not only the shapefile but also the other files, so I took only the shapefile folder (contains shp, shx, dbf, and prj) and compressed them to form a new compressed file. Then, I put the file name as parameter to 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 © <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>
NOTE: I use own tile server and have performed chmod +x
to Shapefile.zip
(I use Mac OSX 10.9.2 and Leaflet 0.7.3 with leaflet.label
, leaflet.sprite
, and Leaflet.Shapefile
plugins)
Why is that so? The first shapefile that worked and the second shapefile that was compressed by myself contain the same number of file, and three necessary files (shp, shx, and dbf) are included in both of them. Am I missing something fundamental or important?
Any thought will be veeeery appreciated. Thanks!
Upvotes: 0
Views: 4988
Reputation: 784
zipping them on a mac added a folder called __MACOSX
which has a file in it with the same name as the other files but proceeded with a dot, it thinks this is a shapefile, fixed your shapefile should work on http://leaflet.calvinmetcalf.com/
Upvotes: 0