Reputation: 405
I have been trying to build a Web Map using the Leaflet. One of the tasks that I was trying to execute was adding a "Shapefile" on the basemap. I get the below error in the console when I try to execute the file.
TypeError: L.Shapefile is not a constructor
I have verified if my shapefile is not corrupt by running it on, http://leaflet.calvinmetcalf.com.
I am not sure where I am going wrong. I would genuinely appreciate some guidance, I am new to JavaScript and Leaflet so I may have missed something obvious.
The code:
<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>
Thank you so much!
Upvotes: 1
Views: 3956
Reputation: 2085
You need to verify that your lealet/shapefile.js
is actually loading, as every problem you have so far is indicating it's not at the path you're specifying. Checking your browser console for 404
errors will verify this.
The "not a constructor" and "not a function" errors have nothing to do with the content of your shapefile. They are both saying the properties on L
, shapefile
and Shapefile
, that your are trying to access, don't exist.
Upvotes: 2