@@ -30,11 +30,11 @@ Configuration
30
30
Configuration is done in your ``config/packages/ux_map.yaml `` file:
31
31
32
32
.. code-block :: yaml
33
-
33
+
34
34
# config/packages/ux_map.yaml
35
35
ux_map :
36
36
renderer : ' %env(resolve:default::UX_MAP_DSN)%'
37
-
37
+
38
38
# Google Maps specific configuration
39
39
google_maps :
40
40
# Configure the default Map Id (https://developers.google.com/maps/documentation/get-map-id),
@@ -47,8 +47,8 @@ Map renderers
47
47
~~~~~~~~~~~~~
48
48
49
49
The Symfony UX Map bundle supports multiple renderers. A map renderer is a
50
- service that provides the code and graphic assets required to render and
51
- interact with a map in the browser.
50
+ service that provides the code and graphic assets required to render and
51
+ interact with a map in the browser.
52
52
53
53
Available renderers
54
54
~~~~~~~~~~~~~~~~~~~
@@ -75,7 +75,7 @@ Create a map
75
75
76
76
A map is created by calling ``new Map() ``. You can configure the center, zoom, and add markers.
77
77
Start by creating a new map instance::
78
-
78
+
79
79
use Symfony\UX\Map\Map;
80
80
81
81
// Create a new map instance
@@ -88,12 +88,12 @@ You can set the center and zoom of the map using the ``center()`` and ``zoom()``
88
88
89
89
use Symfony\UX\Map\Map;
90
90
use Symfony\UX\Map\Point;
91
-
91
+
92
92
$myMap
93
93
// Explicitly set the center and zoom
94
94
->center(new Point(46.903354, 1.888334))
95
95
->zoom(6)
96
-
96
+
97
97
// Or automatically fit the bounds to the markers
98
98
->fitBoundsToMarkers()
99
99
;
@@ -105,13 +105,13 @@ You can add markers to a map using the ``addMarker()`` method::
105
105
106
106
$myMap
107
107
->addMarker(new Marker(
108
- position: new Point(48.8566, 2.3522),
108
+ position: new Point(48.8566, 2.3522),
109
109
title: 'Paris'
110
110
))
111
111
112
112
// With an info window associated to the marker:
113
113
->addMarker(new Marker(
114
- position: new Point(45.7640, 4.8357),
114
+ position: new Point(45.7640, 4.8357),
115
115
title: 'Lyon',
116
116
infoWindow: new InfoWindow(
117
117
headerContent: '<b>Lyon</b>',
@@ -174,7 +174,7 @@ You can add custom HTML attributes too:
174
174
Twig Function ``ux_map() ``
175
175
~~~~~~~~~~~~~~~~~~~~~~~~~~
176
176
177
- The ``ux_map() `` Twig function allows you to create and render a map in your Twig
177
+ The ``ux_map() `` Twig function allows you to create and render a map in your Twig
178
178
templates. The function accepts the same arguments as the ``Map `` class:
179
179
180
180
.. code-block :: html+twig
@@ -216,10 +216,8 @@ Alternatively, you can use the ``<twig:ux:map />`` component.
216
216
"infoWindow": {"content": "Welcome to <b>New York</b>"}
217
217
}
218
218
]'
219
- attributes='{
220
- "class": "foo",
221
- "style": "height: 800px; width: 100%; border: 4px solid red; margin-block: 10vh;"
222
- }'
219
+ class="foo"
220
+ style="height: 800px; width: 100%; border: 4px solid red; margin-block: 10vh;"
223
221
/>
224
222
225
223
The ``<twig:ux:map /> `` component requires the `Twig Component `_ package.
@@ -236,9 +234,9 @@ Symfony UX Map allows you to extend its default behavior using a custom Stimulus
236
234
.. code-block :: javascript
237
235
238
236
// assets/controllers/mymap_controller.js
239
-
237
+
240
238
import { Controller } from ' @hotwired/stimulus' ;
241
-
239
+
242
240
export default class extends Controller {
243
241
connect () {
244
242
this .element .addEventListener (' ux:map:pre-connect' , this ._onPreConnect );
@@ -248,7 +246,7 @@ Symfony UX Map allows you to extend its default behavior using a custom Stimulus
248
246
this .element .addEventListener (' ux:map:info-window:before-create' , this ._onInfoWindowBeforeCreate );
249
247
this .element .addEventListener (' ux:map:info-window:after-create' , this ._onInfoWindowAfterCreate );
250
248
}
251
-
249
+
252
250
disconnect () {
253
251
// You should always remove listeners when the controller is disconnected to avoid side effects
254
252
this .element .removeEventListener (' ux:map:pre-connect' , this ._onPreConnect );
@@ -258,41 +256,41 @@ Symfony UX Map allows you to extend its default behavior using a custom Stimulus
258
256
this .element .removeEventListener (' ux:map:info-window:before-create' , this ._onInfoWindowBeforeCreate );
259
257
this .element .removeEventListener (' ux:map:info-window:after-create' , this ._onInfoWindowAfterCreate );
260
258
}
261
-
259
+
262
260
_onPreConnect (event ) {
263
261
// The map is not created yet
264
262
// You can use this event to configure the map before it is created
265
263
console .log (event .detail .options );
266
264
}
267
-
265
+
268
266
_onConnect (event ) {
269
267
// The map, markers and infoWindows are created
270
268
// The instances depend on the renderer you are using
271
269
console .log (event .detail .map );
272
270
console .log (event .detail .markers );
273
271
console .log (event .detail .infoWindows );
274
272
}
275
-
273
+
276
274
_onMarkerBeforeCreate (event ) {
277
275
// The marker is not created yet
278
276
// You can use this event to configure the marker before it is created
279
277
console .log (event .detail .definition );
280
278
}
281
-
279
+
282
280
_onMarkerAfterCreate (event ) {
283
281
// The marker is created
284
282
// The instance depends on the renderer you are using
285
283
console .log (event .detail .marker );
286
284
}
287
-
285
+
288
286
_onInfoWindowBeforeCreate (event ) {
289
287
// The infoWindow is not created yet
290
288
// You can use this event to configure the infoWindow before it is created
291
289
console .log (event .detail .definition );
292
290
// The associated marker instance is also available
293
291
console .log (event .detail .marker );
294
292
}
295
-
293
+
296
294
_onInfoWindowAfterCreate (event ) {
297
295
// The infoWindow is created
298
296
// The instance depends on the renderer you are using
@@ -306,7 +304,7 @@ Symfony UX Map allows you to extend its default behavior using a custom Stimulus
306
304
Then, you can use this controller in your template:
307
305
308
306
.. code-block :: twig
309
-
307
+
310
308
{{ ux_map(my_map, { 'data-controller': 'mymap', style: 'height: 300px' }) }}
311
309
312
310
.. tip ::
0 commit comments