Skip to content

Commit 1fee3cd

Browse files
committed
[Map][Docs] Add "extra data" section
1 parent 6dc9eb1 commit 1fee3cd

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

src/Map/doc/index.rst

+50-3
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,13 @@ Then, you can use this controller in your template:
416416
Advanced: Low-level options
417417
~~~~~~~~~~~~~~~~~~~~~~~~~~~
418418

419-
UX Map was designed to be renderer-agnostic, it provides a high-level API to configure the map and its elements.
420-
However, sometimes you may feel limited by this abstraction and want to configure low-level options.
419+
UX Map was designed to be renderer-agnostic, it provides a high-level API
420+
to configure the map and its elements.
421+
However, sometimes you may feel limited by this abstraction and you would
422+
like to configure low-level options.
421423

422-
Fortunately, it is possible to configure those low-level options by using the UX Map events ``ux:map:*:before-create`` with the custom ``rawOptions`` property:
424+
Fortunately, it is possible to configure those low-level options by using the
425+
UX Map events ``ux:map:*:before-create`` with the custom ``rawOptions`` property:
423426

424427
.. code-block:: javascript
425428
@@ -492,6 +495,50 @@ Fortunately, it is possible to configure those low-level options by using the UX
492495
}
493496
}
494497
498+
Advanced: Passing extra data from PHP to the Stimulus controller
499+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
500+
501+
For higher customization and extensibility, you can also pass extra data from PHP to the Stimulus controller.
502+
It may be useful to pass data for a specific marker, e.g. the type of place it represents.
503+
504+
Those extra data are only defined and used by you, UX Map only passes them to the Stimulus controller.
505+
506+
To pass extra data from PHP to the Stimulus controller, you must use the ``extra`` property
507+
available for ``Marker``, ``InfoWindow``, ``Polygon`` and ``Polyline`` instances::
508+
509+
$map->addMarker(new Marker(
510+
position: new Point(48.822248, 2.337338),
511+
title: 'Paris - Parc Montsouris',
512+
extra: [
513+
'type' => 'Park',
514+
// ...
515+
],
516+
));
517+
518+
JavaScript side, you can access your extra data through the ``event.detail.definition.extra`` object
519+
available on ``ux:map:*:before-create`` and ``ux:map:*:after-create`` events:
520+
521+
.. code-block:: javascript
522+
523+
// assets/controllers/mymap_controller.js
524+
525+
import { Controller } from '@hotwired/stimulus';
526+
527+
export default class extends Controller {
528+
529+
// ...
530+
531+
_onMarkerBeforeCreate(event) {
532+
console.log(event.detail.definition.extra); // { type: 'Park', ...}
533+
}
534+
535+
_onMarkerAfterCreate(event) {
536+
console.log(event.detail.definition.extra); // { type: 'Park', ...}
537+
}
538+
539+
// ...
540+
}
541+
495542
.. _map-live-component:
496543

497544
Usage with Live Components

0 commit comments

Comments
 (0)