Skip to main content

Map

import { Map } from '@enmovil/ui-design-system';

A map that shows groups of markers, routes and geofences, with optional drawing tools and place search. It needs a Google Maps API key, passed in apiKey.

Properties​

PropertyTypeRequiredDefaultAllowed valuesDescription
centerLatLngLiteralNo{ lat: 17.385044, lng: 78.486671 }—Initial centre of the map as { lat, lng }. Defaults to Hyderabad (17.385044, 78.486671); when it changes the map re-centres, so pass a stable object rather than a new literal on every render.
zoomnumberNo8—Initial zoom level of the map. Defaults to 8; when it changes the map zooms to the new level (0 is ignored).
markerGroups{ key: string; markers: { [key: string]: any; lat: number; lng: number; status?: string | number; label?: string; icon?: string | undefined; }[]; enableClustering?: boolean | undefined; radius?: number | undefined; }[] | undefinedNo[]—Groups of markers to show on the map, each with its own clustering and radius settings. Markers can be hidden with the Show Markers filter.
polylineGroups{ key: string; path: LatLngLiteral[]; color?: string; weight?: number; opacity?: number | undefined; showEndpoints?: boolean | undefined; showArrows?: boolean | undefined; ... 9 more ...; destinationLabel?: string | undefined; }[] | undefinedNo[]—Routes to draw on the map, each with its own colour, line style, arrows and start/end markers.
geofenceGroups{ key: string; type: "circle" | "polygon"; center?: { lat: number; lng: number; }; radius?: number; path?: { lat: number; lng: number; }[] | undefined; strokeColor?: string | undefined; fillColor?: string | undefined; fillOpacity?: number | undefined; strokeWeight?: number | undefined; editab...No[]—Circular and polygonal areas to draw on the map. They can be hidden with the Show Geofences filter.
apiKeystringNo——Google Maps API key used to load the maps script when it is not already on the page. The script is loaded once per page; without a key and without a loaded script the map stays blank and an error is logged.
classNamestringNo——Extra CSS class added to the map wrapper.
enabledFilters("markers" | "geofences" | "viewMarks" | "endpoints")[]No[]—Filter checkboxes shown above the map: markers (Show Markers), geofences (Show Geofences), viewMarks (View Markers) and endpoints (Show Start/End Points). Nothing is shown when it is empty. Changing any checkbox also turns off the layers whose checkbox is not listed, so list every layer you use.
filterOptions{ label: string; key: string | string[]; }[]No[]—Declared, but not used by the component; the checkbox labels are fixed and chosen by enabledFilters.
defaultShowEndpointsbooleanNotrue—Whether route start and end markers are shown at first. Defaults to true; routes still need showEndpoints, and the endpoints filter can change it later.
defaultViewMarksbooleanNofalse—Whether a small dot is drawn at every point of every route at first. Defaults to false; the viewMarks filter can change it later.
enableDrawingbooleanNofalse—Adds the drawing toolbar at the top centre of the map. Turning it off removes the toolbar but keeps the shapes already drawn.
drawingControls{ drawingModes?: ("circle" | "polygon" | "marker" | "polyline" | "rectangle")[]; markerOptions?: { icon?: string; } | undefined; polylineOptions?: { editable?: boolean | undefined; strokeColor?: string | undefined; strokeOpacity?: number | undefined; strokeWeight?: number | undefined; } | und...No——Which shapes the drawing toolbar offers and how they look. Requires enableDrawing, and is only read when the toolbar is created, so later changes are ignored until drawing is turned off and on again.
defaultDrawingMode"circle" | "polygon" | "marker" | "polyline" | "rectangle" | nullNonull—Drawing tool that is active when the toolbar appears. Defaults to null (pan and select); changing it switches the active tool. Requires enableDrawing.
enableSearchbooleanNofalse—Adds a "Search places..." box at the top left of the map. Picking a result drops a marker on each matching place and fits the map to them. The box uses a fixed element id, so only one map on a page can have search.

markerGroups​

An array of objects. Each object has these fields:

FieldTypeRequiredDescription
keystringYesIdentifies the group. Passed to getInfoWindowContent when one of its markers is clicked.
markers{ lat: number; lng: number; status?: number | string; label?: string; icon?: string; [key: string]: any; }[]YesMarkers of the group. Markers without lat or lng are skipped.
enableClusteringbooleanNoGroups nearby markers of this group into numbered clusters that split apart as you zoom in.
radiusnumberNoDraws a shaded circle of this radius, in metres, around every marker of the group. No circle is drawn without it.

markerGroups.markers​

An array of objects. Each object has these fields:

FieldTypeRequiredDescription
latnumberYesLatitude of the marker.
lngnumberYesLongitude of the marker.
statusnumber | stringNoNot used by the component itself; passed to getInfoWindowContent with the rest of the marker data.
labelstringNoTitle of the default popup shown when the marker is clicked.
iconstringNoImage source of the marker icon. Falls back to the bundled marker icon.

polylineGroups​

An array of objects. Each object has these fields:

FieldTypeRequiredDescription
keystringYesIdentifies the group. Not used by the component when drawing.
pathgoogle.maps.LatLngLiteral[]YesPoints of the route, in order, as { lat, lng }. Routes with an empty path are skipped.
colorstringNoColour of the line, also used for its arrows. Falls back to the theme's route colour (dark green).
weightnumberNoLine width in pixels. Defaults to 2.
opacitynumberNoOpacity of the line from 0 to 1, also used for its arrows. Defaults to 1.
showEndpointsbooleanNoShows source and destination markers at the first and last points of the path. Also needs defaultShowEndpoints (or the endpoints filter) to be on.
showArrowsbooleanNoDraws direction arrows along the line, about every 60 pixels.
arrowScalenumberNoSize of the arrows. Defaults to 2. Requires showArrows.
arrowColorstringNoColour of the arrows. Falls back to color. Requires showArrows.
arrowOpacitynumberNoOpacity of the arrows from 0 to 1. Falls back to opacity. Requires showArrows.
variant"solid" | "dashed" | "dotted"NoLine style: solid, dashed or dotted. Defaults to solid.
sourceIconstringNoImage source of the start marker. Falls back to the bundled source icon. Requires showEndpoints.
destinationIconstringNoImage source of the end marker. Falls back to the bundled destination icon. Requires showEndpoints.
sourceKeystringNoKey passed to getInfoWindowContent when the start marker is clicked. Defaults to source.
destinationKeystringNoKey passed to getInfoWindowContent when the end marker is clicked. Defaults to destination.
sourceLabelstringNoTitle of the start marker's popup. Defaults to Source.
destinationLabelstringNoTitle of the end marker's popup. Defaults to Destination.

geofenceGroups​

An array of objects. Each object has these fields:

FieldTypeRequiredDescription
keystringYesIdentifies the geofence. Returned in onEditGeoFenceGroups when the geofence is edited.
type"circle" | "polygon"YesShape of the geofence: circle (needs center and radius) or polygon (needs path).
center{ lat: number; lng: number }NoCentre of a circular geofence. Circles without it are not drawn.
radiusnumberNoRadius of a circular geofence in metres. Circles without it are not drawn.
path{ lat: number; lng: number }[]NoCorner points of a polygonal geofence, in order. Polygons without it are not drawn.
strokeColorstringNoOutline colour. Falls back to the theme's geofence colour (red).
fillColorstringNoFill colour. Falls back to the theme's geofence colour (red).
fillOpacitynumberNoFill opacity from 0 to 1. Defaults to 0.2.
strokeWeightnumberNoOutline width in pixels. Defaults to 2.
editablebooleanNoLets the user drag the geofence's handles to move or reshape it; each change fires onEditGeoFenceGroups. Defaults to false.

geofenceGroups.center​

An object with these fields:

FieldTypeRequiredDescription
latnumberYesLatitude of the circle's centre.
lngnumberYesLongitude of the circle's centre.

geofenceGroups.path​

An array of objects. Each object has these fields:

FieldTypeRequiredDescription
latnumberYesLatitude of the point.
lngnumberYesLongitude of the point.

filterOptions​

An array of objects. Each object has these fields:

FieldTypeRequiredDescription
labelstringYesDeclared, but not used by the component.
keystring | string[]YesDeclared, but not used by the component.

drawingControls​

An object with these fields:

FieldTypeRequiredDescription
drawingModes( | "marker" | "polyline" | "polygon" | "circle" | "rectangle" )[]NoShapes offered in the drawing toolbar: marker, polyline, polygon, circle and rectangle. Only the listed shapes get a button.
markerOptions{ icon?: string; }NoLook of markers placed with the drawing toolbar.
polylineOptions{ editable?: boolean; strokeColor?: string; strokeOpacity?: number; strokeWeight?: number; }NoLook of lines drawn with the drawing toolbar.
polygonOptions{ editable?: boolean; strokeColor?: string; strokeOpacity?: number; strokeWeight?: number; }NoLook of polygons drawn with the drawing toolbar.
circleOptions{ editable?: boolean; fillColor?: string; fillOpacity?: number; strokeColor?: string; strokeOpacity?: number; strokeWeight?: number; }NoLook of circles drawn with the drawing toolbar.
rectangleOptions{ editable?: boolean; fillColor?: string; fillOpacity?: number; strokeColor?: string; strokeOpacity?: number; strokeWeight?: number; }NoLook of rectangles drawn with the drawing toolbar.

drawingControls.markerOptions​

An object with these fields:

FieldTypeRequiredDescription
iconstringNoImage source of drawn markers. Falls back to the bundled marker icon.

drawingControls.polylineOptions​

An object with these fields:

FieldTypeRequiredDescription
editablebooleanNoLets the user drag a drawn line's points after drawing; each change fires onDrawingPolylines.
strokeColorstringNoColour of drawn lines.
strokeOpacitynumberNoOpacity of drawn lines from 0 to 1.
strokeWeightnumberNoWidth of drawn lines in pixels.

drawingControls.polygonOptions​

An object with these fields:

FieldTypeRequiredDescription
editablebooleanNoLets the user drag a drawn polygon's corners after drawing; each change fires onDrawingPolygons.
strokeColorstringNoOutline colour of drawn polygons.
strokeOpacitynumberNoOutline opacity of drawn polygons from 0 to 1.
strokeWeightnumberNoOutline width of drawn polygons in pixels.

drawingControls.circleOptions​

An object with these fields:

FieldTypeRequiredDescription
editablebooleanNoLets the user move and resize a drawn circle after drawing; each change fires onDrawingCircles.
fillColorstringNoFill colour of drawn circles.
fillOpacitynumberNoFill opacity of drawn circles from 0 to 1.
strokeColorstringNoOutline colour of drawn circles.
strokeOpacitynumberNoOutline opacity of drawn circles from 0 to 1.
strokeWeightnumberNoOutline width of drawn circles in pixels.

drawingControls.rectangleOptions​

An object with these fields:

FieldTypeRequiredDescription
editablebooleanNoLets the user move and resize a drawn rectangle after drawing; each change fires onDrawingRectangles.
fillColorstringNoFill colour of drawn rectangles.
fillOpacitynumberNoFill opacity of drawn rectangles from 0 to 1.
strokeColorstringNoOutline colour of drawn rectangles.
strokeOpacitynumberNoOutline opacity of drawn rectangles from 0 to 1.
strokeWeightnumberNoOutline width of drawn rectangles in pixels.

Events​

NameSignatureWhen it fires
getInfoWindowContent((key: string, data: any) => ReactNode)Returns the content of the popup that opens when a marker or route endpoint is clicked. Called with the group key (or the endpoint's sourceKey / destinationKey) and the marker's data; the result is rendered to static HTML, so click handlers and state inside it do not work. Without it the popup shows the marker's label and its latitude and longitude.
onMapInit((map: Map) => void)Fires once with the underlying map instance after the map is created and the groups are drawn.
onDrawingCircles((circles: { lat: number; lng: number; radius: number; }[]) => void)Fires with every circle drawn so far, as { lat, lng, radius } (radius in metres), after a circle is drawn or an editable one is changed.
onDrawingRectangles((rectangles: { northEast: { lat: number; lng: number; }; southWest: { lat: number; lng: number; }; }[]) => void)Fires with every rectangle drawn so far, as { northEast, southWest } corners, after a rectangle is drawn or an editable one is changed.
onDrawingPolygons((polygons: any[]) => void)Fires with every polygon drawn so far, each as an array of { lat, lng } points, after a polygon is drawn or an editable one is changed.
onDrawingPolylines((polylines: any[]) => void)Fires with every line drawn so far, each as an array of { lat, lng } points, after a line is drawn or an editable one is changed.
onDrawingMarkers((markers: { lat: number; lng: number; }[]) => void)Fires with every marker drawn so far, as { lat, lng }, after a marker is placed.
onPlaceSelect((place: PlaceResult) => void)Fires with the first matching place when the user picks a search result. Requires enableSearch.
onEditGeoFenceGroups((geofenceGroups: { key: string; type: "circle" | "polygon"; center?: { lat: number; lng: number; }; radius?: number; path?: { lat: number; lng: number; }[] | undefined; strokeColor?: string | undefined; fillColor?: string | undefined; fillOpacity?: number | undefined; strokeWeight?: number |...Fires when an editable geofence is moved, resized or reshaped, with only the geofences edited so far: { key, type, center, radius } for circles and { key, type, path } for polygons. Also fires with an empty array whenever geofenceGroups changes, including on first render.

Children​

Map does not accept children.

Variants​

Loading examples…

Playground​

Change the controls to see how the properties affect the component. Values the controls don't cover come from the Default example.

Loading playground…

Storybook​

Open Map in Storybook to try every story with the full set of controls.