Closed sxwebster closed 2 years ago
ok so
shp(myshp).then(function (data) {
geo.addData(data).catch(e=>console.log('error',e));
});
should be
shp(url).then(function (data) {
geo.addData(data)
}).catch(e=>console.log('error',e));
that being said, what you were trying to do should have worked but there were a couple bugs
function get(url) {
return fetch(url).then(res => res.arrayBuffer())
}
or
async function get(url) {
const resp = await fetch(url);
if (resp.status > 299) {
throw new Error(resp.statusText);
}
return resp.arrayBuffer();
in other words you don't need to convert into a blob and then into an arrayBuffer
this returns a promise that needs to be resolved before it could be passed to shp
get("https://tmp-demo-dev-bucket.s3.ap-southeast-2.amazonaws.com/my_boxes.zip")
.then((myshape) =>shp(myshape))
.then((data) => {
geo.addData(data)
}).catch(e=>console.log('error',e));
but again that isn't actually necessary since this library can take a url to a shapefile
lastly
new L.Shapefile(myshp);
didn't work because:
Thank you very much for taking the time to reply. In the end the easiest way was to include the shapefile library. It's really good of you to illustrate the other way too, however.
The following example 3 different ways I've been trying to load a shefile from a URL.
I cannot use the method shown on the front page of the leaflet.shapefile repository as it errors our with L.shapefile is not a constructor. I'm struggling to use the examples found on the shapefile-js page because they result in trying to extract an arraybuffer from a returned Javascript Promise.