Maps
Map overlays and tiles
GeoMap markers with shapes, size and color fields, clustering with zoom or spider expansion and dragging, bubbles, data labels, curved routes with arrows, polygons, a generic XYZ tile layer with attribution, annotations and coordinate conversion.
import { GeoMap } from '@salmonui/charts/geo-map';
import '@salmonui/charts/geo-map/styles.css';
<GeoMap
layers={[{ shapes, markers: { data: cities, labelField: 'name', shape: 'balloon', cluster: true }, routes: [{ points: [[55, -4], [36, 14]], arrows: 'end' }] }]}
onMarkerClick={(ctx) => open(ctx.datum)}
/>;
Overlays belong to a layer and draw in screen space, so they keep their size while the map zooms. Layers, projections, zoom, selection and keyboard navigation are on the GeoMap page.
Markers
layer.markers is one group or an array of groups: data with
latitudeField / longitudeField (default latitude / longitude),
shape (circle, rectangle, triangle, invertedTriangle, diamond,
pentagon, star, cross, verticalLine, horizontalLine, balloon),
size or sizeField scaled into sizeRange, color or colorField, a
labelField for tooltips and the table, and render(ctx) for any React
content (an image, an icon). onMarkerClick(ctx) receives the row and its
coordinates.
markers.cluster groups markers that share a 48 px grid cell (cell
changes it) into a counted cluster; clusters are recomputed per zoom level,
so they split as you zoom in. Clicking a cluster calls
onClusterClick and zooms into it; expand: 'spider' fans its markers out
on a circle around it with connector lines instead (a click elsewhere or
Escape closes it), and expand: 'none' keeps the view.
cluster.render(ctx) draws custom cluster content.
markers.draggable lets people move the markers of a group. A
pointer drag moves the marker with a DOM transform (never React state) and
calls onMarkerMove({ markerId, layerId, groupId, index, datum, latitude, longitude }, event) once on release; the marker data is yours, so apply the
move:
const [pins, setPins] = useState(initialPins);
<GeoMap
layers={[{ shapes, markers: { id: 'pins', data: pins, labelField: 'name', draggable: true } }]}
onMarkerMove={(move) => setPins((list) => list.map((p, i) => (i === move.index ? { ...p, latitude: move.latitude, longitude: move.longitude } : p)))}
/>;
Each draggable marker also has a focusable handle (role="button" with the
role description "movable marker", named by labelField): the arrow keys
move it 8 px per press and report each step with event.source === 'keyboard', and Enter or Space clicks it.
Bubbles and labels
layer.bubbles: { valueField, radius: [min, max], shape: 'circle' | 'square', color, colorScale }draws one bubble per shape at its centroid, its area proportional to the joined value;onBubbleClickreports it.layer.labels(trueor{ field, overflow, overlap, render }) writes a label at each shape's centroid:overflow: 'hide'drops labels wider than their shape,'trim'shortens them with an ellipsis,overlap: 'hide'(default) drops labels that collide, andrender(ctx)draws custom content.
Routes and polygons
layer.routes: [{ points, curvature, arrows: 'start' | 'end' | 'both', lineStyle: 'solid' | 'dashed' | 'dotted', color, width }].layer.polygons: [{ points, color, label }]draw filled areas from[latitude, longitude]points.
Tiles
layer.tiles: { url, attribution, minZoom, maxZoom, subdomains } adds an XYZ
raster layer under the vector layers. url is a template with
{z}, {x}, {y} and optional {s}; attribution is required and always
rendered, also on the server. Tiles load on the client only (a lazy chunk
after hydration), so server HTML holds the vector layers. Follow your tile
provider's usage policy; the OpenStreetMap Foundation servers forbid heavy
use.
There is no built-in Bing or Azure Maps provider and no key flow (see the GeoMap page): build the provider URL, key included, in your application:
<GeoMap
zoom
layers={[{
shapes,
tiles: {
url: `https://tiles.example.com/{z}/{x}/{y}.png?key=${apiKey}`,
attribution: <a href="https://tiles.example.com/terms">© Example Tiles</a>,
maxZoom: 18,
},
}]}
/>;
Tile layer and draggable markers
Open demoA GeoMap with an XYZ tile layer and its required attribution under vector regions, plus delivery stops you drag with the pointer or move with the arrow keys, reported by onMarkerMove.
Delivery stops, 9 shapes, 3 markers.
| Name | Value |
|---|---|
| Northwest | |
| North | |
| Northeast | |
| West | |
| Central | |
| East | |
| Southwest | |
| South | |
| Southeast | |
| Depot | 55, -4 |
| Warehouse | 45, 6 |
| Store | 36, 14 |
Moved: none
Annotations and coordinates
annotations: [{ x, y, content, align: 'start' | 'center' | 'end' }]place React content at drawing pixels or percentages.api.toCoordinates({ x, y })andapi.toPoint([lat, lon])convert between drawing pixels and coordinates, andonMapClick({ latitude, longitude })reports the clicked position.api.fitBounds(bounds | 'markers')fits the view.
Accessibility and events
Every marker is listed in the map's accessible table, named by its
labelField; draggable markers add one focusable handle each (see above).
Overlay events: onMarkerClick(ctx) and onClusterClick(ctx) with
the row or cluster members and coordinates, onBubbleClick({ layerId, key, value, datum }), onMarkerMove(move, { source, reason }) and
onMapClick({ latitude, longitude }). Types are in the
API reference.
Markers, clusters, bubbles and routes
Open demoBalloon markers that cluster until you zoom in, bubbles sized by a data field, a curved route with an arrow, a polygon overlay, an annotation, map-click coordinates and a planar seat map.
Cities, 9 shapes, 5 markers.
| Name | population |
|---|---|
| Northwest | 12 |
| North | 30 |
| Northeast | 8 |
| West | 45 |
| Central | 60 |
| East | 22 |
| Southwest | 5 |
| South | 18 |
| Southeast | 40 |
| Alpha | 55, -4 |
| Beta | 54.6, -3.2 |
| Gamma | 45, 6 |
| Delta | 36, 14 |
| Epsilon | 51, 12 |
Seats, 12 shapes.
| Name | Value |
|---|---|
| Seat A1 | |
| Seat A2 | |
| Seat A3 | |
| Seat A4 | |
| Seat A5 | |
| Seat A6 | |
| Seat B1 | |
| Seat B2 | |
| Seat B3 | |
| Seat B4 | |
| Seat B5 | |
| Seat B6 |