11import AbstractMapController from '@symfony/ux-map/abstract-map-controller' ;
22import type { Point , MarkerDefinition } from '@symfony/ux-map/abstract-map-controller' ;
33import 'leaflet/dist/leaflet.min.css' ;
4- import {
5- map as createMap ,
6- tileLayer as createTileLayer ,
7- marker as createMarker ,
8- divIcon ,
9- type Map as LeafletMap ,
10- Marker ,
11- type Popup ,
12- } from 'leaflet' ;
4+ import * as L from 'leaflet' ;
135import type { MapOptions as LeafletMapOptions , MarkerOptions , PopupOptions } from 'leaflet' ;
146
157type MapOptions = Pick < LeafletMapOptions , 'center' | 'zoom' > & {
@@ -18,14 +10,14 @@ type MapOptions = Pick<LeafletMapOptions, 'center' | 'zoom'> & {
1810
1911export default class extends AbstractMapController <
2012 MapOptions ,
21- typeof LeafletMap ,
13+ typeof L . Map ,
2214 MarkerOptions ,
23- Marker ,
24- Popup ,
15+ typeof L . Marker ,
16+ typeof L . Popup ,
2517 PopupOptions
2618> {
2719 connect ( ) : void {
28- Marker . prototype . options . icon = divIcon ( {
20+ L . Marker . prototype . options . icon = L . divIcon ( {
2921 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>' ,
3022 iconSize : [ 25 , 41 ] ,
3123 iconAnchor : [ 12.5 , 41 ] ,
@@ -35,25 +27,25 @@ export default class extends AbstractMapController<
3527 super . connect ( ) ;
3628 }
3729
38- protected doCreateMap ( { center, zoom, options } : { center : Point ; zoom : number ; options : MapOptions } ) : LeafletMap {
39- const map = createMap ( this . element , {
30+ protected doCreateMap ( { center, zoom, options } : { center : Point ; zoom : number ; options : MapOptions } ) : L . Map {
31+ const map = L . map ( this . element , {
4032 ...options ,
4133 center,
4234 zoom,
4335 } ) ;
4436
45- createTileLayer ( options . tileLayer . url , {
37+ L . tileLayer ( options . tileLayer . url , {
4638 attribution : options . tileLayer . attribution ,
4739 ...options . tileLayer . options ,
4840 } ) . addTo ( map ) ;
4941
5042 return map ;
5143 }
5244
53- protected doCreateMarker ( definition : MarkerDefinition ) : Marker {
45+ protected doCreateMarker ( definition : MarkerDefinition ) : L . Marker {
5446 const { position, title, infoWindow, extra, rawOptions = { } , ...otherOptions } = definition ;
5547
56- const marker = createMarker ( position , { title, ...otherOptions , ...rawOptions } ) . addTo ( this . map ) ;
48+ const marker = L . marker ( position , { title, ...otherOptions , ...rawOptions } ) . addTo ( this . map ) ;
5749
5850 if ( infoWindow ) {
5951 this . createInfoWindow ( { definition : infoWindow , marker } ) ;
@@ -67,8 +59,8 @@ export default class extends AbstractMapController<
6759 marker,
6860 } : {
6961 definition : MarkerDefinition [ 'infoWindow' ] ;
70- marker : Marker ;
71- } ) : Popup {
62+ marker : L . Marker ;
63+ } ) : L . Popup {
7264 const { headerContent, content, extra, rawOptions = { } , ...otherOptions } = definition ;
7365
7466 marker . bindPopup ( [ headerContent , content ] . filter ( ( x ) => x ) . join ( '<br>' ) , { ...otherOptions , ...rawOptions } ) ;
@@ -89,11 +81,17 @@ export default class extends AbstractMapController<
8981 }
9082
9183 this . map . fitBounds (
92- this . markers . map ( ( marker : Marker ) => {
84+ this . markers . map ( ( marker : L . Marker ) => {
9385 const position = marker . getLatLng ( ) ;
9486
9587 return [ position . lat , position . lng ] ;
9688 } )
9789 ) ;
9890 }
91+
92+ protected augmentEventPayload ( payload : Record < string , unknown > ) : Record < string , unknown > {
93+ payload . L = L ;
94+
95+ return payload ;
96+ }
9997}
0 commit comments