-
-
Notifications
You must be signed in to change notification settings - Fork 364
[Map] Add possibility to configure extra options #2810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It looks like you unchecked the "Allow edits from maintainer" box. That is fine, but please note that if you have multiple commits, you'll need to squash your commits into one before this can be merged. Or, you can check the "Allow edits from maintainers" box and the maintainer can squash for you. Cheers! Carsonbot |
📊 Packages dist files size differenceThanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
|
As this is serialized, I guess we should make some minimal type check on the content of extra, no ? cc @Kocal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra
is already used for Marker
and cie to let the developper pass extra data from the back to the front, but the difference with the actual system is that extra
are not used by UX Map, these extra
data are only used in ux:map:*
events.
Instead, I suggest you to implement rawOptions
on Map options front-side, nothing should be modified backend-side.
Thanks!
If we only change the front-side how can we set options in the backend which are passed to the front? We want to set some options to the map configuration based on configuration from Symfony DI. Example: for the vector layers we need to pass a layerName and apiKey. |
This could be done through You can't pass I'm not fan how things are done for Map and options, raw options, etc, I will open a new PR asap. |
…onnect` event (e.g.: `zoom`, `options`, `bridgeOptions`...) (Kocal) This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Map] Allows Map options customization in `ux:map:pre-connect` event (e.g.: `zoom`, `options`, `bridgeOptions`...) | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Docs? | yes <!-- required for new features --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> This feature allows users to override the options passed to `L.Map()` or `new google.maps.Map()` trough the `ux:map:pre-connect` event. The configurable options are: - zoom - center - options - bridgeOptions, not injected by default, but can be defined on-the-fly This is a blocking step for #2810, but also for one of my need when I wanted to persist the zoom/center in the URL, to share my map (https://hugo.alliau.me/places 😛) : ```js _onMapPreConnect = (event) => { const { L } = event.detail; if (window.location.hash) { try { const state = Object.fromEntries(new URLSearchParams(window.location.hash.slice(1))); const zoom = Number(state.z); const center = state.center.split(",").map(Number); event.detail.zoom = zoom; event.detail.center = L.latLng(center[0], center[1]); } catch (e) { console.error("Invalid state in URL hash:", e); } } } _onMapConnect = (event) => { const { map } = event.detail; const updateState = () => { const center = map.getCenter(); const zoom = map.getZoom(); const state = { z: zoom, center: [center.lat.toFixed(5), center.lng.toFixed(5)], }; window.history.replaceState(state, "", `#${new URLSearchParams(state).toString()}`); }; map.addEventListener("zoom", () => updateState()); map.addEventListener("move", () => updateState()); }; ``` Commits ------- afc7db6 [Map] Add missing doc for Circle and Rectangle b0463b7 [Map] Allows Map options customization in `ux:map:pre-connect` event (e.g.: `zoom`, `options`, `bridgeOptions`...)
Replaced by #2863, thanks anyway for your contribution :) |
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Map] Add `extra` data to `Map` | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Docs? | yes <!-- required for new features --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Replace #2810 Like for `Marker` and cie, `extra` data can now be defined on the `Map` in order to pass extra data from your PHP code to your custom Stimulus Controller, through `ux:map:pre-connect` and `ux:map:connect` events. Combo-ed with `bridgeOptions` from #2861, it means that you can fully customize the Map creation given extra data given your PHP code (e.g.: injecting some API keys): ```php $map = new Map(extra: ['vector_layer_api_key' => 'bar']); // or $map->extra(['foo' => 'bar']); ``` ```js this.element.addEventListener('ux:map:pre-connect', (event) => { const { detail } = event; console.log(detail.extra); // {'foo': 'bar'} if (detail.extra.foo === 'bar') { detail.extra.bridgeOptions = { a_bridge_specific_option: 'foobar' }; } }); ``` Commits ------- 0363d5d [Map] Add `extra` data to `Map` b4b7f61 [Map] Reword PHPDoc about "extra" properties
TODO
Related to #2445 (comment)
Usage: