Skip to content

Commit 4e092e3

Browse files
committed
run yarn workspace
fix: js tests
1 parent 7e05add commit 4e092e3

File tree

6 files changed

+188
-8
lines changed

6 files changed

+188
-8
lines changed

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

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,68 @@
1-
import AbstractMapController from '@symfony/ux-map';
1+
import { Controller } from '@hotwired/stimulus';
22
import { Loader } from '@googlemaps/js-api-loader';
33

4+
let default_1$1 = class default_1 extends Controller {
5+
constructor() {
6+
super(...arguments);
7+
this.markers = [];
8+
this.infoWindows = [];
9+
this.polygons = [];
10+
this.polylines = [];
11+
}
12+
connect() {
13+
const { center, zoom, options, markers, polygons, polylines, fitBoundsToMarkers } = this.viewValue;
14+
this.dispatchEvent('pre-connect', { options });
15+
this.map = this.doCreateMap({ center, zoom, options });
16+
markers.forEach((marker) => this.createMarker(marker));
17+
polygons.forEach((polygon) => this.createPolygon(polygon));
18+
polylines.forEach((polyline) => this.createPolyline(polyline));
19+
if (fitBoundsToMarkers) {
20+
this.doFitBoundsToMarkers();
21+
}
22+
this.dispatchEvent('connect', {
23+
map: this.map,
24+
markers: this.markers,
25+
polygons: this.polygons,
26+
polylines: this.polylines,
27+
infoWindows: this.infoWindows,
28+
});
29+
}
30+
createMarker(definition) {
31+
this.dispatchEvent('marker:before-create', { definition });
32+
const marker = this.doCreateMarker(definition);
33+
this.dispatchEvent('marker:after-create', { marker });
34+
this.markers.push(marker);
35+
return marker;
36+
}
37+
createPolygon(definition) {
38+
this.dispatchEvent('polygon:before-create', { definition });
39+
const polygon = this.doCreatePolygon(definition);
40+
this.dispatchEvent('polygon:after-create', { polygon });
41+
this.polygons.push(polygon);
42+
return polygon;
43+
}
44+
createPolyline(definition) {
45+
this.dispatchEvent('polyline:before-create', { definition });
46+
const polyline = this.doCreatePolyline(definition);
47+
this.dispatchEvent('polyline:after-create', { polyline });
48+
this.polylines.push(polyline);
49+
return polyline;
50+
}
51+
createInfoWindow({ definition, element, }) {
52+
this.dispatchEvent('info-window:before-create', { definition, element });
53+
const infoWindow = this.doCreateInfoWindow({ definition, element });
54+
this.dispatchEvent('info-window:after-create', { infoWindow, element });
55+
this.infoWindows.push(infoWindow);
56+
return infoWindow;
57+
}
58+
};
59+
default_1$1.values = {
60+
providerOptions: Object,
61+
view: Object,
62+
};
63+
464
let _google;
5-
class default_1 extends AbstractMapController {
65+
class default_1 extends default_1$1 {
666
async connect() {
767
if (!_google) {
868
_google = { maps: {} };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('GoogleMapsController', () => {
4141
data-controller="check google"
4242
style="height: 700px&#x3B; margin: 10px"
4343
data-google-provider-options-value="{"version":"weekly","libraries":["maps","marker"],"apiKey":""}"
44-
data-google-view-value="{"center":{"lat":48.8566,"lng":2.3522},"zoom":4,"fitBoundsToMarkers":true,"options":{"mapId":"YOUR_MAP_ID","gestureHandling":"auto","backgroundColor":null,"disableDoubleClickZoom":false,"zoomControl":true,"zoomControlOptions":{"position":22},"mapTypeControl":true,"mapTypeControlOptions":{"mapTypeIds":[],"position":14,"style":0},"streetViewControl":true,"streetViewControlOptions":{"position":22},"fullscreenControl":true,"fullscreenControlOptions":{"position":20}},"markers":[{"position":{"lat":48.8566,"lng":2.3522},"title":"Paris","infoWindow":null},{"position":{"lat":45.764,"lng":4.8357},"title":"Lyon","infoWindow":{"headerContent":"<b>Lyon<\/b>","content":"The French town in the historic Rh\u00f4ne-Alpes region, located at the junction of the Rh\u00f4ne and Sa\u00f4ne rivers.","position":null,"opened":false,"autoClose":true}}],"polygons":[]}polylines":[]}"
44+
data-google-view-value="{"center":{"lat":48.8566,"lng":2.3522},"zoom":4,"fitBoundsToMarkers":true,"options":{"mapId":"YOUR_MAP_ID","gestureHandling":"auto","backgroundColor":null,"disableDoubleClickZoom":false,"zoomControl":true,"zoomControlOptions":{"position":22},"mapTypeControl":true,"mapTypeControlOptions":{"mapTypeIds":[],"position":14,"style":0},"streetViewControl":true,"streetViewControlOptions":{"position":22},"fullscreenControl":true,"fullscreenControlOptions":{"position":20}},"markers":[{"position":{"lat":48.8566,"lng":2.3522},"title":"Paris","infoWindow":null},{"position":{"lat":45.764,"lng":4.8357},"title":"Lyon","infoWindow":{"headerContent":"<b>Lyon<\/b>","content":"The French town in the historic Rh\u00f4ne-Alpes region, located at the junction of the Rh\u00f4ne and Sa\u00f4ne rivers.","position":null,"opened":false,"autoClose":true}}],"polygons":[]},"polylines":[]}"
4545
></div>
4646
`);
4747
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import AbstractMapController from '@symfony/ux-map';
2+
import type { Point, MarkerDefinition, PolygonDefinition, PolylineDefinition } from '@symfony/ux-map';
3+
import 'leaflet/dist/leaflet.min.css';
4+
import * as L from 'leaflet';
5+
import type { MapOptions as LeafletMapOptions, MarkerOptions, PopupOptions, PolygonOptions, PolylineOptions } from 'leaflet';
6+
type MapOptions = Pick<LeafletMapOptions, 'center' | 'zoom'> & {
7+
tileLayer: {
8+
url: string;
9+
attribution: string;
10+
options: Record<string, unknown>;
11+
};
12+
};
13+
export default class extends AbstractMapController<MapOptions, typeof L.Map, MarkerOptions, typeof L.Marker, PopupOptions, typeof L.Popup, PolygonOptions, typeof L.Polygon, PolylineOptions, typeof L.Polyline> {
14+
connect(): void;
15+
protected dispatchEvent(name: string, payload?: Record<string, unknown>): void;
16+
protected doCreateMap({ center, zoom, options, }: {
17+
center: Point | null;
18+
zoom: number | null;
19+
options: MapOptions;
20+
}): L.Map;
21+
protected doCreateMarker(definition: MarkerDefinition): L.Marker;
22+
protected doCreatePolygon(definition: PolygonDefinition): L.Polygon;
23+
protected doCreatePolyline(definition: PolylineDefinition): L.Polyline;
24+
protected doCreateInfoWindow({ definition, element, }: {
25+
definition: MarkerDefinition['infoWindow'] | PolygonDefinition['infoWindow'] | PolylineDefinition['infoWindow'];
26+
element: L.Marker | L.Polygon | L.Polyline;
27+
}): L.Popup;
28+
protected doFitBoundsToMarkers(): void;
29+
}
30+
export {};
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import AbstractMapController from '@symfony/ux-map';
2+
import 'leaflet/dist/leaflet.min.css';
3+
import * as L from 'leaflet';
4+
5+
class map_controller extends AbstractMapController {
6+
connect() {
7+
L.Marker.prototype.options.icon = L.divIcon({
8+
html: '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" fill-rule="evenodd" stroke-linecap="round" clip-rule="evenodd" viewBox="0 0 500 820"><defs><linearGradient id="__sf_ux_map_gradient_marker_fill" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -37.57 37.57 0 416.45 541)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#126FC6"/><stop offset="1" stop-color="#4C9CD1"/></linearGradient><linearGradient id="__sf_ux_map_gradient_marker_border" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -19.05 19.05 0 414.48 522.49)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2E6C97"/><stop offset="1" stop-color="#3883B7"/></linearGradient></defs><circle cx="252.31" cy="266.24" r="83.99" fill="#fff"/><path fill="url(#__sf_ux_map_gradient_marker_fill)" stroke="url(#__sf_ux_map_gradient_marker_border)" stroke-width="1.1" d="M416.54 503.61c-6.57 0-12.04 5.7-12.04 11.87 0 2.78 1.56 6.3 2.7 8.74l9.3 17.88 9.26-17.88c1.13-2.43 2.74-5.79 2.74-8.74 0-6.18-5.38-11.87-11.96-11.87Zm0 7.16a4.69 4.69 0 1 1-.02 9.4 4.69 4.69 0 0 1 .02-9.4Z" transform="translate(-7889.1 -9807.44) scale(19.54)"/></svg>',
9+
iconSize: [25, 41],
10+
iconAnchor: [12.5, 41],
11+
popupAnchor: [0, -41],
12+
className: '',
13+
});
14+
super.connect();
15+
}
16+
dispatchEvent(name, payload = {}) {
17+
this.dispatch(name, {
18+
prefix: 'ux:map',
19+
detail: {
20+
...payload,
21+
L,
22+
},
23+
});
24+
}
25+
doCreateMap({ center, zoom, options, }) {
26+
const map = L.map(this.element, {
27+
...options,
28+
center: center === null ? undefined : center,
29+
zoom: zoom === null ? undefined : zoom,
30+
});
31+
L.tileLayer(options.tileLayer.url, {
32+
attribution: options.tileLayer.attribution,
33+
...options.tileLayer.options,
34+
}).addTo(map);
35+
return map;
36+
}
37+
doCreateMarker(definition) {
38+
const { position, title, infoWindow, extra, rawOptions = {}, ...otherOptions } = definition;
39+
const marker = L.marker(position, { title, ...otherOptions, ...rawOptions }).addTo(this.map);
40+
if (infoWindow) {
41+
this.createInfoWindow({ definition: infoWindow, element: marker });
42+
}
43+
return marker;
44+
}
45+
doCreatePolygon(definition) {
46+
const { points, title, infoWindow, rawOptions = {} } = definition;
47+
const polygon = L.polygon(points, { ...rawOptions }).addTo(this.map);
48+
if (title) {
49+
polygon.bindPopup(title);
50+
}
51+
if (infoWindow) {
52+
this.createInfoWindow({ definition: infoWindow, element: polygon });
53+
}
54+
return polygon;
55+
}
56+
doCreatePolyline(definition) {
57+
const { points, title, infoWindow, rawOptions = {} } = definition;
58+
const polyline = L.polyline(points, { ...rawOptions }).addTo(this.map);
59+
if (title) {
60+
polyline.bindPopup(title);
61+
}
62+
if (infoWindow) {
63+
this.createInfoWindow({ definition: infoWindow, element: polyline });
64+
}
65+
return polyline;
66+
}
67+
doCreateInfoWindow({ definition, element, }) {
68+
const { headerContent, content, rawOptions = {}, ...otherOptions } = definition;
69+
element.bindPopup([headerContent, content].filter((x) => x).join('<br>'), { ...otherOptions, ...rawOptions });
70+
if (definition.opened) {
71+
element.openPopup();
72+
}
73+
const popup = element.getPopup();
74+
if (!popup) {
75+
throw new Error('Unable to get the Popup associated with the element.');
76+
}
77+
return popup;
78+
}
79+
doFitBoundsToMarkers() {
80+
if (this.markers.length === 0) {
81+
return;
82+
}
83+
this.map.fitBounds(this.markers.map((marker) => {
84+
const position = marker.getLatLng();
85+
return [position.lat, position.lng];
86+
}));
87+
}
88+
}
89+
90+
export { map_controller as default };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('LeafletController', () => {
4141
data-controller="check leaflet"
4242
style="height&#x3A;&#x20;700px&#x3B;&#x20;margin&#x3A;&#x20;10px"
4343
data-leaflet-provider-options-value="&#x7B;&#x7D;"
44-
data-leaflet-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;4,&quot;fitBoundsToMarkers&quot;&#x3A;true,&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;45.764,&quot;lng&quot;&#x3A;4.8357&#x7D;,&quot;title&quot;&#x3A;&quot;Lyon&quot;,&quot;infoWindow&quot;&#x3A;&#x7B;&quot;headerContent&quot;&#x3A;&quot;&lt;b&gt;Lyon&lt;&#x5C;&#x2F;b&gt;&quot;,&quot;content&quot;&#x3A;&quot;The&#x20;French&#x20;town&#x20;in&#x20;the&#x20;historic&#x20;Rh&#x5C;u00f4ne-Alpes&#x20;region,&#x20;located&#x20;at&#x20;the&#x20;junction&#x20;of&#x20;the&#x20;Rh&#x5C;u00f4ne&#x20;and&#x20;Sa&#x5C;u00f4ne&#x20;rivers.&quot;,&quot;position&quot;&#x3A;null,&quot;opened&quot;&#x3A;false,&quot;autoClose&quot;&#x3A;true&#x7D;&#x7D;&#x5D;,&quot;polygons&quot;&#x3A;[]&#x7D;polylines&quot;&#x3A;[]&#x7D;"
44+
data-leaflet-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;4,&quot;fitBoundsToMarkers&quot;&#x3A;true,&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;45.764,&quot;lng&quot;&#x3A;4.8357&#x7D;,&quot;title&quot;&#x3A;&quot;Lyon&quot;,&quot;infoWindow&quot;&#x3A;&#x7B;&quot;headerContent&quot;&#x3A;&quot;&lt;b&gt;Lyon&lt;&#x5C;&#x2F;b&gt;&quot;,&quot;content&quot;&#x3A;&quot;The&#x20;French&#x20;town&#x20;in&#x20;the&#x20;historic&#x20;Rh&#x5C;u00f4ne-Alpes&#x20;region,&#x20;located&#x20;at&#x20;the&#x20;junction&#x20;of&#x20;the&#x20;Rh&#x5C;u00f4ne&#x20;and&#x20;Sa&#x5C;u00f4ne&#x20;rivers.&quot;,&quot;position&quot;&#x3A;null,&quot;opened&quot;&#x3A;false,&quot;autoClose&quot;&#x3A;true&#x7D;&#x7D;&#x5D;,&quot;polygons&quot;&#x3A;[]&#x7D;,&quot;polylines&quot;&#x3A;[]&#x7D;"
4545
></div>
4646
`);
4747
});

src/Map/src/Twig/MapRuntime.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public function renderMap(
5858
foreach ($markers ?? [] as $marker) {
5959
$map->addMarker(Marker::fromArray($marker));
6060
}
61-
foreach ($polygons ?? [] as $polygons) {
62-
$map->addPolygon(Polygon::fromArray($polygons));
61+
foreach ($polygons ?? [] as $polygon) {
62+
$map->addPolygon(Polygon::fromArray($polygon));
6363
}
64-
foreach ($polylines ?? [] as $polylines) {
65-
$map->addPolyline(Polyline::fromArray($polylines));
64+
foreach ($polylines ?? [] as $polyline) {
65+
$map->addPolyline(Polyline::fromArray($polyline));
6666
}
6767
if (null !== $center) {
6868
$map->center(Point::fromArray($center));

0 commit comments

Comments
 (0)