-
-
Notifications
You must be signed in to change notification settings - Fork 361
Add color to marker #2770
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
Comments
You can, by passing your own icon / svg, either directly in the good color, or you can add a tiny bit of CSS |
Is it not a way easy like this ? |
In a loop it would be nice to be able to assign a different color per entity, I tried to change the code a little, without success, can you help me? Thank you In the Icon.php file I add some params:
Without success... |
Would you like to work on a PR ? |
Euh what is PR ? Edit: I don't think I have the skill to do this, but I'd like to try :) |
A Pull Request.. meaning you try to code this (we can assist --when we have time 😅 ) and we then integrate the feature for everyone ? You could, to start, look at the documentation: https://symfony.com/doc/current/contributing/code/pull_requests.html and/or this great tutorial from symfonycast : https://symfonycasts.com/screencast/contributing/submitting-pr |
Sorry I don't know how to do PR, but I write code with a little bit of IA... //vendor/symfony/ux-leaflet-map/assets/dist/map_controller.fs And... * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\UX\Map\Icon; use Symfony\UX\Map\Exception\InvalidArgumentException; /** * Represents an icon that can be displayed on a map marker. * * @author Sylvain Blondeau * @author Hugo Alliaume */ abstract class Icon { /** * Creates a new icon based on a URL (e.g.: `https://cdn.jsdelivr.net/npm/[email protected]/icons/geo-alt.svg`). * * @param non-empty-string $url */ public static function url(string $url): UrlIcon { return new UrlIcon($url); } /** * Creates a new icon based on an SVG string (e.g.: `...`). * Using an SVG string may not be the best option if you want to customize the icon afterward, * it would be preferable to use {@see Icon::ux()} or {@see Icon::url()} instead. * * @param non-empty-string $html */ public static function svg(string $html): SvgIcon { return new SvgIcon($html); } /** * Creates a new icon based on a UX icon name (e.g.: `fa:map-marker`). * * @param non-empty-string $name */ public static function ux(string $name): UxIcon { return new UxIcon($name); } /** * @param positive-int $width * @param positive-int $height */ protected function __construct( protected IconType $type, protected int $width = 24, protected int $height = 24, protected ?string $color = null, // Nouvelle propriété pour la couleur ) { } /** * Sets the width of the icon. * * @param positive-int $width */ public function width(int $width): static { $this->width = $width; return $this; } /** * Sets the height of the icon. * * @param positive-int $height */ public function height(int $height): static { $this->height = $height; return $this; } /** * Sets the color of the icon. * Note: This only has an effect on SvgIcon and UxIcon types when rendered client-side by the JavaScript controller. * The color should be a valid CSS color string (e.g., 'red', '#FF0000', 'rgb(255,0,0)'). * * @param non-empty-string $color */ public function color(string $color): static { $this->color = $color; return $this; } /** * @internal */ public function toArray(): array { return [ 'type' => $this->type->value, 'width' => $this->width, 'height' => $this->height, 'color' => $this->color, // Ajout de la couleur au tableau de sérialisation ]; } /** * @param array{ type: value-of, width: positive-int, height: positive-int, color?: string } * &(array{ url: non-empty-string } * |array{ html: non-empty-string } * |array{ name: non-empty-string }) $data * * @internal */ public static function fromArray(array $data): static { return match ($data['type']) { IconType::Url->value => UrlIcon::fromArray($data), IconType::Svg->value => SvgIcon::fromArray($data), IconType::UxIcon->value => UxIcon::fromArray($data), default => throw new InvalidArgumentException(\sprintf('Invalid icon type %s.', $data['type'])), }; } } - - - - - - - - - - - - - - - - - - - - - Work for me when I do: `$iconOfTechnician = Icon::ux('ri:taxi-wifi-fill')->width(24)->height(24)->color('#0029D2');` Now on a map, thanks to a foreach loop, each Entity has a different color, this works very well. If someone can try and make the pull request themselves... it might help others. Thank you. |
Hello,
Is it possible to change the color of a marker when using a Symfony UX icon?
Thank you.
The text was updated successfully, but these errors were encountered: