Skip to content

Unable to overwrite isGeometryValid function. #50

@hparkertt

Description

@hparkertt

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions