question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

readFeatures method throws an error

See original GitHub issue

I am experiencing an issue with OpenLayers readFeatures method. Whenever i try to include this code…

const format = new OlFormatGeoJSON();
// following line throws an error
const features = format.readFeatures(buildingsData);

… into my react-geo application, the following error message shows up:

Uncaught SyntaxError: Unexpected token / in JSON at position 0
    at JSON.parse (<anonymous>)
    at getObject (JSONFeature.js:216)
    at GeoJSON.readFeatures (JSONFeature.js:59)
    at Module../src/components/Map.js (Map.js:107)
    (and many more) 

I already tried to reinstall Ol and react-geo, but the error message still remains the same. My goal is to implement the AgFeatureGrid from react-geo, but i’m not sure if the problem stems from react-geo or Open Layers.

here you can find the repo.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ahocevarcommented, Dec 1, 2019

As @mike-000 pointed out, buildingsData holds a url, but readFeatures() expects a JSON object or string. So you’d have to change your code to something like

const format = new OlFormatGeoJSON();
fetch(buildingsData).then(response => response.json()).then(json => {
  const features = format.readFeatures(json);
});
1reaction
mike-000commented, Dec 1, 2019

At https://github.com/dmenneck/campusmap/blob/master/src/components/Map.js#L56 you use buildingsData as a url. It cannot be both a url and a json string.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error reading geojson features in OpenLayers 4.6
The error gets thrown on the readFeatures method when passed the geojson. I'm open to other implementations, but I was trying to something ......
Read more >
org.geotools.geojson.feature.FeatureJSON.readFeature java ...
Thrown when trying to retrieve an element past the end of an Enumeration or Iterator. ExecutorService (java.util.concurrent). An Executor that provides methods ......
Read more >
Featurereader error using DB/2 via ODBC - wrong SQL syntax
I am trying to read features from a DB/2 database using an ODBC connection. This is the statement that throws an error;.
Read more >
Drag and drop interaction error handling in OpenLayers
Some formats will throw an error if not caught while others fail silently, so if no format works which ... readFeatures(reader.result); .
Read more >
FeatureJSON (Geotools modules 29-SNAPSHOT API)
All Methods Instance Methods Concrete Methods ... public SimpleFeature readFeature(Object input) throws IOException. Reads a feature from GeoJSON.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found