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

feat: add static Marker.computePixelAlignment method to calculate absolute alignment #1847

Merged
merged 7 commits into from
Mar 12, 2024

Conversation

monsieurtanuki
Copy link
Contributor

@monsieurtanuki monsieurtanuki commented Mar 9, 2024

What I've done:

What can still be done:

  • I'm open to name change or to constructor against factory - but I wanted to keep the const and I'm not sure we can do that if computing the alignment
  • I can create another example, as reusing the "Marker Layer" for 2 distinct purposes can be confusing
  • Now Marker has a specific pixel-alignment constructor that MarkerLayer does not have. Not sure if that would make sense to create a new MarkerLayer constructor with the left+top parameters being used as default.

Impacted files:

  • marker.dart: added factory Marker.withPixelAlignment
  • markers.dart: now a click on the map creates a new "U-turn-left" marker with custom alignment

…lignment

Impacted files:
* `marker.dart`: added `factory Marker.withPixelAlignment`
* `markers.dart`: now a click on the map creates a new "U-turn-left" marker with custom alignment
@monsieurtanuki monsieurtanuki changed the title feat: factory Marker.withPixelAlignment with left+top custom alignment feat: factory Marker.withPixelAlignment with left+top custom alignment Mar 10, 2024
@JaffaKetchup JaffaKetchup linked an issue Mar 10, 2024 that may be closed by this pull request
@JaffaKetchup
Copy link
Member

Now Marker has a specific pixel-alignment constructor that MarkerLayer does not have. Not sure if that would make sense to create a new MarkerLayer constructor with the left+top parameters being used as default.

This is a good point, and it makes me wonder whether it would be better just to have a more simple implementation where _computeAlignment becomes a static public method on Marker named computePixelAligment. Then we wouldn't need to have any new constructors, and everything would be much simpler. What do you think?

@monsieurtanuki
Copy link
Contributor Author

This is a good point, and it makes me wonder whether it would be better just to have a more simple implementation where _computeAlignment becomes a static public method on Marker named computePixelAligment. Then we wouldn't need to have any new constructors, and everything would be much simpler. What do you think?

Looks good to me! I've just pushed it.
Perhaps this may deserve a specific example, e.g. where the MarkerLayer has an Alignment computed by Marker.computePixelAligment for U-turn-left icons, and U-turn-left Markers without specified Alignment.

@monsieurtanuki
Copy link
Contributor Author

@JaffaKetchup Finally I've removed my inconsistent example and just kept the new static Marker.computePixelAligment method.

Copy link
Contributor

@josxha josxha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally liked the factory constructor better since it was more self explaining to me.
Seeing that the relative alignment gets calculated into top/left pixel values anyways I wonder if it would be better to make pixel alignment the default and give users the option for relative alignment?

But since non-realtive marker alignment is a much needed feature so I'm down for a static method.
Edit: It would be really helpful to hint to this static method and its usage from the default Marker constructor.

@monsieurtanuki
Copy link
Contributor Author

I personally liked the factory constructor better since it was more self explaining to me.

I agree with you. It can still be done, in this PR or a next one.
The added value of the public static method is that it can be used for both MarkerLayers and individual Markers. Once you've understood it at the low level, you can use it at the high level.

Seeing that the relative alignment gets calculated into top/left pixel values anyways I wonder if it would be better to make pixel alignment the default and give users the option for relative alignment?

Possible, but I'd like to avoid breaking changes.
Besides, it looks like no solution (Alignment vs pixel) is the perfect one, and we may dance tango between both, cf. #1659, several times a year.

But since non-realtive marker alignment is a much needed feature so I'm down for a static method.

Cool

Edit: It would be really helpful to hint to this static method and its usage from the default Marker constructor.

I've just added

/// [alignment] may be computed using [computePixelAlignment].

I don't know how it works here: feel free to merge my PR when relevant.

@josxha josxha changed the title feat: factory Marker.withPixelAlignment with left+top custom alignment feat: add static Marker.computePixelAlignment method to calculate left+top alignment Mar 12, 2024
@JaffaKetchup JaffaKetchup changed the title feat: add static Marker.computePixelAlignment method to calculate left+top alignment feat: add static Marker.computePixelAlignment method to calculate absolute alignment Mar 12, 2024
Copy link
Member

@JaffaKetchup JaffaKetchup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this :)
I think it's good that we've distilled it down into the most vital component, we can always make the factories at a later point, as you said.

@JaffaKetchup JaffaKetchup merged commit bf70478 into fleaflet:master Mar 12, 2024
6 checks passed
@josxha josxha added this to the v7.0 milestone Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[FEATURE] (Re-)Support absolute Marker alignment
3 participants