From cf27e7eeb4241de42a19a7c14d722f12e48239cb Mon Sep 17 00:00:00 2001 From: David Rice Date: Wed, 13 May 2015 14:53:59 -0500 Subject: [PATCH 1/3] Add optional importUrl to Shapefile signature --- leaflet.shpfile.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/leaflet.shpfile.js b/leaflet.shpfile.js index 5c2c4b3..f7f3921 100644 --- a/leaflet.shpfile.js +++ b/leaflet.shpfile.js @@ -1,8 +1,11 @@ L.Shapefile =L.GeoJSON.extend({ - initialize: function (file, options) { + initialize: function (file, options, importUrl) { if(typeof cw !== 'undefined'){ + if (typeof importUrl === 'undefined') { + importUrl = 'shp.js'; + } this.worker = cw(function(data,cb){ - importScripts('shp.js'); + importScripts(importUrl); shp(data).then(cb); }); } @@ -33,6 +36,6 @@ L.Shapefile =L.GeoJSON.extend({ } }); -L.shapefile= function(a,b){ - return new L.Shapefile(a,b); +L.shapefile= function(a,b,c){ + return new L.Shapefile(a,b,c); } From 7589c1523a5be376f1f4d74a80d9f250f8e0dc33 Mon Sep 17 00:00:00 2001 From: David Rice Date: Wed, 13 May 2015 15:41:38 -0500 Subject: [PATCH 2/3] guard against empty string passed as the importUrl --- leaflet.shpfile.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/leaflet.shpfile.js b/leaflet.shpfile.js index f7f3921..e12d03e 100644 --- a/leaflet.shpfile.js +++ b/leaflet.shpfile.js @@ -1,11 +1,8 @@ L.Shapefile =L.GeoJSON.extend({ initialize: function (file, options, importUrl) { if(typeof cw !== 'undefined'){ - if (typeof importUrl === 'undefined') { - importUrl = 'shp.js'; - } this.worker = cw(function(data,cb){ - importScripts(importUrl); + importScripts(importUrl || 'shp.js'); shp(data).then(cb); }); } From 344bba487eb8d9833575460fcab7e2a9a408b53d Mon Sep 17 00:00:00 2001 From: David Rice Date: Wed, 13 May 2015 15:56:12 -0500 Subject: [PATCH 3/3] Updated docs to include new importUrl parameter --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9558b97..14dbbb3 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,12 @@ to be done in a worker, you'll need [catiline](https://github.com/calvinmetcalf/ usage: ```javascript -new L.Shapefile(arrayBuffer or url[,options]); +new L.Shapefile(arrayBuffer or url[,options][,importUrl]); -L.shapefile(arrayBuffer or url[,options]); +L.shapefile(arrayBuffer or url[,options][,importUrl]); ``` Options are passed to L.Geojson as is. First argument is either an array buffer of a zipped shapefile, -the url to a zipped shapefile, or the url to file.shp (this assumes file.dbf exists). +the url to a zipped shapefile, or the url to file.shp (this assumes file.dbf exists). The importUrl parameter allows you to change where a worker loads in `shp.js` when using [catiline](https://github.com/calvinmetcalf/catiline) and defaults to `shp.js`. To easily try this out using your own shapefile, see the demo at [leaflet.calvinmetcalf.com](http://leaflet.calvinmetcalf.com/), where you can drag-and-drop your own shapefile and have it displayed on the map.