1'use strict'; 2 3/* global cw, shp */ 4L.Shapefile = L.GeoJSON.extend({ 5 options: { 6 importUrl: 'shp.js' 7 }, 8 9 initialize: function(file, options) { 10 L.Util.setOptions(this, options); 11 if (typeof cw !== 'undefined') { 12 /*eslint-disable no-new-func*/ 13 if (!options.isArrayBuffer) { 14 this.worker = cw(new Function('data', 'cb', 'importScripts("' + this.options.importUrl + '");shp(data).then(cb);')); 15 } else { 16 this.worker = cw(new Function('data', 'importScripts("' + this.options.importUrl + '"); return shp.parseZip(data);')); 17 } 18 /*eslint-enable no-new-func*/ 19 } 20 L.GeoJSON.prototype.initialize.call(this, { 21 features: [] 22 }, options); 23 this.addFileData(file); 24 }, 25 26 addFileData: function(file) { 27 var self = this; 28 this.fire('data:loading'); 29 if (typeof file !== 'string' && !('byteLength' in file)) { 30 var data = this.addData(file); 31 this.fire('data:loaded'); 32 return data; 33 } 34 if (!this.worker) { 35 shp(file).then(function(data) { 36 self.addData(data); 37 self.fire('data:loaded'); 38 }).catch(function(err) { 39 self.fire('data:error', err); 40 }) 41 return this; 42 } 43 var promise; 44 if (this.options.isArrayBufer) { 45 promise = this.worker.data(file, [file]); 46 } else { 47 promise = this.worker.data(cw.makeUrl(file)); 48 } 49 50 promise.then(function(data) { 51 self.addData(data); 52 self.fire('data:loaded'); 53 self.worker.close(); 54 }).then(function() {}, function(err) { 55 self.fire('data:error', err); 56 }) 57 return this; 58 } 59}); 60 61L.shapefile = function(a, b, c) { 62 return new L.Shapefile(a, b, c); 63};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.