2

In case anyone remembers or have seen my earlier post, I was trying to parse a GeoJSON string with limited success. That issue has been resolved, however I have a geojson file with roughly 80k lines. I took out the string in my .js file and trying to point my geojsonObject at the filepath of the geojson file. It seemed simple enough, but now I get "Unsupported GeoJSON type: undefined" in Microsoft Edge's console. The error points to the bundle-url.js

Not sure what's going wrong.

The code from the .js file linked in the console:

var bundleURL = null;
function getBundleURLCached() {
  if (!bundleURL) {
    bundleURL = getBundleURL();
  }

  return bundleURL;
}

function getBundleURL() {
  // Attempt to find the URL of the current script and use that as the base URL
  try {
    throw new Error;
  } catch (err) {
    var matches = ('' + err.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):$
    if (matches) {
      return getBaseURL(matches[0]);
    }
  }

  return '/';
}

function getBaseURL(url) {
  return ('' + url).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)\/$
}

exports.getBundleURL = getBundleURLCached;
exports.getBaseURL = getBaseURL;

The code from my .js file. The url points to the geojson file that is in the same folder of the .js:

var geojsonObject = {
        url: './locality.geojson',
        format: new GeoJSON()
}

var vectorSource = new VectorSource({
        features: new GeoJSON().readFeatures(geojsonObject, {
                dataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
        })
});

I have put my geojson through two validators, which have come up with no issues. This is all on a localhost (Ubuntu VPS), using npm.

As stated above, the geojson file is 80k lines long so I can't stick it all in here so here is a snippet;

{
   "type": "FeatureCollection",
   "features": [
   {
    "type": "Feature",
    "geometry": {
       "type": "Point",
       "coordinates":  [ -6.65073,54.34794 ]
    },
    "properties": {
    "Site":"ARMAGH"
    }
  },
snewall
  • 89
  • 1
  • 7

2 Answers2

3

You are asking GeoJSON to readFeatures on an object that is not in GeoJSON form. geojsonObject has no type so you get the "Unsupported GeoJSON type: undefined" error.

...readFeatures({ url: ..., format: ... /* there's no type! */})

Have a look at this reproduction for an example of the type of object readFeatures expects.

I suspect what you actually want is something like:

var vectorSource = new VectorSource({
    url: './locality.json',
    format: new GeoJSON({ featureProjection: "EPSG:3857" })
});

You'd usually use either url & format or features & readFeatures depending on what suits.

John Leonard
  • 909
  • 11
  • 18
-4

You can store all your data into 'data.json' file instead of .geojson. require the file in your js then you can read it using readFeatures

const data = require('./data.json')
var geojsonObject = data;

var vectorSource = new VectorSource({
    features: (new GeoJSON()).readFeatures(geojsonObject,
            {
            dataProjection: 'EPSG:4326',
            featureProjection: 'EPSG:3857'
            })
    });
Venkat
  • 1