GeoJSON.js icon indicating copy to clipboard operation
GeoJSON.js copied to clipboard

Unable to overwrite isGeometryValid function.

Open hparkertt opened this issue 6 years ago • 5 comments

Running this in NodeJS, I seem to be unable to overwrite this function to provide a custom implementation (as suggested by the comment). Here is a snippet of what I'm trying to do:

function translate(json) {
  GeoJSON.isGeometryValid = GJV.isGeometryObject;
  return GeoJSON.parse(json, { Point: 'coords', doThrows: { invalidGeometry: true } } );
}

This appears to be a scoping issue. You can set the function on the GeoJSON object, but that does not change the function used internally. I've tested this with a few console.log statements. For example:

function translate(json) {
  GeoJSON.isGeometryValid = GJV.isGeometryObject;
  console.log(GeoJSON.isGeometryValid); // displays the GJV.isGeometryObject function
  return GeoJSON.parse(json, { Point: 'coords', doThrows: { invalidGeometry: true } } );
}

In geojson.js:

...
GeoJSON.parse = function(objects, params, callback) {
  ...
  console.log(GeoJSON.isGeometryValid); // displays the original GeoJSON.isGeometryValid function
  geomAttrs.length = 0;
  ...
}

Maybe the isGeometryValid function should be included in the GeoJSON.defaults object, allowing for it to be overwritten as part of the params parameter?

hparkertt avatar Oct 02 '19 15:10 hparkertt

Hi @caseycesari , have you had a chance to look over this yet?

hparkertt avatar Nov 19 '19 13:11 hparkertt

Hi @hparkertt. Thanks for the ping. I haven't had a chance yet. Realistically, I'm hoping to wrap up all the open PRs and issues by the end of the year.

caseycesari avatar Nov 26 '19 14:11 caseycesari

Hey @caseycesari , just checking in again. Let me know if you need anything!

hparkertt avatar Jan 13 '20 13:01 hparkertt

Hi @caseycesari , any word on this?

hparkertt avatar Jun 08 '20 16:06 hparkertt

Hello @hparkertt Many apologies for the delay. Truly trying to get to this soon, and make a release.

caseycesari avatar Jul 14 '20 13:07 caseycesari