query-overpass
query-overpass copied to clipboard
JSON.parse error on webpack
I'm getting JSON.parse error because overpass is returning result in content-type: "application/osm3s+xml" https://github.com/perliedman/query-overpass/blob/7bde46af36a56d0af4b8def0d5fb892138c40c7f/index.js#L69
Fixed by adding '[out:json];' in query
@Semigradsky Hi can you give an example of how do you add '[out:json];' . I got the same parse error, but with this I still receive the same parser error:
query_overpass('way(57.7,11.9,57.701,11.901)[out=json];out;', writeToHTML);
try query_overpass('[out:json];way(57.7,11.9,57.701,11.901);out;', writeToHTML);
I'm a little at loss of what the issue is here. If you could provide an example that reproduces this problem, it might be possible to debug.
I've tried @boxin-nutonomy's example from the command line without issue:
$ echo 'way(57.7,11.9,57.701,11.901);out;'| query-overpass
{"type":"FeatureCollection","features":[]}
@perliedman you will get this error if remove [out:json]; here:
https://github.com/Semigradsky/osm-validator/blob/af94db85a77e0786009bf29c3ff38d4ea0b7e7bb/src/main.js#L38
Just run
npm install
npm run build
open index.html in browser and press button.
@tyrasd It works! Thank you for the help:))))
@perliedman I have tried to run from command line and javascript. For command line,
echo 'way(57.7,11.9,57.8,12.0);out;' | query-overpass does not produce any errors. However, if you run query_overpass('way(57.7,11.9,57.8,12.0);out;', writeToHTML); in javascript, there is error in console log. Please try the javascript library to reproduce the error.
@Semigradsky hm, guessing you changed something, doing those steps works for me (displays a number of markers on the map)...
@perliedman sorry I didn't right specify the sequence of actions. Need remove [out:json]; and run npm run build after this.
Looking at this again, it is clear that the issue is that query-overpass in the browser can only handle JSON, not XML.
This should be documented. Possibly, it would also be interesting to add XML support on the browser as well.