Skip to content

Commit

Permalink
fix lint and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sblondeau committed Nov 6, 2024
1 parent 67befe6 commit 23e5928
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 157 deletions.
5 changes: 4 additions & 1 deletion src/Map/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 2.22

- Add `Polyline` support

## 2.20

- Deprecate `render_map` Twig function (will be removed in 2.21). Use
Expand All @@ -10,7 +14,6 @@
- The importmap entry `@symfony/ux-map/abstract-map-controller` can be removed
from your importmap, it is no longer needed.
- Add `Polygon` support
- Add `Polyline` support

## 2.19

Expand Down
14 changes: 10 additions & 4 deletions src/Map/assets/dist/abstract_map_controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ export default abstract class<MapOptions, Map, MarkerOptions, Marker, InfoWindow
protected abstract doCreateMarker(definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>): Marker;
protected abstract doCreatePolygon(definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>): Polygon;
protected abstract doCreatePolyline(definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>): Polyline;
protected createInfoWindow({ definition, element, }: {
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'] | PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'] | PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
element: Marker | Polygon | Polyline;
protected abstract createInfoWindow(args: {
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
element: Marker;
} | {
definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'];
element: Polygon;
} | {
definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
element: Polyline;
}): InfoWindow;
protected abstract doCreateInfoWindow({ definition, element, }: {
protected abstract doCreateInfoWindow(args: {
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
element: Marker;
} | {
Expand Down
5 changes: 3 additions & 2 deletions src/Map/assets/dist/abstract_map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class default_1 extends Controller {
this.polylines = [];
}
connect() {
const { center, zoom, options, markers, polygons, fitBoundsToMarkers } = this.viewValue;
const { center, zoom, options, markers, polygons, polylines, fitBoundsToMarkers } = this.viewValue;
this.dispatchEvent('pre-connect', { options });
this.map = this.doCreateMap({ center, zoom, options });
markers.forEach((marker) => this.createMarker(marker));
Expand Down Expand Up @@ -47,7 +47,8 @@ class default_1 extends Controller {
this.polylines.push(polyline);
return polyline;
}
createInfoWindow({ definition, element, }) {
createInfoWindow(args) {
const { definition, element } = args;
this.dispatchEvent('info-window:before-create', { definition, element });
const infoWindow = this.doCreateInfoWindow({ definition, element });
this.dispatchEvent('info-window:after-create', { infoWindow, element });
Expand Down
59 changes: 32 additions & 27 deletions src/Map/assets/src/abstract_map_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default abstract class<
protected polylines: Array<Polyline> = [];

connect() {
const { center, zoom, options, markers, polygons, fitBoundsToMarkers } = this.viewValue;
const { center, zoom, options, markers, polygons, polylines, fitBoundsToMarkers } = this.viewValue;

Check failure on line 94 in src/Map/assets/src/abstract_map_controller.ts

View workflow job for this annotation

GitHub Actions / tests-js

Unhandled error

SyntaxError: Unexpected non-whitespace character after JSON at position 853 (line 1 column 854) ❯ object ../../../../../../../../../../../node_modules/.vite/deps/@hotwired_stimulus.js:2245:25 ❯ extended.get ../../../../../../../../../../../node_modules/.vite/deps/@hotwired_stimulus.js:2113:18 ❯ extended.connect ../../../../assets/src/abstract_map_controller.ts:94:97 ❯ extended.connect src/map_controller.ts:81:14

this.dispatchEvent('pre-connect', { options });

Expand Down Expand Up @@ -156,16 +156,22 @@ export default abstract class<
protected abstract doCreatePolygon(definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>): Polygon;
protected abstract doCreatePolyline(definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>): Polyline;

protected createInfoWindow({
definition,
element,
}: {
definition:
| MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow']
| PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow']
| PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
element: Marker | Polygon | Polyline;
}): InfoWindow {
protected abstract createInfoWindow(
args:
| {
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
element: Marker;
}
| {
definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'];
element: Polygon;
}
| {
definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
element: Polyline;
}
): InfoWindow {
const { definition, element } = args;
this.dispatchEvent('info-window:before-create', { definition, element });
const infoWindow = this.doCreateInfoWindow({ definition, element });
this.dispatchEvent('info-window:after-create', { infoWindow, element });
Expand All @@ -175,22 +181,21 @@ export default abstract class<
return infoWindow;
}

protected abstract doCreateInfoWindow({
definition,
element,
}:
| {
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
element: Marker;
}
| {
definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'];
element: Polygon;
}
| {
definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
element: Polyline;
}): InfoWindow;
protected abstract doCreateInfoWindow(
args:
| {
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
element: Marker;
}
| {
definition: PolygonDefinition<PolygonOptions, InfoWindowOptions>['infoWindow'];
element: Polygon;
}
| {
definition: PolylineDefinition<PolylineOptions, InfoWindowOptions>['infoWindow'];
element: Polyline;
}
): InfoWindow;

protected abstract doFitBoundsToMarkers(): void;

Expand Down
25 changes: 14 additions & 11 deletions src/Map/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,40 +130,43 @@ You can add markers to a map using the ``addMarker()`` method::
)
;

Add Polylines
~~~~~~~~~~~~~

You can add Polylines, which represents a path made by a series of `Point` instances
$myMap->addPolyline(new Polyline(
Add Polygons
~~~~~~~~~~~~

You can also add Polygons, which represents an area enclosed by a series of ``Point`` instances::

$myMap->addPolygon(new Polygon(
points: [
new Point(48.8566, 2.3522),
new Point(45.7640, 4.8357),
new Point(43.2965, 5.3698),
new Point(44.8378, -0.5792),
],
infoWindow: new InfoWindow(
content: 'A line passing through Paris, Lyon, Marseille, Bordeaux',
content: 'Paris, Lyon, Marseille, Bordeaux',
),
));

Add Polygons
~~~~~~~~~~~~

You can also add Polygons, which represents an area enclosed by a series of ``Point`` instances::
Add Polylines
~~~~~~~~~~~~~

$myMap->addPolygon(new Polygon(
You can add Polylines, which represents a path made by a series of `Point` instances
$myMap->addPolyline(new Polyline(
points: [
new Point(48.8566, 2.3522),
new Point(45.7640, 4.8357),
new Point(43.2965, 5.3698),
new Point(44.8378, -0.5792),
],
infoWindow: new InfoWindow(
content: 'Paris, Lyon, Marseille, Bordeaux',
content: 'A line passing through Paris, Lyon, Marseille, Bordeaux',
),
));


Render a map
------------

To render a map in your Twig template, use the ``ux_map`` Twig function, e.g.:

Expand Down
24 changes: 4 additions & 20 deletions src/Map/src/Bridge/Google/assets/dist/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let default_1$1 = class default_1 extends Controller {
this.polylines = [];
}
connect() {
const { center, zoom, options, markers, polygons, fitBoundsToMarkers } = this.viewValue;
const { center, zoom, options, markers, polygons, polylines, fitBoundsToMarkers } = this.viewValue;
this.dispatchEvent('pre-connect', { options });
this.map = this.doCreateMap({ center, zoom, options });
markers.forEach((marker) => this.createMarker(marker));
Expand Down Expand Up @@ -48,7 +48,8 @@ let default_1$1 = class default_1 extends Controller {
this.polylines.push(polyline);
return polyline;
}
createInfoWindow({ definition, element, }) {
createInfoWindow(args) {
const { definition, element } = args;
this.dispatchEvent('info-window:before-create', { definition, element });
const infoWindow = this.doCreateInfoWindow({ definition, element });
this.dispatchEvent('info-window:after-create', { infoWindow, element });
Expand Down Expand Up @@ -165,24 +166,7 @@ class default_1 extends default_1$1 {
infoWindow.open({ map: this.map, anchor: element });
}
}
else if (element instanceof google.maps.Polygon) {
element.addListener('click', (event) => {
if (definition.autoClose) {
this.closeInfoWindowsExcept(infoWindow);
}
infoWindow.setPosition(event.latLng);
infoWindow.open(this.map);
});
if (definition.opened) {
const bounds = new google.maps.LatLngBounds();
element.getPath().forEach((point) => {
bounds.extend(point);
});
infoWindow.setPosition(bounds.getCenter());
infoWindow.open({ map: this.map, anchor: element });
}
}
else if (element instanceof google.maps.Polyline) {
else if (element instanceof google.maps.Polygon || element instanceof google.maps.Polyline) {
element.addListener('click', (event) => {
if (definition.autoClose) {
this.closeInfoWindowsExcept(infoWindow);
Expand Down
19 changes: 1 addition & 18 deletions src/Map/src/Bridge/Google/assets/src/map_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,24 +210,7 @@ export default class extends AbstractMapController<
if (definition.opened) {
infoWindow.open({ map: this.map, anchor: element });
}
} else if (element instanceof google.maps.Polygon) {
element.addListener('click', (event: any) => {
if (definition.autoClose) {
this.closeInfoWindowsExcept(infoWindow);
}
infoWindow.setPosition(event.latLng);
infoWindow.open(this.map);
});

if (definition.opened) {
const bounds = new google.maps.LatLngBounds();
element.getPath().forEach((point: google.maps.LatLng) => {
bounds.extend(point);
});
infoWindow.setPosition(bounds.getCenter());
infoWindow.open({ map: this.map, anchor: element });
}
} else if (element instanceof google.maps.Polyline) {
} else if (element instanceof google.maps.Polygon || element instanceof google.maps.Polyline) {
element.addListener('click', (event: any) => {
if (definition.autoClose) {
this.closeInfoWindowsExcept(infoWindow);
Expand Down
Loading

0 comments on commit 23e5928

Please sign in to comment.