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 ] ,
@@ -39,25 +31,25 @@ export default class extends AbstractMapController<
3931 center,
4032 zoom,
4133 options,
42- } : { center : Point | null ; zoom : number | null ; options : MapOptions } ) : LeafletMap {
43- const map = createMap ( this . element , {
34+ } : { center : Point | null ; zoom : number | null ; options : MapOptions } ) : L . Map {
35+ const map = L . map ( this . element , {
4436 ...options ,
4537 center : center === null ? undefined : center ,
4638 zoom : zoom === null ? undefined : zoom ,
4739 } ) ;
4840
49- createTileLayer ( options . tileLayer . url , {
41+ L . tileLayer ( options . tileLayer . url , {
5042 attribution : options . tileLayer . attribution ,
5143 ...options . tileLayer . options ,
5244 } ) . addTo ( map ) ;
5345
5446 return map ;
5547 }
5648
57- protected doCreateMarker ( definition : MarkerDefinition ) : Marker {
49+ protected doCreateMarker ( definition : MarkerDefinition ) : L . Marker {
5850 const { position, title, infoWindow, extra, rawOptions = { } , ...otherOptions } = definition ;
5951
60- const marker = createMarker ( position , { title, ...otherOptions , ...rawOptions } ) . addTo ( this . map ) ;
52+ const marker = L . marker ( position , { title, ...otherOptions , ...rawOptions } ) . addTo ( this . map ) ;
6153
6254 if ( infoWindow ) {
6355 this . createInfoWindow ( { definition : infoWindow , marker } ) ;
@@ -71,8 +63,8 @@ export default class extends AbstractMapController<
7163 marker,
7264 } : {
7365 definition : MarkerDefinition [ 'infoWindow' ] ;
74- marker : Marker ;
75- } ) : Popup {
66+ marker : L . Marker ;
67+ } ) : L . Popup {
7668 const { headerContent, content, extra, rawOptions = { } , ...otherOptions } = definition ;
7769
7870 marker . bindPopup ( [ headerContent , content ] . filter ( ( x ) => x ) . join ( '<br>' ) , { ...otherOptions , ...rawOptions } ) ;
@@ -93,11 +85,17 @@ export default class extends AbstractMapController<
9385 }
9486
9587 this . map . fitBounds (
96- this . markers . map ( ( marker : Marker ) => {
88+ this . markers . map ( ( marker : L . Marker ) => {
9789 const position = marker . getLatLng ( ) ;
9890
9991 return [ position . lat , position . lng ] ;
10092 } )
10193 ) ;
10294 }
95+
96+ protected augmentEventPayload ( payload : Record < string , unknown > ) : Record < string , unknown > {
97+ payload . L = L ;
98+
99+ return payload ;
100+ }
103101}
0 commit comments