Skip to content

[Map] Add extra data to Map #2863

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

Merged
merged 2 commits into from
Jun 23, 2025
Merged

[Map] Add extra data to Map #2863

merged 2 commits into from
Jun 23, 2025

Conversation

Kocal
Copy link
Member

@Kocal Kocal commented Jun 23, 2025

Q A
Bug fix? no
New feature? yes
Docs? yes
Issues Fix #...
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):

$map = new Map(extra: ['vector_layer_api_key' => 'bar']);
// or
$map->extra(['foo' => 'bar']);
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' };
    }
});

@carsonbot carsonbot added Feature New Feature Map Status: Needs Review Needs to be reviewed labels Jun 23, 2025
Copy link
Contributor

github-actions bot commented Jun 23, 2025

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
Map
abstract_map_controller.d.ts 7.35 kB / 1.38 kB 7.45 kB+1% 📈 / 1.41 kB+3% 📈
abstract_map_controller.js 5.35 kB / 1.35 kB 5.47 kB+2% 📈 / 1.38 kB+2% 📈
Map (Bridge Google)
map_controller.js 14.1 kB / 3.01 kB 14.22 kB+1% 📈 / 3.04 kB+1% 📈
Map (Bridge Leaflet)
map_controller.js 13.24 kB / 3.2 kB 13.36 kB+1% 📈 / 3.22 kB+1% 📈

@@ -259,10 +271,12 @@ export default abstract class<
protected abstract dispatchEvent(name: string, payload: Record<string, unknown>): void;

connect() {
const extra = this.hasExtraValue ? this.extraValue : {};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null from Map::toState() makes the attribute data-...-extra-value not being rendered, so we use this.hasExtraValue to ensure something was defined or not

@Kocal Kocal merged commit 11f3cd4 into symfony:2.x Jun 23, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature Map Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants