1

I am trying to load a geojson file. I get an error (404) if the file doesn't exist but nothing happens if the file exists. I have tried different versions of D3 ... v3, v4, v5

console.log("hello"); // displays
d3.json("/sites/default/d3_files/json/conposcovidloc.geojson")
.then(function(data) {
   console.log("data"); // nothing
})
.catch(function(error) {
   console.log("error", error); // displays 404 error if file not found
});

What could be the problem?

8
  • I just tested it with a json file (not geojson) and it displayed the console message.
    – PatriciaW
    Commented May 11, 2020 at 15:04
  • Try changing console.log("data"); into console.log(data);, without quotation marks?
    – julien
    Commented May 11, 2020 at 15:04
  • Or also: d3.json("...myfile.geojson", function(data) { console.log(data) });
    – julien
    Commented May 11, 2020 at 15:08
  • I tried with a different geojson file and it worked. I always add a comment to console but I removed it and it didn't display. Obviously there is something wrong with the geojson file but what?
    – PatriciaW
    Commented May 11, 2020 at 15:25
  • have you run the file through a GeoJSON validator like GeoJSONLint ~ geojsonlint.com
    – nmtoken
    Commented May 11, 2020 at 17:09

0

Browse other questions tagged or ask your own question.