Overview
MapChart is the main class for creating map visualizations in amCharts 5. It extends SerialChart and provides functionality for displaying geographic data with various projections, zoom controls, and pan/zoom interactions.
Creating a MapChart
Settings
Projection
A projection to use when plotting the map. See the Projections page for available options.
Zoom and Position
Current zoom level of the map.
Lowest zoom level the map is allowed to zoom out to.
Highest zoom level the map is allowed to zoom in to.
Increment zoom level by this value when user zooms in via ZoomControl or API.
Current x position of the map.
Current y position of the map.
Rotation
Horizontal centering of the map. Use with projections that support rotation.See Centering the map for more info.
Vertical centering of the map. Use with projections that support rotation.
Depth centering of the map. Use with projections that support rotation.
Pan Behavior
Defines what happens when map is dragged horizontally.
"none"- No panning"rotateX"- Rotate the globe"translateX"- Translate the map
Defines what happens when map is dragged vertically.
How much of a map can go outside the viewport (0-1 where 0.4 = 40%).See Panning outside viewport for more info.
Wheel Behavior
Defines what happens when mouse wheel is turned.See Mouse wheel behavior for more info.
Defines what happens when horizontal mouse wheel is turned (only some mice support this).
Sensitivity of mouse wheel. This setting is ignored when wheelX or wheelY is set to “zoom”.
Duration of mouse-wheel action animation in milliseconds. This setting is ignored when wheelX or wheelY is set to “zoom”.
An easing function to use for mouse wheel action animations. This setting is ignored when wheelX or wheelY is set to “zoom”.See Easing functions for more info.
Pinch Zoom
Enables pinch-zooming of the map on multi-touch devices.See Pinch zoom for more info.
Animation
Duration of zoom/pan animations in milliseconds.
An easing function to use for zoom/pan animations.See Easing functions for more info.
Home Position
Initial/home zoom level.See Initial position and zoom for more info.
Initial/home rotationX.
Initial/home rotationY.
Initial coordinates to center map on load or
goHome() call.If
true, the map will automatically center itself (or go to homeGeoPoint if set) when fully zoomed out.If false, zoom out will be centered around the mouse cursor (when zooming using wheel), or current map position.Zoom Control
Methods
Zoom Methods
Zooms the map in by the
zoomStep amount.Zooms the map out by the
zoomStep amount.Zooms the map to a specific screen point.
zoomToGeoPoint(geoPoint, level, center?, duration?, rotationX?, rotationY?)
Animation<number> | undefined
Zooms the map to a specific geographical point.
Zooms the map to fit geographical bounds.
Repositions the map to the “home” zoom level and center coordinates.See Resetting position/level for more info.
Rotation Methods
Rotates the map (for projections that support rotation).
Animates the map projection transition from the current projection to the target projection.Since d3-geo does not expose raw projection functions on projection instances, you must pass both the target
GeoProjection and its corresponding GeoRawProjection. On the first call you must also pass sourceRaw so the method knows the current projection’s raw function.Coordinate Conversion
Converts latitude/longitude to screen coordinates (X and Y).
Converts screen coordinates (X and Y) to latitude and longitude.
Information Methods
Returns the geoPoint of the current zoom position.You can use this to restore zoom position:
chart.zoomToGeoPoint(geoPoint, zoomLevel, true)Returns coordinates to the geographical center of the map.
Returns geographical bounds of the map.Returns an object with
left, right, top, bottom properties.Returns geographical coordinates for calculated or manual center of the map.
Returns area of a MapPolygon in square pixels.
Events
Invoked when geo bounds of the map change, usually after map is initialized.