From c4cf216ec4683ce28b6e8d324ab1065635731e85 Mon Sep 17 00:00:00 2001 From: Chad Burt Date: Mon, 9 Sep 2013 16:07:10 -0700 Subject: [PATCH] Add jsRoot constructor option Workers were being constructed with a hardcoded path of 'shapefile.js'. The new jsRoot option can be used to specify an alternate location. For example: shapefile = new Shapefile({ shp: "testdata/world.shp", dbf: "testdata/world.dbf", jsRoot: '/js-shapefile-to-geojson/' }, function(data) ... --- shapefile.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shapefile.js b/shapefile.js index f050d4e..9be3bb6 100644 --- a/shapefile.js +++ b/shapefile.js @@ -1,14 +1,18 @@ (function(window,undefined){ if(window.document && window.Worker){ - var worker = new Worker("shapefile.js") + var worker = null; var Shapefile = function(o, callback){ var - w = this.worker = worker, t = this, o = typeof o == "string" ? {shp: o} : o + if (!worker) { + var path = (o.jsRoot || "") + "shapefile.js" + var w = worker = this.worker = new Worker(path) + } + w.onmessage = function(e){ t.data = e.date if(callback) callback(e.data) @@ -69,7 +73,7 @@ xhr.send() if(200 != xhr.status) - throw "Unable to load " + o.shp + " status: " + xhr.status + throw "Unable to load " + o.shp + " status: " + xhr.status this.url = o.shp this.stream = new Gordon.Stream(xhr.responseText)