-
Notifications
You must be signed in to change notification settings - Fork 1
/
leaflet.shpfile.js
38 lines (37 loc) · 1.1 KB
/
leaflet.shpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
L.Shapefile =L.GeoJSON.extend({
initialize: function (file, options) {
if(typeof cw !== 'undefined'){
this.worker = cw(function(data,cb){
importScripts('shp.js');
shp(data).then(cb);
});
}
L.GeoJSON.prototype.initialize.call(this,{features:[]},options);
this.addFileData(file);
},
addFileData:function(file){
var self = this;
self.fire('data:loading');
if(typeof file !== 'string' && !('byteLength' in 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');
self.worker.close();
});
}else{
shp(file).then(function(data){
self.addData(data);
self.fire('data:loaded');
});
}
return this;
}
});
L.shapefile= function(a,b){
return new L.Shapefile(a,b);
}