Skip to content

Commit b0c8144

Browse files
committed
[Map] Rework UxIconRenderer injection
1 parent 9976692 commit b0c8144

16 files changed

+122
-48
lines changed

src/Map/assets/src/abstract_map_controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type Icon = {
1616
| {
1717
type: typeof IconTypes.UxIcon;
1818
name: string;
19-
_generated_html: string,
19+
_generated_html: string;
2020
}
2121
| {
2222
type: typeof IconTypes.Url;
@@ -26,7 +26,7 @@ export type Icon = {
2626
type: typeof IconTypes.Svg;
2727
html: string;
2828
}
29-
);
29+
);
3030

3131
export type MarkerDefinition<MarkerOptions, InfoWindowOptions> = WithIdentifier<{
3232
position: Point;

src/Map/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"symfony/framework-bundle": "^6.4|^7.0",
4141
"symfony/phpunit-bridge": "^6.4|^7.0",
4242
"symfony/twig-bundle": "^6.4|^7.0",
43-
"symfony/ux-twig-component": "^2.18"
43+
"symfony/ux-twig-component": "^2.18",
44+
"symfony/ux-icons": "^2.18"
4445
},
4546
"conflict": {
4647
"symfony/ux-twig-component": "<2.21"

src/Map/config/services.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
->abstract()
4040
->args([
4141
service('stimulus.helper'),
42-
service('.ux_map.ux_icons.renderer')->nullOnInvalid(),
42+
service('.ux_map.ux_icons.renderer'),
4343
])
4444

4545
->set('ux_map.renderer_factory', Renderer::class)

src/Map/src/Bridge/Google/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"symfony/ux-map": "^2.19"
2222
},
2323
"require-dev": {
24-
"symfony/phpunit-bridge": "^6.4|^7.0"
24+
"symfony/phpunit-bridge": "^6.4|^7.0",
25+
"symfony/ux-icons": "^2.18"
2526
},
2627
"autoload": {
2728
"psr-4": { "Symfony\\UX\\Map\\Bridge\\Google\\": "src/" },

src/Map/src/Bridge/Google/src/Renderer/GoogleRenderer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
public function __construct(
3131
StimulusHelper $stimulusHelper,
32+
UxIconRenderer $uxIconRenderer,
3233
#[\SensitiveParameter]
3334
private string $apiKey,
3435
private ?string $id = null,
@@ -43,7 +44,6 @@ public function __construct(
4344
*/
4445
private array $libraries = [],
4546
private ?string $defaultMapId = null,
46-
?UxIconRenderer $uxIconRenderer = null,
4747
) {
4848
parent::__construct($stimulusHelper, $uxIconRenderer);
4949
}

src/Map/src/Bridge/Google/src/Renderer/GoogleRendererFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class GoogleRendererFactory extends AbstractRendererFactory implements Ren
2727
{
2828
public function __construct(
2929
StimulusHelper $stimulus,
30-
?UxIconRenderer $uxIconRenderer = null,
30+
UxIconRenderer $uxIconRenderer,
3131
private ?string $defaultMapId = null,
3232
) {
3333
parent::__construct($stimulus, $uxIconRenderer);
@@ -43,7 +43,8 @@ public function create(Dsn $dsn): RendererInterface
4343

4444
return new GoogleRenderer(
4545
$this->stimulus,
46-
$apiKey,
46+
$this->uxIconRenderer,
47+
apiKey: $apiKey,
4748
id: $dsn->getOption('id'),
4849
language: $dsn->getOption('language'),
4950
region: $dsn->getOption('region'),
@@ -53,7 +54,6 @@ public function create(Dsn $dsn): RendererInterface
5354
version: $dsn->getOption('version', 'weekly'),
5455
libraries: ['maps', 'marker', ...$dsn->getOption('libraries', [])],
5556
defaultMapId: $this->defaultMapId,
56-
uxIconRenderer: $this->uxIconRenderer,
5757
);
5858
}
5959

src/Map/src/Bridge/Google/tests/GoogleRendererFactoryTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\UX\Map\Bridge\Google\Tests;
1313

1414
use Symfony\UX\Map\Bridge\Google\Renderer\GoogleRendererFactory;
15+
use Symfony\UX\Map\Icon\UxIconRenderer;
1516
use Symfony\UX\Map\Renderer\RendererFactoryInterface;
1617
use Symfony\UX\Map\Test\RendererFactoryTestCase;
1718
use Symfony\UX\StimulusBundle\Helper\StimulusHelper;
@@ -20,7 +21,7 @@ final class GoogleRendererFactoryTest extends RendererFactoryTestCase
2021
{
2122
public function createRendererFactory(): RendererFactoryInterface
2223
{
23-
return new GoogleRendererFactory(new StimulusHelper(null));
24+
return new GoogleRendererFactory(new StimulusHelper(null), new UxIconRenderer(null));
2425
}
2526

2627
public static function supportsRenderer(): iterable

src/Map/src/Bridge/Google/tests/GoogleRendererTest.php

+42-18
Large diffs are not rendered by default.

src/Map/src/Bridge/Leaflet/assets/dist/map_controller.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,25 @@ class map_controller extends default_1 {
209209
const { type, width, height } = definition;
210210
let icon;
211211
if (type === IconTypes.Svg) {
212-
icon = L.divIcon({ html: definition.html, iconSize: [width, height], className: '' });
212+
icon = L.divIcon({
213+
html: definition.html,
214+
iconSize: [width, height],
215+
className: '',
216+
});
213217
}
214218
else if (type === IconTypes.UxIcon) {
215-
icon = L.divIcon({ html: definition._generated_html, iconSize: [width, height], className: '' });
219+
icon = L.divIcon({
220+
html: definition._generated_html,
221+
iconSize: [width, height],
222+
className: '',
223+
});
216224
}
217225
else if (type === IconTypes.Url) {
218-
icon = L.icon({ iconUrl: definition.url, iconSize: [width, height], className: '' });
226+
icon = L.icon({
227+
iconUrl: definition.url,
228+
iconSize: [width, height],
229+
className: '',
230+
});
219231
}
220232
else {
221233
throw new Error(`Unsupported icon type: ${type}.`);

src/Map/src/Bridge/Leaflet/assets/src/map_controller.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class extends AbstractMapController<
4242
iconSize: [25, 41],
4343
iconAnchor: [12.5, 41],
4444
popupAnchor: [0, -41],
45-
className: '',
45+
className: '', // Adding an empty class to the icon to avoid the default Leaflet styles
4646
});
4747

4848
super.connect();
@@ -189,11 +189,23 @@ export default class extends AbstractMapController<
189189

190190
let icon: L.DivIcon | L.Icon;
191191
if (type === IconTypes.Svg) {
192-
icon = L.divIcon({ html: definition.html, iconSize: [width, height], className: '' });
192+
icon = L.divIcon({
193+
html: definition.html,
194+
iconSize: [width, height],
195+
className: '', // Adding an empty class to the icon to avoid the default Leaflet styles
196+
});
193197
} else if (type === IconTypes.UxIcon) {
194-
icon = L.divIcon({ html: definition._generated_html, iconSize: [width, height], className: '' });
198+
icon = L.divIcon({
199+
html: definition._generated_html,
200+
iconSize: [width, height],
201+
className: '', // Adding an empty class to the icon to avoid the default Leaflet styles
202+
});
195203
} else if (type === IconTypes.Url) {
196-
icon = L.icon({ iconUrl: definition.url, iconSize: [width, height], className: '' });
204+
icon = L.icon({
205+
iconUrl: definition.url,
206+
iconSize: [width, height],
207+
className: '', // Adding an empty class to the icon to avoid the default Leaflet styles
208+
});
197209
} else {
198210
throw new Error(`Unsupported icon type: ${type}.`);
199211
}

src/Map/src/Bridge/Leaflet/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"symfony/ux-map": "^2.19"
2222
},
2323
"require-dev": {
24-
"symfony/phpunit-bridge": "^6.4|^7.0"
24+
"symfony/phpunit-bridge": "^6.4|^7.0",
25+
"symfony/ux-icons": "^2.18"
2526
},
2627
"autoload": {
2728
"psr-4": { "Symfony\\UX\\Map\\Bridge\\Leaflet\\": "src/" },

src/Map/src/Bridge/Leaflet/tests/LeafletRendererFactoryTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\UX\Map\Bridge\Leaflet\Tests;
1313

1414
use Symfony\UX\Map\Bridge\Leaflet\Renderer\LeafletRendererFactory;
15+
use Symfony\UX\Map\Icon\UxIconRenderer;
1516
use Symfony\UX\Map\Renderer\RendererFactoryInterface;
1617
use Symfony\UX\Map\Test\RendererFactoryTestCase;
1718
use Symfony\UX\StimulusBundle\Helper\StimulusHelper;
@@ -20,7 +21,7 @@ final class LeafletRendererFactoryTest extends RendererFactoryTestCase
2021
{
2122
public function createRendererFactory(): RendererFactoryInterface
2223
{
23-
return new LeafletRendererFactory(new StimulusHelper(null));
24+
return new LeafletRendererFactory(new StimulusHelper(null), new UxIconRenderer(null));
2425
}
2526

2627
public static function supportsRenderer(): iterable

0 commit comments

Comments
 (0)