Skip to content

Commit 09be8b1

Browse files
committed
[Map] Replace LatLng by Point
1 parent 774ce08 commit 09be8b1

20 files changed

+64
-68
lines changed

src/Map/assets/dist/abstract_map_controller.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import { Controller } from '@hotwired/stimulus';
2-
export type LatLng = {
2+
export type Point = {
33
lat: number;
44
lng: number;
55
};
66
export type MapView<Options, MarkerOptions, InfoWindowOptions> = {
7-
center: LatLng;
7+
center: Point;
88
zoom: number;
99
fitBoundsToMarkers: boolean;
1010
markers: Array<MarkerDefinition<MarkerOptions, InfoWindowOptions>>;
1111
options: Options;
1212
};
1313
export type MarkerDefinition<MarkerOptions, InfoWindowOptions> = {
14-
position: LatLng;
14+
position: Point;
1515
title: string | null;
1616
infoWindow?: Omit<InfoWindowDefinition<InfoWindowOptions>, 'position'>;
1717
rawOptions?: MarkerOptions;
1818
};
1919
export type InfoWindowDefinition<InfoWindowOptions> = {
2020
headerContent: string | null;
2121
content: string | null;
22-
position: LatLng;
22+
position: Point;
2323
opened: boolean;
2424
autoClose: boolean;
2525
rawOptions?: InfoWindowOptions;
@@ -36,7 +36,7 @@ export default abstract class<MapOptions, Map, MarkerOptions, Marker, InfoWindow
3636
initialize(): void;
3737
connect(): void;
3838
protected abstract doCreateMap({ center, zoom, options, }: {
39-
center: LatLng;
39+
center: Point;
4040
zoom: number;
4141
options: MapOptions;
4242
}): Map;

src/Map/assets/src/abstract_map_controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { Controller } from '@hotwired/stimulus';
22

3-
export type LatLng = { lat: number; lng: number };
3+
export type Point = { lat: number; lng: number };
44

55
export type MapView<Options, MarkerOptions, InfoWindowOptions> = {
6-
center: LatLng;
6+
center: Point;
77
zoom: number;
88
fitBoundsToMarkers: boolean;
99
markers: Array<MarkerDefinition<MarkerOptions, InfoWindowOptions>>;
1010
options: Options;
1111
};
1212

1313
export type MarkerDefinition<MarkerOptions, InfoWindowOptions> = {
14-
position: LatLng;
14+
position: Point;
1515
title: string | null;
1616
infoWindow?: Omit<InfoWindowDefinition<InfoWindowOptions>, 'position'>;
1717
rawOptions?: MarkerOptions;
@@ -20,7 +20,7 @@ export type MarkerDefinition<MarkerOptions, InfoWindowOptions> = {
2020
export type InfoWindowDefinition<InfoWindowOptions> = {
2121
headerContent: string | null;
2222
content: string | null;
23-
position: LatLng;
23+
position: Point;
2424
opened: boolean;
2525
autoClose: boolean;
2626
rawOptions?: InfoWindowOptions;
@@ -72,7 +72,7 @@ export default abstract class<
7272
zoom,
7373
options,
7474
}: {
75-
center: LatLng;
75+
center: Point;
7676
zoom: number;
7777
options: MapOptions;
7878
}): Map;

src/Map/doc/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ A map is created by calling ``new Map()``. You can configure the center, zoom, a
6767
use Symfony\Component\HttpFoundation\Response;
6868
use Symfony\Component\Routing\Attribute\Route;
6969
use Symfony\UX\Map\InfoWindow;
70-
use Symfony\UX\Map\LatLng;
7170
use Symfony\UX\Map\Map;
7271
use Symfony\UX\Map\Marker;
72+
use Symfony\UX\Map\Point;
7373
7474
final class HomeController extends AbstractController
7575
{
@@ -78,18 +78,18 @@ A map is created by calling ``new Map()``. You can configure the center, zoom, a
7878
{
7979
// 1. Create a new map instance
8080
$myMap = (new Map());
81-
->center(new LatLng(46.903354, 1.888334))
81+
->center(new Point(46.903354, 1.888334))
8282
->zoom(6)
8383
;
8484
8585
// 2. You can add markers, with an optional info window
8686
$myMap
8787
->addMarker(new Marker(
88-
position: new LatLng(48.8566, 2.3522),
88+
position: new Point(48.8566, 2.3522),
8989
title: 'Paris'
9090
))
9191
->addMarker(new Marker(
92-
position: new LatLng(45.7640, 4.8357),
92+
position: new Point(45.7640, 4.8357),
9393
title: 'Lyon',
9494
// With an info window
9595
infoWindow: new InfoWindow(

src/Map/src/Bridge/Google/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ use Symfony\UX\Map\Bridge\Google\Option\MapTypeControlOptions;
3737
use Symfony\UX\Map\Bridge\Google\Option\MapTypeControlStyle;
3838
use Symfony\UX\Map\Bridge\Google\Option\StreetViewControlOptions;
3939
use Symfony\UX\Map\Bridge\Google\Option\ZoomControlOptions;
40-
use Symfony\UX\Map\LatLng;
40+
use Symfony\UX\Map\Point;
4141
use Symfony\UX\Map\Map;
4242

4343
$map = (new Map())
44-
->center(new LatLng(48.8566, 2.3522))
44+
->center(new Point(48.8566, 2.3522))
4545
->zoom(6);
4646

4747
// To configure controls options, and some other options:

src/Map/src/Bridge/Google/assets/dist/map_controller.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="google.maps" />
22
import AbstractMapController from '@symfony/ux-map/abstract-map-controller';
3-
import type { LatLng, MarkerDefinition } from '@symfony/ux-map/abstract-map-controller';
3+
import type { Point, MarkerDefinition } from '@symfony/ux-map/abstract-map-controller';
44
import type { LoaderOptions } from '@googlemaps/js-api-loader';
55
type MapOptions = Pick<google.maps.MapOptions, 'mapId' | 'gestureHandling' | 'backgroundColor' | 'disableDoubleClickZoom' | 'zoomControl' | 'zoomControlOptions' | 'mapTypeControl' | 'mapTypeControlOptions' | 'streetViewControl' | 'streetViewControlOptions' | 'fullscreenControl' | 'fullscreenControlOptions'>;
66
export default class extends AbstractMapController<MapOptions, google.maps.Map, google.maps.marker.AdvancedMarkerElement, google.maps.InfoWindow> {
@@ -10,7 +10,7 @@ export default class extends AbstractMapController<MapOptions, google.maps.Map,
1010
providerOptionsValue: Pick<LoaderOptions, 'apiKey' | 'id' | 'language' | 'region' | 'nonce' | 'retries' | 'url' | 'version'>;
1111
connect(): Promise<void>;
1212
protected doCreateMap({ center, zoom, options, }: {
13-
center: LatLng;
13+
center: Point;
1414
zoom: number;
1515
options: MapOptions;
1616
}): google.maps.Map;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import AbstractMapController from '@symfony/ux-map/abstract-map-controller';
11-
import type { LatLng, MarkerDefinition } from '@symfony/ux-map/abstract-map-controller';
11+
import type { Point, MarkerDefinition } from '@symfony/ux-map/abstract-map-controller';
1212
import type { LoaderOptions } from '@googlemaps/js-api-loader';
1313
import { Loader } from '@googlemaps/js-api-loader';
1414

@@ -67,7 +67,7 @@ export default class extends AbstractMapController<
6767
zoom,
6868
options,
6969
}: {
70-
center: LatLng;
70+
center: Point;
7171
zoom: number;
7272
options: MapOptions;
7373
}): google.maps.Map {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use Symfony\UX\Map\Bridge\Google\GoogleOptions;
1515
use Symfony\UX\Map\Bridge\Google\Renderer\GoogleRenderer;
1616
use Symfony\UX\Map\InfoWindow;
17-
use Symfony\UX\Map\LatLng;
1817
use Symfony\UX\Map\Map;
1918
use Symfony\UX\Map\Marker;
19+
use Symfony\UX\Map\Point;
2020
use Symfony\UX\Map\Test\RendererTestCase;
2121
use Symfony\UX\StimulusBundle\Helper\StimulusHelper;
2222

@@ -25,7 +25,7 @@ class GoogleRendererTest extends RendererTestCase
2525
public function provideTestRenderMap(): iterable
2626
{
2727
$map = (new Map())
28-
->center(new LatLng(48.8566, 2.3522))
28+
->center(new Point(48.8566, 2.3522))
2929
->zoom(12);
3030

3131
yield 'simple map, with minimum options' => [
@@ -44,8 +44,8 @@ public function provideTestRenderMap(): iterable
4444
'expected_render' => '<div data-controller="symfony--ux-map-google--map" data-symfony--ux-map-google--map-provider-options-value="&#x7B;&quot;apiKey&quot;&#x3A;&quot;api_key&quot;&#x7D;" data-symfony--ux-map-google--map-view-value="&#x7B;&quot;center&quot;&#x3A;&#x7B;&quot;lat&quot;&#x3A;48.8566,&quot;lng&quot;&#x3A;2.3522&#x7D;,&quot;zoom&quot;&#x3A;12,&quot;fitBoundsToMarkers&quot;&#x3A;false,&quot;options&quot;&#x3A;&#x7B;&quot;mapId&quot;&#x3A;null,&quot;gestureHandling&quot;&#x3A;&quot;auto&quot;,&quot;backgroundColor&quot;&#x3A;null,&quot;disableDoubleClickZoom&quot;&#x3A;false,&quot;zoomControlOptions&quot;&#x3A;&#x7B;&quot;position&quot;&#x3A;22&#x7D;,&quot;mapTypeControlOptions&quot;&#x3A;&#x7B;&quot;mapTypeIds&quot;&#x3A;&#x5B;&#x5D;,&quot;position&quot;&#x3A;14,&quot;style&quot;&#x3A;0&#x7D;,&quot;streetViewControlOptions&quot;&#x3A;&#x7B;&quot;position&quot;&#x3A;22&#x7D;,&quot;fullscreenControlOptions&quot;&#x3A;&#x7B;&quot;position&quot;&#x3A;20&#x7D;&#x7D;,&quot;markers&quot;&#x3A;&#x5B;&#x7B;&quot;position&quot;&#x3A;&#x7B;&quot;lat&quot;&#x3A;48.8566,&quot;lng&quot;&#x3A;2.3522&#x7D;,&quot;title&quot;&#x3A;&quot;Paris&quot;,&quot;infoWindow&quot;&#x3A;null&#x7D;,&#x7B;&quot;position&quot;&#x3A;&#x7B;&quot;lat&quot;&#x3A;48.8566,&quot;lng&quot;&#x3A;2.3522&#x7D;,&quot;title&quot;&#x3A;&quot;Lyon&quot;,&quot;infoWindow&quot;&#x3A;&#x7B;&quot;headerContent&quot;&#x3A;null,&quot;content&quot;&#x3A;&quot;Lyon&quot;,&quot;position&quot;&#x3A;null,&quot;opened&quot;&#x3A;false,&quot;autoClose&quot;&#x3A;true&#x7D;&#x7D;&#x5D;&#x7D;"></div>',
4545
'renderer' => new GoogleRenderer(new StimulusHelper(null), apiKey: 'api_key'),
4646
'map' => (clone $map)
47-
->addMarker(new Marker(new LatLng(48.8566, 2.3522), 'Paris'))
48-
->addMarker(new Marker(new LatLng(48.8566, 2.3522), 'Lyon', infoWindow: new InfoWindow(content: 'Lyon'))),
47+
->addMarker(new Marker(new Point(48.8566, 2.3522), 'Paris'))
48+
->addMarker(new Marker(new Point(48.8566, 2.3522), 'Lyon', infoWindow: new InfoWindow(content: 'Lyon'))),
4949
];
5050

5151
yield 'with controls enabled' => [

src/Map/src/Bridge/Leaflet/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ You can use the `LeafletOptions` class to configure your `Map`::
1515
```php
1616
use Symfony\UX\Map\Bridge\Leaflet\LeafletOptions;
1717
use Symfony\UX\Map\Bridge\Leaflet\Option\TileLayer;
18-
use Symfony\UX\Map\LatLng;
18+
use Symfony\UX\Map\Point;
1919
use Symfony\UX\Map\Map;
2020

2121
$map = (new Map())
22-
->center(new LatLng(48.8566, 2.3522))
22+
->center(new Point(48.8566, 2.3522))
2323
->zoom(6);
2424

2525
$leafletOptions = (new LeafletOptions())

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import AbstractMapController from '@symfony/ux-map/abstract-map-controller';
2-
import type { LatLng, MarkerDefinition } from '@symfony/ux-map/abstract-map-controller';
2+
import type { Point, MarkerDefinition } from '@symfony/ux-map/abstract-map-controller';
33
import 'leaflet/dist/leaflet.min.css';
44
import { type Map as LeafletMap, Marker, type Popup } from 'leaflet';
55
import type { MapOptions as LeafletMapOptions, MarkerOptions, PopupOptions } from 'leaflet';
@@ -12,8 +12,8 @@ type MapOptions = Pick<LeafletMapOptions, 'center' | 'zoom'> & {
1212
};
1313
export default class extends AbstractMapController<MapOptions, typeof LeafletMap, MarkerOptions, Marker, Popup, PopupOptions> {
1414
connect(): void;
15-
protected doCreateMap({ center, zoom, options, }: {
16-
center: LatLng;
15+
protected doCreateMap({ center, zoom, options }: {
16+
center: Point;
1717
zoom: number;
1818
options: MapOptions;
1919
}): LeafletMap;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class map_controller extends AbstractMapController {
1313
});
1414
super.connect();
1515
}
16-
doCreateMap({ center, zoom, options, }) {
16+
doCreateMap({ center, zoom, options }) {
1717
const map$1 = map(this.element, {
1818
...options,
1919
center,

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import AbstractMapController from '@symfony/ux-map/abstract-map-controller';
2-
import type { LatLng, MarkerDefinition } from '@symfony/ux-map/abstract-map-controller';
2+
import type { Point, MarkerDefinition } from '@symfony/ux-map/abstract-map-controller';
33
import 'leaflet/dist/leaflet.min.css';
44
import {
55
map as createMap,
@@ -35,11 +35,7 @@ export default class extends AbstractMapController<
3535
super.connect();
3636
}
3737

38-
protected doCreateMap({
39-
center,
40-
zoom,
41-
options,
42-
}: { center: LatLng; zoom: number; options: MapOptions }): LeafletMap {
38+
protected doCreateMap({ center, zoom, options }: { center: Point; zoom: number; options: MapOptions }): LeafletMap {
4339
const map = createMap(this.element, {
4440
...options,
4541
center,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
use Symfony\UX\Map\Bridge\Leaflet\Renderer\LeafletRenderer;
1515
use Symfony\UX\Map\InfoWindow;
16-
use Symfony\UX\Map\LatLng;
1716
use Symfony\UX\Map\Map;
1817
use Symfony\UX\Map\Marker;
18+
use Symfony\UX\Map\Point;
1919
use Symfony\UX\Map\Test\RendererTestCase;
2020
use Symfony\UX\StimulusBundle\Helper\StimulusHelper;
2121

@@ -24,7 +24,7 @@ class LeafletRendererTest extends RendererTestCase
2424
public function provideTestRenderMap(): iterable
2525
{
2626
$map = (new Map())
27-
->center(new LatLng(48.8566, 2.3522))
27+
->center(new Point(48.8566, 2.3522))
2828
->zoom(12);
2929

3030
yield 'simple map' => [
@@ -37,8 +37,8 @@ public function provideTestRenderMap(): iterable
3737
'expected_render' => '<div data-controller="symfony--ux-map-leaflet--map" data-symfony--ux-map-leaflet--map-provider-options-value="&#x7B;&#x7D;" data-symfony--ux-map-leaflet--map-view-value="&#x7B;&quot;center&quot;&#x3A;&#x7B;&quot;lat&quot;&#x3A;48.8566,&quot;lng&quot;&#x3A;2.3522&#x7D;,&quot;zoom&quot;&#x3A;12,&quot;fitBoundsToMarkers&quot;&#x3A;false,&quot;options&quot;&#x3A;&#x7B;&quot;tileLayer&quot;&#x3A;&#x7B;&quot;url&quot;&#x3A;&quot;https&#x3A;&#x5C;&#x2F;&#x5C;&#x2F;tile.openstreetmap.org&#x5C;&#x2F;&#x7B;z&#x7D;&#x5C;&#x2F;&#x7B;x&#x7D;&#x5C;&#x2F;&#x7B;y&#x7D;.png&quot;,&quot;attribution&quot;&#x3A;&quot;&#x5C;u00a9&#x20;&lt;a&#x20;href&#x3D;&#x5C;&quot;https&#x3A;&#x5C;&#x2F;&#x5C;&#x2F;www.openstreetmap.org&#x5C;&#x2F;copyright&#x5C;&quot;&gt;OpenStreetMap&lt;&#x5C;&#x2F;a&gt;&quot;,&quot;options&quot;&#x3A;&#x7B;&#x7D;&#x7D;&#x7D;,&quot;markers&quot;&#x3A;&#x5B;&#x7B;&quot;position&quot;&#x3A;&#x7B;&quot;lat&quot;&#x3A;48.8566,&quot;lng&quot;&#x3A;2.3522&#x7D;,&quot;title&quot;&#x3A;&quot;Paris&quot;,&quot;infoWindow&quot;&#x3A;null&#x7D;,&#x7B;&quot;position&quot;&#x3A;&#x7B;&quot;lat&quot;&#x3A;48.8566,&quot;lng&quot;&#x3A;2.3522&#x7D;,&quot;title&quot;&#x3A;&quot;Lyon&quot;,&quot;infoWindow&quot;&#x3A;&#x7B;&quot;headerContent&quot;&#x3A;null,&quot;content&quot;&#x3A;&quot;Lyon&quot;,&quot;position&quot;&#x3A;null,&quot;opened&quot;&#x3A;false,&quot;autoClose&quot;&#x3A;true&#x7D;&#x7D;&#x5D;&#x7D;"></div>',
3838
'renderer' => new LeafletRenderer(new StimulusHelper(null)),
3939
'map' => (clone $map)
40-
->addMarker(new Marker(new LatLng(48.8566, 2.3522), 'Paris'))
41-
->addMarker(new Marker(new LatLng(48.8566, 2.3522), 'Lyon', infoWindow: new InfoWindow(content: 'Lyon'))),
40+
->addMarker(new Marker(new Point(48.8566, 2.3522), 'Paris'))
41+
->addMarker(new Marker(new Point(48.8566, 2.3522), 'Lyon', infoWindow: new InfoWindow(content: 'Lyon'))),
4242
];
4343
}
4444
}

src/Map/src/InfoWindow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
public function __construct(
2222
private ?string $headerContent = null,
2323
private ?string $content = null,
24-
private ?LatLng $position = null,
24+
private ?Point $position = null,
2525
private bool $opened = false,
2626
private bool $autoClose = true,
2727
) {

src/Map/src/Map.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class Map
2323
public function __construct(
2424
private readonly ?string $rendererName = null,
2525
private ?MapOptionsInterface $options = null,
26-
private ?LatLng $center = null,
26+
private ?Point $center = null,
2727
private ?float $zoom = null,
2828
private bool $fitBoundsToMarkers = false,
2929
/**
@@ -38,7 +38,7 @@ public function getRendererName(): ?string
3838
return $this->rendererName;
3939
}
4040

41-
public function center(LatLng $center): self
41+
public function center(Point $center): self
4242
{
4343
$this->center = $center;
4444

src/Map/src/Marker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
final readonly class Marker
2020
{
2121
public function __construct(
22-
private LatLng $position,
22+
private Point $position,
2323
private ?string $title = null,
2424
private ?InfoWindow $infoWindow = null,
2525
) {

src/Map/src/LatLng.php renamed to src/Map/src/Point.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Hugo Alliaume <hugo@alliau.me>
2020
*/
21-
final readonly class LatLng
21+
final readonly class Point
2222
{
2323
public function __construct(
2424
public float $latitude,

src/Map/tests/InfoWindowTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\UX\Map\InfoWindow;
16-
use Symfony\UX\Map\LatLng;
16+
use Symfony\UX\Map\Point;
1717

1818
class InfoWindowTest extends TestCase
1919
{
@@ -22,7 +22,7 @@ public function testToArray(): void
2222
$infoWindow = new InfoWindow(
2323
headerContent: 'Paris',
2424
content: 'Capitale de la France, est une grande ville européenne et un centre mondial de l\'art, de la mode, de la gastronomie et de la culture.',
25-
position: new LatLng(48.8566, 2.3522),
25+
position: new Point(48.8566, 2.3522),
2626
opened: true,
2727
autoClose: false,
2828
);

0 commit comments

Comments
 (0)