The map components in Reflex Enterprise provide interactive mapping capabilities built on top of Leaflet, one of the most popular open-source JavaScript mapping libraries. These components enable you to create rich, interactive maps with markers, layers, controls, and event handling.
🌍 View Live Demo - See the map components in action with interactive examples.
Map components are included with reflex-enterprise
. No additional installation is required.
Here's a simple example of creating a map with a marker:
The rxe.map()
component is the primary container that holds all other map elements:
Key Properties:
center
: Initial map center coordinateszoom
: Initial zoom level (0-18+ depending on tile provider)bounds
: Alternative to center/zoom, fits map to boundsheight
/width
: Map container dimensions
Tile layers provide the base map imagery. The most common is OpenStreetMap:
Add point markers to specific locations:
Draw shapes and areas on the map:
Maps support comprehensive event handling for user interactions:
Last click: No clicks yet
Current zoom: 13
Add UI controls for enhanced user interaction:
The Map API provides programmatic control over your maps, allowing you to manipulate the map programmatically from your Reflex state methods.
To access the Map API, you need to get a reference to your map using its ID:
Here are some commonly used API methods demonstrated in action:
Current location: London
View Control:
fly_to(latlng, zoom, options)
- Smooth animated movement to locationset_view(latlng, zoom, options)
- Instant movement to locationset_zoom(zoom)
- Change zoom levelzoom_in()
/zoom_out()
- Zoom by one levelfit_bounds(bounds, options)
- Fit map to specific bounds
Location Services:
locate(options)
- Get user's current locationstop_locate()
- Stop location tracking
Information Retrieval:
get_center(callback)
- Get current map centerget_zoom(callback)
- Get current zoom levelget_bounds(callback)
- Get current map boundsget_size(callback)
- Get map container size
Layer Management:
add_layer(layer)
- Add a layer to the mapremove_layer(layer)
- Remove a layer from the maphas_layer(layer)
- Check if layer exists on map
This means you can use any method from the Leaflet Map documentation. For example:
Python (snake_case) → JavaScript (camelCase):
map_api.pan_to(latlng)
→map.panTo(latlng)
map_api.set_max_bounds(bounds)
→map.setMaxBounds(bounds)
map_api.get_pixel_bounds()
→map.getPixelBounds()
map_api.container_point_to_lat_lng(point)
→map.containerPointToLatLng(point)
Status: Location tracking disabled
Constraints: None
Many API methods that retrieve information require callbacks to handle the results:
The map components support a comprehensive set of events:
Map Events:
on_click
,on_dblclick
- Mouse click eventson_zoom
,on_zoom_start
,on_zoom_end
- Zoom eventson_move
,on_move_start
,on_move_end
- Pan eventson_resize
- Map container resizeon_load
,on_unload
- Map lifecycle
Location Events:
on_locationfound
,on_locationerror
- Geolocation
Layer Events:
on_layeradd
,on_layerremove
- Layer management
Popup Events:
on_popupopen
,on_popupclose
- Popup lifecycleon_tooltipopen
,on_tooltipclose
- Tooltip lifecycle
- Always include attribution for tile providers
- Set reasonable zoom levels (typically 1-18)
- Use bounds for multiple markers instead of arbitrary center/zoom
- Handle loading states for dynamic map content
- Optimize marker rendering for large datasets using clustering
- Test on mobile devices for touch interactions