-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for arraybuffer in workers
- Loading branch information
Showing
3 changed files
with
106 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
|
||
# Change these settings to your own preference | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# We recommend you to keep these unchanged | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[{package,bower}.json] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.{js,less}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"node": true, | ||
"esnext": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"indent": 4, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"quotmark": "single", | ||
"regexp": true, | ||
"undef": true, | ||
"unused": true, | ||
"strict": true, | ||
"trailing": true, | ||
"smarttabs": true, | ||
"white": true, | ||
"jquery": true, | ||
"browser": true, | ||
"predef": ["shp", "define", "cw", "L"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,59 @@ | ||
'use strict'; | ||
|
||
/* global cw, shp */ | ||
L.Shapefile =L.GeoJSON.extend({ | ||
initialize: function (file, options, importUrl) { | ||
if(typeof cw !== 'undefined'){ | ||
importUrl = importUrl || 'shp.js'; | ||
this.worker = cw(new Function('data', 'cb', 'importScripts("' + importUrl + '");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; | ||
options: { | ||
isArrayBufer: false, | ||
importUrl: 'shp.js' | ||
}, | ||
|
||
initialize: function (file, options) { | ||
L.Util.setOptions(this, options); | ||
if(typeof cw !== 'undefined'){ | ||
/*jslint evil: true */ | ||
if(!options.isArrayBufer) { | ||
this.worker = cw(new Function('data', 'cb', 'importScripts("' + this.options.importUrl + '");shp(data).then(cb);')); | ||
} else { | ||
this.worker = cw(new Function('data', 'importScripts("' + this.options.importUrl + '"); return shp.parseZip(data);')); | ||
} | ||
} | ||
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) { | ||
if(!self.options.isArrayBufer) { | ||
self.worker.data(cw.makeUrl(file)).then(function(data){ | ||
self.addData(data); | ||
self.fire('data:loaded'); | ||
self.worker.close(); | ||
}); | ||
} else { | ||
self.worker.data(file, [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,c){ | ||
return new L.Shapefile(a,b,c); | ||
} | ||
return new L.Shapefile(a,b,c); | ||
}; |