Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install this leaflet module using npm? #53

Open
jcpatac opened this issue Jun 21, 2018 · 8 comments
Open

How to install this leaflet module using npm? #53

jcpatac opened this issue Jun 21, 2018 · 8 comments

Comments

@jcpatac
Copy link

jcpatac commented Jun 21, 2018

So I want to use this module for my leaflet map but I'm developing it on ionic. How can I use this module?

@calvinmetcalf
Copy link
Owner

copy over the shp.js file leaflet.shapefile.js files into your vendors folder, or really just any folder in your app and then require them (require shp first) this was written way before I know about bundlers or anything

@jcpatac
Copy link
Author

jcpatac commented Jun 21, 2018

Okay, so I did just that. Inside shp.js, in the binaryAjax function, I also tweaked the ajax.addEventListener because it did not trigger or something like that. So I changed it into ajax.onreadystatechange. The logic/function is still the same but I still got an error. The error is on return resolve(new Buffer(ajax.response));
It seems like the response is null. Any thoughts on this?
image

@calvinmetcalf
Copy link
Owner

change new Buffer(ajax.response) to Buffer.from(ajax.response)

@calvinmetcalf
Copy link
Owner

more generally the shapefile to geojson library is available on npm as shpjs and should work, it's only this leaflet plugin that isn't working, you might be better off just using shpjs directly and then using the built in leaflet geojson stuff.

@jcpatac
Copy link
Author

jcpatac commented Jun 21, 2018

So I changed new Buffer(ajax.response) to Buffer.from(ajax.response) but the same error occurred. When I log the response value to the console, it says null. I don't know why though. I think it's because I'm fetching the file locally? I am also in a localhost development server.

@calvinmetcalf
Copy link
Owner

yup local would be the issue, run a server so it's on local host npm install -g server && serve will do the trick

@jcpatac
Copy link
Author

jcpatac commented Jun 22, 2018

I already did this and the error still occurred. I don't know what went wrong really

@calvinmetcalf
Copy link
Owner

as I said above, this shapefile plugin for leaflet is pretty old, you might be better off using the shapefile to geojson library directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants