Skip to content

[Map] Add "extra" data for markers and infowindows #2040

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 1 commit into from
Aug 9, 2024

Conversation

Kocal
Copy link
Member

@Kocal Kocal commented Aug 9, 2024

Q A
Bug fix? no
New feature? yes
Issues Fix #...
License MIT

Actually when creating Marker and InfoWindow with Symfony UX Map, you can only pass:

  • Marker: position, title, and infoWindow
  • InfoWindow: headerContent, content, position, opened and autoClose

This is great, but too strict.
Adding a new property extra, defined by the developper and only used by the developper (in specific Stimulus events), is IMHO a good way to open for more extensibility.

Note that the new example in the documentation is not complete yet, a 2nd PR will appears soon to customize the Marker Icon :)

@carsonbot carsonbot added Feature New Feature Status: Needs Review Needs to be reviewed labels Aug 9, 2024
@Kocal Kocal force-pushed the feat/ux-map-extra-data branch 2 times, most recently from d66ce7b to c56e9eb Compare August 9, 2024 09:57
@Kocal Kocal force-pushed the feat/ux-map-extra-data branch from c56e9eb to c118875 Compare August 9, 2024 09:59
@javiereguiluz
Copy link
Member

Thanks to your description I understand the need for this. Also, I like the extra option name because it's short and easy to understand. Thanks Hugo!

@javiereguiluz javiereguiluz merged commit 9bcdd35 into symfony:2.x Aug 9, 2024
39 checks passed
@Kocal Kocal deleted the feat/ux-map-extra-data branch August 9, 2024 10:18
kbond added a commit that referenced this pull request Aug 12, 2024
…ject provider's SDK (`L` or `google`) to dispatched events (Kocal)

This PR was squashed before being merged into the 2.x branch.

Discussion
----------

[Map] Add support for `libraries` for Google Bridge, inject provider's SDK (`L` or `google`) to dispatched events

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| 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.
 - 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).
-->

Follows #2040.

This PR gives the developper access to `L` (if using Leaflet) or `google` (if using Google Maps) in dispatched events, so the developper can **fully and freely** customize the map, their markers (before and after creation), and info windows (before and after creation).

I've added some use cases/examples in respective documentation, but tell me if a better place fits!

Also, please no quick merge this time (even if I like that :D), I really wants some reviews for this PR! cc `@javiereguiluz`  🙏🏻

# Code and screenshots

On my personal project, I have a map with a lot of markers.

Before UX Map, I was using Google Maps because I've found the "glyph" feature really sexy, but I was not able to use it anymore... until now!

## With Google Maps

Code:
```js
import {Controller} from "`@hotwired`/stimulus";

export default class extends Controller
{
    connect() {
        this.element.addEventListener('ux:map:marker:before-create', this._onMarkerBeforeCreate);
    }

    disconnect() {
        this.element.removeEventListener('ux:map:marker:before-create', this._onMarkerBeforeCreate);
    }

    _onMarkerBeforeCreate(event) {
        const { definition, google } = event.detail;

        const pinElement = new google.maps.marker.PinElement({
            glyph: new URL(String(definition.extra['icon_mask_uri'])), // I've filled `extra` parameter from `new Marker()` (PHP) with the icon mask URL
            glyphColor: "white",
        });

        definition.rawOptions = {
            content: pinElement.element,
        }
    }
}
```

Screenshot:
<img width="470" alt="Capture d’écran 2024-08-09 à 22 58 19" src="https://github.com/user-attachments/assets/ace5a033-a423-45c5-bd67-0da68dd188c1">

## With Leaflet

A dumb example taken from the website:

Code:
```js
import {Controller} from "`@hotwired`/stimulus";

export default class extends Controller
{
    connect() {
        this.element.addEventListener('ux:map:marker:before-create', this._onMarkerBeforeCreate);
    }

    disconnect() {
        this.element.removeEventListener('ux:map:marker:before-create', this._onMarkerBeforeCreate);
    }

    _onMarkerBeforeCreate(event) {
        const { definition, L } = event.detail;

        const redIcon = L.icon({
            iconUrl: 'https://leafletjs.com/examples/custom-icons/leaf-red.png',
            shadowUrl: 'https://leafletjs.com/examples/custom-icons/leaf-shadow.png',
            iconSize:     [38, 95], // size of the icon
            shadowSize:   [50, 64], // size of the shadow
            iconAnchor:   [22, 94], // point of the icon which will correspond to marker's location
            shadowAnchor: [4, 62],  // the same for the shadow
            popupAnchor:  [-3, -76] // point from which the popup should open relative to the iconAnchor
        })

        definition.rawOptions = {
            icon: redIcon,
        }
    }
}
```

Screenshot:

<img width="495" alt="Capture d’écran 2024-08-09 à 23 19 23" src="https://github.com/user-attachments/assets/e771c133-794a-4693-bfbb-5a3118f5f7f5">

Commits
-------

2dbb169 [Map] Add support for `libraries` for Google Bridge, inject provider's SDK (`L` or `google`) to dispatched events
@Kocal Kocal added the Map label Aug 15, 2024
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.

3 participants