Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to overwrite isGeometryValid function. #50

Open
hparkertt opened this issue Oct 2, 2019 · 5 comments · May be fixed by #53
Open

Unable to overwrite isGeometryValid function. #50

hparkertt opened this issue Oct 2, 2019 · 5 comments · May be fixed by #53

Comments

@hparkertt
Copy link
Contributor

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
Copy link
Contributor Author

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

@caseycesari
Copy link
Owner

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.

@hparkertt
Copy link
Contributor Author

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

@hparkertt
Copy link
Contributor Author

Hi @caseycesari , any word on this?

@caseycesari
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants