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

Eliminate Source#on{Add,Remove}(map) #3350

Open
jfirebaugh opened this issue Oct 12, 2016 · 3 comments
Open

Eliminate Source#on{Add,Remove}(map) #3350

jfirebaugh opened this issue Oct 12, 2016 · 3 comments

Comments

@jfirebaugh
Copy link
Contributor

The main use of on{Add,Remove}(map) in source subclasses is to store a reference to the map for later use. This introduces both statefulness (certain source operations work only after onAdd has been called) and tight coupling between a source and the map.

Instead, sources should be passed the things to which they need access as parameters to the relevant methods.

Ref #3255 (comment)

@mourner
Copy link
Member

mourner commented Oct 12, 2016

Instead, sources should be passed the things to which they need access as parameters to the relevant methods.

It's not always possible directly — e.g. map.getSource('image').setCoordinates(coords), where setCoordinates depends on map transform to recalculate coords. We'll have to pass a map reference to methods like loadTile.

@jfirebaugh
Copy link
Contributor Author

In that case, setCoordinates should be a simple setter, deferring the calculations that require a transform until a later time. Ideally loadTile should not take a map reference but rather a reference to the transform or whatever other state is needed, so that there isn't a circular dependency between map and sources.

@lucaswoj
Copy link
Contributor

Thank you for opening! This will go hand-in-hand with #3186.

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

No branches or pull requests

3 participants