Skip to content

Commit

Permalink
Merge pull request #2 from patrickarlt/gh-pages
Browse files Browse the repository at this point in the history
add load and loading events
  • Loading branch information
calvinmetcalf committed Apr 11, 2014
2 parents 0a4a5df + 8e777dc commit 39b249c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<script>
var m = L.map('map').setView([ 42.09618442380296, -71.5045166015625],8);
var watercolor = L.tileLayer('http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg',{attribution:'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; 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>'}).addTo(m);

var shpfile = new L.Shapefile('congress.zip',{onEachFeature:function(feature, layer) {
if (feature.properties) {
layer.bindPopup(Object.keys(feature.properties).map(function(k){
Expand All @@ -36,6 +36,10 @@
}
}});
shpfile.addTo(m);
shpfile.once("load", function(){
console.log("finished loaded shapefile");
});

</script>
</body>
</html>
Expand Down
7 changes: 6 additions & 1 deletion leaflet.shpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ L.Shapefile =L.GeoJSON.extend({
},
addFileData:function(file){
var self = this;
self.fire('data:loading');
if(typeof file !== 'string' && !('byteLength' in file)){
return self.addData(file);
var data = self.addData(file);
self.fire('data:loaded');
return data;
}
if(self.worker){
self.worker.data(cw.makeUrl(file)).then(function(data){
self.addData(data);
self.fire('data:loaded');
});
}else{
shp(file).then(function(data){
self.addData(data);
self.fire('data:loaded');
});
}
return this;
Expand Down

0 comments on commit 39b249c

Please sign in to comment.