calvinmetcalf / leaflet.shapefile

Shapefile in Leaflet
http://calvinmetcalf.github.io/leaflet.shapefile/
MIT License
258 stars 119 forks source link

Error reading arraybuffer #22

Open turbobuilt opened 9 years ago

turbobuilt commented 9 years ago

Hello, I'm having an issue loading a raw arraybuffer into the shapefile program. Here is the error I get in chrome:

GET http://domain.com/dir/rawinflate.min.js.map 404 (Not Found) [object%20ArrayBuffer].shp:1 GET http://domain.com/dir/[object%20ArrayBuffer].shp 404 (Not Found) [object%20ArrayBuffer].prj:1 GET http://domain.com/dir//[object%20ArrayBuffer].prj 404 (Not Found) [object%20ArrayBuffer].dbf:1 GET http://domain.com/dir//[object%20ArrayBuffer].dbf 404 (Not Found)

The plugin is working fine if I load from a url, but I'm just having an issue here. To load it, I use

var r = new FileReader();
r.onload = function (e) {
  var contents = e.target.result;
  var layer = new L.Shapefile(contents, {style: {
    "color": "#000000",
    "fill": "none",
    "weight": 2
  }});
}
r.readAsArrayBuffer(f)

This may very well be an issue on my end, and if so, sorry for opening an issue.

calvinmetcalf commented 9 years ago

I believe you need to do

var contents = r.result;

That's how I've done it at http://leaflet.calvinmetcalf.com

turbobuilt commented 9 years ago

I changed it to r.result, and got the same error. Using the Javascript debugger in chrome indicates that it is indeed an array buffer that I am passing in both instances. What's more, the same shape file loads fine via AJAX. Any ideas?

calvinmetcalf commented 9 years ago

Hm I can look into it tommorow

On Sun, May 10, 2015, 4:12 PM dtruel notifications@github.com wrote:

I changed it to r.result, and got the same error. Using the Javascript debugger in chrome indicates that it is indeed an array buffer that I am passing in both instances. What's more, the same shape file loads fine via AJAX. Any ideas?

— Reply to this email directly or view it on GitHub https://github.com/calvinmetcalf/leaflet.shapefile/issues/22#issuecomment-100691996 .

calvinmetcalf commented 9 years ago

oo make sure you are not using a worker (aka make sure catiline is not on the page) as that will assume it's a url.

turbobuilt commented 9 years ago

Awesome, that fixed it! I never would have guessed that myself as I'm not familiar with workers/catiline. Thanks a million!

davidlukerice commented 9 years ago

Are there any plans for supporting passing arrayBuffers to the worker?