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

Filter classes not exported #382

Open
coffex opened this issue Jun 11, 2019 · 1 comment
Open

Filter classes not exported #382

coffex opened this issue Jun 11, 2019 · 1 comment
Milestone

Comments

@coffex
Copy link

coffex commented Jun 11, 2019

In a project I've been working on recently I've had need of the Geometry#apply function to convert the coordinates to and from WGS84, sinusoidal, and gnomonic projections.

I've had a lot of trouble getting this function to work correctly, but in the end I ended up using code similar to the following:

const jsts = require("jsts");

const translateFilter = {
  interfaces_: {
    indexOf: function (cls) {
      // the class name here is minified! Unable to trust that it remains stable between releases.
      console.log(cls.name);
      return true;
    }
  },
  filter: function (coord) {
    coord.x += 1;
    coord.y += 1;
  }
};

const coords = [new jsts.geom.Coordinate(0, 0), new jsts.geom.Coordinate(1, 1)];
const line = new jsts.geom.GeometryFactory().createLineString(coords);

console.log(line.getEnvelopeInternal());
line.apply(translateFilter);
line.geometryChanged();
console.log(line.getEnvelopeInternal());

This works ok if I want to just use CoordinateFilter, as its the first thing all the #apply implementations check for, but if I want to use a CoordinateSequenceFilter or GeometryFilter for example, I have to distinguish between them by their minified names.

It would be useful to have the *Filter classes exported in jsts.geom for this purpose, or to have a better interface for applying filters. If the *Filter classes do get exported, it would also be useful for their interfaces_ getter implementations to be filled out instead of being a blank array (see here). At that point the user could just subclass them and override #filter.

@bjornharrtell
Copy link
Owner

Interesting. Obviously the interfaces was never meant to be used other than internally, but I see your use case here.

@bjornharrtell bjornharrtell self-assigned this Jun 11, 2019
@bjornharrtell bjornharrtell added this to the Future milestone Nov 26, 2019
@bjornharrtell bjornharrtell removed their assignment Nov 26, 2019
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

No branches or pull requests

2 participants