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

projection.copy? #123

Open
mbostock opened this issue Nov 23, 2017 · 4 comments
Open

projection.copy? #123

mbostock opened this issue Nov 23, 2017 · 4 comments
Labels

Comments

@mbostock
Copy link
Member

It’d be nice to have a method to create a copy of a projection with identical settings (that, or change projections to be immutable, and every method that modifies the projection instead returns a new projection).

@tinius
Copy link

tinius commented Dec 3, 2017

+1 for immutable projections. I might even be able to help with this

@Fil
Copy link
Member

Fil commented Jun 11, 2020

Should we try and do this for d3-geo@2 d3-geo-projection@3 d3-geo-polygon@2 ?

I'm really not sure about immutable projections — they would mean rewriting almost all map interactions everywhere; but projection.copy() would be super useful in many instances.

Related (maybe), I very often find that I would need the projections to carry some metadata (for example & at the very least, a name; but also a flag indicating if it needs clipping to the sphere, etc).

@Fil Fil added the idea label Jul 10, 2020
@nirazul
Copy link

nirazul commented Dec 17, 2020

This would come in very handy when implementing rotation calculations as I currently need to set the rotation to [0, 0] and reset it to the original state after having calculated a point with attitude.

For example:

function getProjectedPoint(projection, event) {
  const originalRotation = projection.rotate()
  const pt = pointers(event, event.sourceEvent.target)[0]
  const result = projection.rotate([0, 0]).invert(pt)

  projection.rotate(originalRotation)

  return result
}

@Fil
Copy link
Member

Fil commented Dec 17, 2020

Agree, but I don't have the beginning of an idea how to implement this—projections are a very complex object and there's no easy "deep clone" operation. Maybe I'm missing something? Contributions are welcome.

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

No branches or pull requests

4 participants