-
-
Notifications
You must be signed in to change notification settings - Fork 356
[Map] Add Marker Icon customization capability #2605
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
Conversation
📊 Packages dist files size differenceThanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
|
e7f3fb1
to
721e596
Compare
Hey, and thanks for the PR! Thanks! |
I have read it some time ago. I have kept in mind that we should be able to use image url OR svg (OR directly Ux-icon). It was the goal, but maybe I only did a small first step ;-) |
a7dd42e
to
100deca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
About the IconFactory
, we want to keep things simple to use for the user, and so we should not expose it to the user. Instead, we can create Icon
named constructor:
Icon::fromUrl(url: string, width: int, height: int)
Icon::fromInlineSvg(html: string, width: int, height: int)
Icon::fromUxIcon(name: string, width: int, height: int)
For each named constructor, I think we must create distinct child classes like Icon\Url
, Icon\InlineSvg
, Icon\Ux
, to keep things cleaner, and it will also helps for later...
Finally, to render a Icon\Ux
with the UxIconRenderer
, I think it should be done at rendering time in \Symfony\UX\Map\Renderer\AbstractRenderer::getMapAttributes()
, or maybe a bit before, to transform an Icon\Ux
to Icon\InlineSvg
.
Thanks!
100deca
to
3db80b6
Compare
31780fa
to
d4c98c0
Compare
@Kocal thanks for the review, I've just send an update. Let me know if you have other remarks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it's not far from being perfect, just a last round and it should be fine
if (null !== $this->uxIconRenderer && null !== $marker['icon'] && 'ux-icon' === $marker['icon']['type']) { | ||
$attrs['markers'][$key]['icon']['content'] = $this->uxIconRenderer->render($marker['icon']['content']); | ||
$attrs['markers'][$key]['icon']['type'] = 'inline-svg'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we want to throw an error if the user wanted to use an UxIcon
but without symfony/ux-icons, wdyt?
if (null !== $this->uxIconRenderer && null !== $marker['icon'] && 'ux-icon' === $marker['icon']['type']) { | |
$attrs['markers'][$key]['icon']['content'] = $this->uxIconRenderer->render($marker['icon']['content']); | |
$attrs['markers'][$key]['icon']['type'] = 'inline-svg'; | |
} | |
if (UxIcon::TYPE === ($marker['icon']['type'] ?? null)) { | |
if (!$this->uxIconRenderer) { | |
throw new ...; | |
} | |
$attrs['markers'][$key]['icon']['content'] = $this->uxIconRenderer->render($marker['icon']['content']); | |
$attrs['markers'][$key]['icon']['type'] = InlineSvg::TYPE; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and it requires to add TYPE
constants to InlineSvg, UxIcon, etc.. classes, we don't want to hardcode them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already throw a similar exception in UxIconRenderer, it might be redundant ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But so, $uxIconRenderer
property does not need to be nullable right?
Don't worry for the failing check on TwigComponent, that's not related |
3248cb5
to
704617a
Compare
704617a
to
dd20dbe
Compare
b4a6a8f
to
311689c
Compare
PR's description updated |
I reworked many minor things (see commits), here is what the following code renders: $map = (new Map())
->center(new Point(48.8566, 2.3522))
->zoom(6)
;
$cities = require_once __DIR__.'/../../config/cities.php';
foreach (array_slice($cities, 0, 500) as $i => $city) {
$map->addMarker(new Marker(
position: new Point($city['latitude'], $city['longitude']),
title: $city['label'],
icon: match(true) {
$i < 150 => Icon::ux('fa:map-marker'),
$i < 325 => Icon::url('https://cdn.jsdelivr.net/npm/[email protected]/icons/geo-alt.svg'),
default => Icon::svg(file_get_contents(__DIR__.'/../../assets/icons/el/map-marker.svg')),
}
));
} I will merge tomorrow I think |
Great job @Kocal ! Thanks for this final touch :) |
…d HTML, and icons rendering
b0c8144
to
3ee6627
Compare
3ee6627
to
c4f9828
Compare
Thank you @sblondeau. |
A nicely asked feature, adding Marker icon customization, it can be an UX Icon, an URL, or a SVG content:
Rendering