mirror of
https://github.com/wavded/js-shapefile-to-geojson
synced 2024-11-23 14:34:54 +00:00
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) ...
This commit is contained in:
parent
db9bfd55d8
commit
c4cf216ec4
10
shapefile.js
10
shapefile.js
@ -1,14 +1,18 @@
|
|||||||
(function(window,undefined){
|
(function(window,undefined){
|
||||||
|
|
||||||
if(window.document && window.Worker){
|
if(window.document && window.Worker){
|
||||||
var worker = new Worker("shapefile.js")
|
var worker = null;
|
||||||
|
|
||||||
var Shapefile = function(o, callback){
|
var Shapefile = function(o, callback){
|
||||||
var
|
var
|
||||||
w = this.worker = worker,
|
|
||||||
t = this,
|
t = this,
|
||||||
o = typeof o == "string" ? {shp: o} : o
|
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){
|
w.onmessage = function(e){
|
||||||
t.data = e.date
|
t.data = e.date
|
||||||
if(callback) callback(e.data)
|
if(callback) callback(e.data)
|
||||||
@ -69,7 +73,7 @@
|
|||||||
xhr.send()
|
xhr.send()
|
||||||
|
|
||||||
if(200 != xhr.status)
|
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.url = o.shp
|
||||||
this.stream = new Gordon.Stream(xhr.responseText)
|
this.stream = new Gordon.Stream(xhr.responseText)
|
||||||
|
Loading…
Reference in New Issue
Block a user