---
url: 'https://d3-maps.netlify.app/api/core.md'
---
# @d3-maps/core
## Modules
* [annotation](annotation.md)
* [feature](feature.md)
* [graticule](graticule.md)
* [line](line.md)
* [map](map.md)
* [mapObject](mapObject.md)
* [marker](marker.md)
* [utils](utils.md)
* [zoom](zoom.md)
---
---
url: 'https://d3-maps.netlify.app/api.md'
description: API docs entry point for generated d3-maps core docs and local TypeDoc pages
---
---
---
url: 'https://d3-maps.netlify.app/components.md'
description: >-
D3 SVG map components in React and Vue: MapBase, MapFeatures, MapMarker,
MapZoom, and MapGraticule
---
# Components
Components are adapter-level building blocks for rendering map layers
* [MapBase](/components/map-base)
* [MapFeatures](/components/map-features)
* [MapFeature](/components/map-feature)
* [MapAnnotation](/components/map-annotation)
* [MapLine](/components/map-line)
* [MapMarker](/components/map-marker)
* [MapMesh](/components/map-mesh)
* [MapGraticule](/components/map-graticule)
* [MapZoom](/components/map-zoom)
Need helpers for custom layers and interactions?
* [Helpers](/helpers/)
---
---
url: 'https://d3-maps.netlify.app/guide/core-concepts.md'
description: >-
Core concepts for D3 SVG maps in React and Vue, including projections,
features, mesh, markers, zoom, and responsive rendering
---
# Core concepts
Let's build the map step by step to understand how the library works
## Data
[MapBase](/components/map-base) accepts either GeoJSON or TopoJSON and then transforms it into GeoJSON.\
Both used for geo data encoding, but **TopoJSON is recommended**, it's smaller.
Simply pass `data` prop to render the basic map
:::tabs key:framework
\== Vue
```vue [vue]
```
\== React
```tsx [react]
```
:::
## Data transformation
Add `dataTransformer` to preprocess GeoJSON features before render
```ts
// e.g. don't render Antarctica ๐ฆ๐ถ
function dataTransformer(features) {
return features.filter((x) => x.properties?.name !== 'Antarctica')
}
```
:::tabs key:framework
\== Vue
```vue{4} [vue]
```
\== React
```tsx{3} [react]
```
:::
## Projection
A map projection transforms the Earth's 3D curved surface into SVG map.\
It determines how exactly map will look.
By default `geoNaturalEarth1` is used in core, but you can provide your own:
:::tabs key:framework
\== Vue
```vue{2,9} [vue]
```
\== React
```tsx{1,6} [react]
import { geoEquirectangular } from 'd3-geo'
```
:::
::: details
* You can tweak a projection with [MapBase.projectionConfig](/components/map-base#props) (defaults are strong though)
* Projections are available in [d3-geo](https://github.com/d3/d3-geo) and [d3-geo-projection](https://github.com/d3/d3-geo-projection)
* Here you can see [visualized projections](https://observablehq.com/@fil/d3-projections)
:::
## Features
Map feature is geographic entity, e.g. country or state.\
[MapFeatures](/components/map-features) render all features internally, [MapFeature](/components/map-feature) renders a single one.\
Switch to slot/render-function when each feature needs custom render logic.
:::tabs key:framework
\== Vue
```vue{7-15} [vue]
```
\== React
```tsx{6-17} [react]
{({ features }) => (
<>
{features.map((feature) => (
))}
>
)}
```
:::
## Mesh
To render borders use [MapMesh](/components/map-mesh) instead of applying `stroke`. It will render a single `` (more efficient) and ensure borders don't overlap.
:::tabs key:framework
\== Vue
```vue{8} [vue]
```
\== React
```tsx{7} [react]
```
:::
> Default stroke width is 0.5
## Graticule
Use [MapGraticule](/components/map-graticule) to draw latitude and longitude grid lines
:::tabs key:framework
\== Vue
```vue{7} [vue]
```
\== React
```tsx{6} [react]
```
:::
## Zoom
Wrap layers with [MapZoom](/components/map-zoom) to enable pan and zoom
:::tabs key:framework
\== Vue
```vue{7,11} [vue]
```
\== React
```tsx{6,10} [react]
```
:::
> Detailed zoom [usage example](/examples/zoom)
## Markers
Add any points to the map with [MapMarker](/components/map-marker)
* pass `coordinates` as `[longitude, latitude]`
* and any SVG elements as a children
:::tabs key:framework
\== Vue
```vue{11-18} [vue]
Sweet home ๐งก
```
\== React
```tsx{10-17} [react]
Sweet home ๐งก
```
:::
## Styling
[MapFeature](/components/map-feature)\*, [MapMarker](/components/map-marker), [MapMesh](/components/map-mesh), [MapGraticule](/components/map-graticule), [MapLine](/components/map-line), and [MapAnnotation](/components/map-annotation) accept a `styles` prop
```ts
const styles = {
default: { fill: 'lightblue' }, // default state
hover: { fill: 'skyblue' }, // on hover
active: { fill: 'lightskyblue' }, // on mousedown
}
```
:::tabs key:framework
\== Vue
```vue{9} [vue]
Sweet home ๐งก
```
\== React
```tsx{8} [react]
Sweet home ๐งก
```
:::
> \* [MapFeatures](/components/map-features) forwards `styles` to internally rendered `MapFeature`'s
### CSS
1. Import [default stylesheet](https://github.com/souljorje/d3-maps/blob/main/packages/core/src/index.css) to simplify global map styles
:::tabs key:framework-css
\== Vue
```ts
import '@d3-maps/vue/index.css'
```
\== React
```ts
import '@d3-maps/react/index.css'
```
:::
2. Define styles for map components with plain CSS
| Component | CSS selector |
| --- | --- |
| [MapBase](/components/map-base) | `.d3-map` |
| [MapFeature](/components/map-feature) | `[name="feature"]` |
| [MapMesh](/components/map-mesh) | `[name="mesh"]` |
| [MapMarker](/components/map-marker) | `[name="marker"]` |
| [MapGraticule](/components/map-graticule) lines | `[name="graticule"]` |
| [MapGraticule](/components/map-graticule) border | `[name="border"]` |
| [MapGraticule](/components/map-graticule) background | `[name="background"]` |
| [MapLine](/components/map-line) | `[name="line"]` |
| [MapAnnotation](/components/map-annotation) connector | `[name="annotation-line"]` |
| [MapZoom](/components/map-zoom) | `[name="zoom"]` |
See example (this site) [packages/docs/.vitepress/theme/custom.css](https://github.com/souljorje/d3-maps/blob/main/packages/docs/.vitepress/theme/custom.css)
## Responsiveness
Simply make it with an aspect-ratio wrapper and the `aspect-ratio` prop
:::tabs key:framework
\== Vue
```vue{2,7} [vue]
Sweet home ๐งก
```
\== React
```tsx{1,6} [react]
Sweet home ๐งก
```
:::
::: details
[MapBase](/components/map-base) renders an `