← Back to examples

API Reference — async-map-modal

Full parameter documentation for showMapModal(options) and helper functions.

showMapModal(options)

Opens the map modal. Returns Promise<{ lat, lng } | null> in single-select mode, Promise<Array<{ lat, lng }> | null> in multi-select mode.

Mode

ParameterTypeDefaultDescription
multiSelect boolean false true = multiple points, list on the right, checkboxes, delete one/all. false = single point.

Example — single:

const result = await asyncMapModal.show({ leaflet: L });
// result: { lat: 39.93, lng: 32.85 } or null

Example — multiple:

const points = await asyncMapModal.show({ multiSelect: true, leaflet: L });
// points: [{ lat, lng }, ...] or null

Title and button labels

ParameterTypeDefaultModeDescription
titlestringFrom localebothModal title.
confirmTextstringFrom localebothConfirm button label (e.g. "Select", "OK").
cancelTextstringFrom localebothCancel button label.
copyTextstringFrom localebothCopy coordinates button label.
deleteSelectedTextstringFrom localemulti"Delete selected" button label.
deleteAllTextstringFrom localemulti"Delete all" button label.
listTitlestringFrom localemultiRight-hand list section title (e.g. "Selected points").
fitBoundsTextstringFrom localemulti"Show all" (fit all points on map) button label.
asyncMapModal.show({
  title: 'Select delivery address',
  confirmText: 'Deliver here',
  cancelText: 'Cancel',
  copyText: 'Copy coordinates',
  leaflet: L,
});

Map initial values

ParameterTypeDefaultDescription
initialCenter[number, number][38.7143, 35.5323]Map center on open [lat, lng].
initialZoomnumber13Initial zoom level (0–22, depends on tile maxZoom).
mapHeightstring'400px'CSS height of map container (e.g. '50vh', '300px').
asyncMapModal.show({
  initialCenter: [41.0082, 28.9784],
  initialZoom: 11,
  mapHeight: '50vh',
  leaflet: L,
});

Marker

ParameterTypeDefaultDescription
markerIconL.Icon | L.DivIconnullCustom marker icon. null = default Leaflet blue pin. Same icon in single and multi mode.
const customIcon = L.divIcon({
  className: 'my-marker',
  html: '<span class="pin"></span>',
  iconSize: [24, 24],
  iconAnchor: [12, 24],
});
asyncMapModal.show({ markerIcon: customIcon, leaflet: L });

Multi-select only

ParameterTypeDefaultDescription
initialPointsArray<{lat,lng}|[number,number]>[]Points to show in the list when modal opens. User can add/remove; "OK" returns current list.
maxPointsnumber | nullnullMax number of points. When set, no new point is added above this limit. null = unlimited.
asyncMapModal.show({
  multiSelect: true,
  initialPoints: [
    { lat: 39.9255, lng: 32.8663 },
    [41.0082, 28.9784],
  ],
  maxPoints: 10,
  leaflet: L,
});

Selection bounds

Restrict selectable coordinates. Two options:

ParameterTypeDefaultDescription
bounds[[number, number], [number, number]][[south, west], [north, east]] — only clicks/paste inside this area are accepted.
minLat, maxLatnumberLatitude min/max.
minLng, maxLngnumberLongitude min/max.
asyncMapModal.show({
  bounds: [[39.5, 32.0], [42.0, 35.0]],
  initialCenter: [40.5, 33.5],
  leaflet: L,
});

Tile layer

ParameterTypeDefaultDescription
tileLayerUrlstringOpenStreetMapTile URL template (e.g. https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png).
tileLayerAttributionstring© OSMAttribution text shown below map.
tileLayerMaxZoomnumber18Max zoom for the layer.
asyncMapModal.show({
  tileLayerUrl: 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png',
  tileLayerAttribution: '© CARTO',
  tileLayerMaxZoom: 19,
  leaflet: L,
});

Language and theme

ParameterTypeDefaultDescription
languagestringgetConfig() or 'tr'UI language: 'tr', 'en', 'de', 'es', 'fr'. All strings in-package.
darkMode'light' | 'dark' | 'auto'getConfig() or 'light'Modal theme. 'auto' = system preference (prefers-color-scheme: dark).
asyncMapModal.show({
  language: 'en',
  darkMode: 'dark',
  leaflet: L,
});

Leaflet reference

ParameterTypeDefaultDescription
leafletobjectwindow.LLeaflet library object. Required when L is not global (e.g. in ESM).
import L from 'leaflet';
const result = await asyncMapModal.show({ leaflet: L });

init(options)

Sets project-wide default language and theme. Subsequent showMapModal calls merge these with their options; per-call language / darkMode take precedence.

ParameterTypeDescription
languagestringDefault language: 'tr', 'en', 'de', 'es', 'fr'.
darkMode'light' | 'dark' | 'auto'Default theme.
asyncMapModal.init({
  language: 'en',
  darkMode: 'auto',
});

getConfig()

Returns current project defaults (copy). Use init, setTheme, or setLanguage to change them.

Returns: { language: string | undefined, darkMode: string | undefined }

const config = asyncMapModal.getConfig();
console.log(config.language, config.darkMode);

setTheme(theme)

Sets default theme. Used by showMapModal when options.darkMode is not provided.

ParameterTypeDescription
theme'light' | 'dark' | 'auto'Theme to use.
asyncMapModal.setTheme('dark');

setLanguage(lang)

Sets default language code.

ParameterTypeDescription
langstring'tr', 'en', 'de', 'es', 'fr'.
asyncMapModal.setLanguage('en');

Parameter summary table

ParameterTypeDefaultMode
multiSelectbooleanfalse
titlestring(locale)both
initialCenter[number, number][38.7143, 35.5323]both
initialZoomnumber13both
confirmTextstring(locale)both
cancelTextstring(locale)both
mapHeightstring'400px'both
markerIconL.Icon | L.DivIconnullboth
copyTextstring(locale)both
deleteSelectedTextstring(locale)multi
deleteAllTextstring(locale)multi
listTitlestring(locale)multi
fitBoundsTextstring(locale)multi
initialPointsArray[]multi
maxPointsnumber | nullnullmulti
bounds[[s,w],[n,e]]both
minLat, maxLat, minLng, maxLngnumberboth
tileLayerUrlstringOSMboth
tileLayerAttributionstringOSMboth
tileLayerMaxZoomnumber18both
languagestringtr / getConfig()both
darkMode'light'|'dark'|'auto'light / getConfig()both
leafletobjectwindow.Lboth