-
-
Notifications
You must be signed in to change notification settings - Fork 356
[Map] Add support for libraries
for Google Bridge, inject provider's SDK (L
or google
) to dispatched events
#2044
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
5ad48e6
to
a9b4ca7
Compare
@simondaigre I didn't forget about you #1937 (comment) ;) |
a9b4ca7
to
bdbc30f
Compare
I've updated the PR to:
|
libraries
Google Bridge, inject provider SDK (L
or google
) to dispatched eventslibraries
for Google Bridge, inject provider's SDK (L
or google
) to dispatched events
Could you add some shared alias for |
| `retries` | The number of script load retries | 3 | | ||
| `url` | Custom url to load the Google Maps API script | `https://maps.googleapis.com/maps/api/js` | | ||
| `version` | The release channels or version numbers | `weekly` | | ||
| `libraries` | The additional libraries to load, see [list of supported libraries](https://googlemaps.github.io/js-api-loader/types/Library.html) | `['maps', 'marker']`, those two libraries are always loaded | |
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.
Should that be in controller.json or something like that ?
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.
What do you mean?
export default class extends Controller | ||
{ | ||
connect() { | ||
this.element.addEventListener('ux:map:marker:before-create', this._onMarkerBeforeCreate); |
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.
This is new: ux:map:marker:before-create
?
Or did i left way too long to remember ? (4 days hahaha)
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.
Always has been here ;)
const beachFlagImg = document.createElement("img"); | ||
// Note: instead of using an hardcoded URL, you can use the `extra` parameter from `new Marker()` (PHP) and access it here with `definition.extra`. | ||
beachFlagImg.src = "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png"; |
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.
I think we should illustrate this example with a controller "value"
_onMarkerBeforeCreate(event) { | ||
// You can access the marker definition and the Leaflet object | ||
// Note: `definition.rawOptions` is the raw options object that will be passed to the `L.marker` constructor. | ||
const { definition, L } = event.detail; | ||
|
||
// Use a custom icon for the marker | ||
const redIcon = L.icon({ | ||
// Note: instead of using an hardcoded URL, you can use the `extra` parameter from `new Marker()` (PHP) and access it here with `definition.extra`. | ||
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, | ||
} | ||
} |
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.
This will update all maps on the page (if multiple ones) right ?
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.
Nope, only the ones using my-map
as data-controller
|
||
class map_controller extends AbstractMapController { | ||
connect() { | ||
Marker.prototype.options.icon = divIcon({ | ||
L.Marker.prototype.options.icon = L.divIcon({ | ||
html: '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" fill-rule="evenodd" stroke-linecap="round" clip-rule="evenodd" viewBox="0 0 500 820"><defs><linearGradient id="a" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -37.57 37.57 0 416.45 541)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#126FC6"/><stop offset="1" stop-color="#4C9CD1"/></linearGradient><linearGradient id="b" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -19.05 19.05 0 414.48 522.49)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2E6C97"/><stop offset="1" stop-color="#3883B7"/></linearGradient></defs><circle cx="252.31" cy="266.24" r="83.99" fill="#fff"/><path fill="url(#a)" stroke="url(#b)" stroke-width="1.1" d="M416.54 503.61c-6.57 0-12.04 5.7-12.04 11.87 0 2.78 1.56 6.3 2.7 8.74l9.3 17.88 9.26-17.88c1.13-2.43 2.74-5.79 2.74-8.74 0-6.18-5.38-11.87-11.96-11.87Zm0 7.16a4.69 4.69 0 1 1-.02 9.4 4.69 4.69 0 0 1 .02-9.4Z" transform="translate(-7889.1 -9807.44) scale(19.54)"/></svg>', |
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.
Oh please remind me to give you a more optimized icon @Kocal ... sorry 😞
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.
I recently updated it in #2036, I think we are really fine now
I know this is some "last minute before release" PR, but let's try to not mix features (extra info, librairies configuration) and documentation (custom marker) for the next ones ;) That beeing said: thanks for the job again @Kocal !! Amazing |
55ab782
to
7faf302
Compare
I'm curious, how would you have done it? Dedicated PRs for:
👀 |
83b8e03
to
d54c835
Compare
…s SDK (`L` or `google`) to dispatched events
d54c835
to
2dbb169
Compare
Thanks Hugo. |
Follows #2040.
This PR gives the developper access to
L
(if using Leaflet) orgoogle
(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:
Screenshot:

With Leaflet
A dumb example taken from the website:
Code:
Screenshot: