Bertin.js is a JavaScript library for visualizing geospatial data and make thematic maps for the web.
The project is under active development. Some of features and options are subject to change. We welcome contributions of all kinds: bug reports, code contributions and documentation. A todo list of the next improvements is available here.
bertin
is an easy to use JavaScript library mainly based on D3.js makes creating thematic maps simple. The principle is to work with layers stacked on top of one other. Much like in Geographic Information Software (GIS) software, Bertin.js displays layers with a specific hierarchy. The layer at bottom are rendered and then followed by the layer right above it. Some of the layers are used to display various components of a map, some of common layers are: header, footer, graticule, outline, choro, typo, prop, shadow, scalebar, text etc.
draw()
function is the most important function of the library. It allows you to draw all types of maps.update()
function allows you to modify specific elements of the map without the need to redraw everything. Only the parameters underlined in the documentation can be modified through this function.Jacques Bertin (1918-2010) was a French cartographer, whose major contribution was a theoretical and practical reflection on all graphic representations (diagrams, maps and graphs), forming the subject of a fundamental treatise, Graphic Semiology, originally published in 1967. Bertin’s influence remains strong not only in academics, teaching of cartography today, but also among statisticians and data visualization specialists.
Latest version
<script
src="https://cdn.jsdelivr.net/npm/bertin"
charset="utf-8"
></script>
Pinned version
<script src="https://cdn.jsdelivr.net/npm/bertin@1.7" charset="utf-8"></script>
Latest version
bertin = require("bertin");
Pinned version
bertin = require("bertin@1.7");
In Quarto, you can use bertin
with ojs cells. This allows to combine analyses in R or Python with visualizations made with bertin
. An example is available here
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<script src="https://cdn.jsdelivr.net/npm/bertin"></script>
<script>
let geojson =
"https://raw.githubusercontent.com/neocarto/bertin/main/data/world.geojson";
d3.json(geojson).then((r) =>
document.body.appendChild(
bertin.draw({
params: {
projection: "VanDerGrinten4",
clip: true,
},
layers: [
{ geojson: r, tooltip: ["$ISO3", "$NAMEen"] },
{ type: "outline" },
{ type: "graticule" },
],
})
)
);
</script>
See examples: Example 1, Example 2 and Example 3.
The bertin.js library is really easy to use within an Observable notebook. You’ll find many examples in this notebook collection. Feel free to fork, copy, modify with your own data.
draw() is the main function of the library. It allows you to make various thematic maps. It allows to display and overlay different types of layers listed below. The layers written on top are displayed first. Source Example
In the section params, we define the global parameters of the map: its size, projection, background color, etc. To have access to a large number of projections, you will need to load the d3-geo-projection\@4 library. This section is optional.
bertin.draw({
params: {
projection: d3.geoBertin1953(),
width: 750,
},
layers: [...]
})
A globe view is available for some types of layers: simple
(with symbol_shift == 0), spikes
, bubble
(with dorling == true), geolines
, graticule
, inner
, missing
, shadow
, tissot
, dotdensity
and label
.
To use it, you juste have to use "globe"
as projection. You can also define the center og the map by using "globe(x,y,rotate)"
[[112, -43],[153, -9]]
(default: null)The layer type allows to display a simple geojson layer (points, lines or polygons). Source. Example 1 and Example 2.
bertin.draw({
layers: [
{
type: "layer",
geojson: *a geojson here*,
fill: "#e6acdf",
}
]
})
geojson: a geojson (compulsory)
rewind: a boolean. If true, the geojson is rewinded for a proper display (default: false)
fill color (default: a random color)
stroke color (default: “white”)
strokeWidth
stroke width (default:0.5)
stroke-linecap (default:”round”)
stroke-linejoin (default:”round”)
stroke-dasharray (default:”none”)
fill opacity (default:1)
stroke opacity (default:1)
if it is a dot layer, the type of symbol. “circle”, “cross”, “diamond”, “square”, “star”, “triangle”, “wye” (default: “circle”)
if it is a dot layer, a number indicating the size of the symbol (default: 5)
symbol_shift: if it is a dot layer, use a value > 0 to switch symbols and avoid overlay (default: 0)
symbol_iteration: Number of iteration to shift symbols (default: 200)
Parameters of the legend
The choro type aims to draw Choropleth maps. This kind of representation is especially suitable for relative quantitative data (rates, indices, densities). The choro type can be applied to the fill or stroke property of a simple layer. Example.
bertin.draw({
layers: [
{
type: "layer",
geojson: data,
fill: {
type: "choro",
values: "gdppc",
nbreaks: 5,
method: "quantile",
colors: "RdYlGn",
leg_round: -1,
leg_title: `GDP per inh (in $)`,
leg_x: 100,
leg_y: 200
}
]
})
a string corresponding to the targeted variable in the properties (compulsory)
Number of classes (default:5)
Class breaks (default:null)
An array of colors or a palette of colors (Blues”, “Greens”, “Greys”, “Oranges”, “Purples”, “Reds”, “BrBG”, “PRGn”, “PiYG”, “PuOr”, “RdBu”, “RdYlBu”, “RdYlGn”, “Spectral”,”Turbo”,”Viridis”,”Inferno”, “Magma”, “Plasma”, “Cividis”, “Warm”, “Cool”, “CubehelixDefault”, “BuGn”, “BuPu”, “GnBu”, “OrRd”, “PuBuGn”, “PuBu”, “PuRd”, “RdPu”, “YlGnBu”, “YlGn”, “YlOrBr”, “YlOrRd”, “Rainbow”, “Sinebow”. default: Blues) See
A method of classification. “quantile”, “q6”, “equal”, “msd” (mean standard deviation), “jenks”, “geometric”, “headtail” or “pretty” (default: “quantile”). See statsbreaks example for method implementation in action.
for msd method only. middle class or not (default:false);
for msd method only. number of sd. (default:1);
Color for missing values (default “#f5f5f5”)
Text for missing values (default “No data”)
stroke color (default: “white”)
Stroke width (default: 0.5)
Fill opacity (default: 1)
Parameters of the legend
position in x (if this value is not filled, the legend is not displayed)
position in y (if this value is not filled, the legend is not displayed)
width of the box (default: 30)
height of the box (default:20)
text of the box (default: “leg_text”)
text font size (default: 10)
color of the box (same as the layer displayed)
stroke of the box (default: “black”)
stroke-width (default: 0.5)
stroke opacity (same as the layer displayed)
color of the text (default: “#363636”)
Number of digits (default: undefined)
The typo type allows to realize a qualitative map. The choro type can be applied to the fill or stroke property of a simple layer. Example.
bertin.draw({
layers: [
{
type: "layer",
geojson: data,
fill: {
type: "typo",
values: "region",
pal: "Tableau10",
tooltip: ["$region", "$name"],
leg_title: `The Continents`,
leg_x: 55,
leg_y: 180
}
}
]
})
a string corresponding to the targeted variable in the properties (compulsory)
An array containing n colors for n types, or a a palette of categorical colors (default: “Tableau10”). See the handy color scheme reference for full list of palettes.
an array of values to set the order of the colors
Color for missing values (default “#f5f5f5”)
Text for missing values (default “No data”)
stroke color (default: “white”)
Stroke width (default: 0.5)
Fill opacity (default: 1)
Parameters of the legend
position in x (if this value is not filled, the legend is not displayed)
position in y (if this value is not filled, the legend is not displayed)
width of the box (default: 30)
height of the box (default:20)
title of the legend (default; null)
title legend font size (default: 14)
values font size (default: 10)
stroke of the box (default: “black”)
stroke-width (default: 0.5)
stroke opacity (same as the layer displayed)
color of the text (default: “#363636”)
The bubble type is used to draw a map by proportional circles. Source, Example.
bertin.draw({
layers: [
{
type: "bubble",
geojson: countries,
values: "pop",
k: 60,
tooltip: ["$country", "$pop", "(inh.)"],
},
],
});
geojson: a geojson (compulsory)
rewind: a boolean. If true, the geojson is rewinded for a proper display (default: false)
a string corresponding to the targeted variable in the properties(compulsory)
size of the largest circle (default:50)
fixmax: Max value to fix the size of the biggest circle, in order to make maps comparable (default:undefined)
fill color (default: random color)
stroke color (default: “white”)
stroke width (default: 0.5)
fill opacity (default: 1)
a boolean (default:false)
iteration: an integer to define the number of iteration for the Dorling method (default: 200)
tooltip: an array of values defining what to display within the tooltip. If you use a $, the value within the geojson is displayed. Example.
Parameters of the legend
The square type is used to draw a map by proportional squares. Source, Example.
bertin.draw({
layers: [
{
type: "square",
geojson: countries,
values: "pop",
k: 60,
tooltip: ["$country", "$pop", "(inh.)"],
},
],
});
geojson: a geojson (compulsory)
rewind: a boolean. If true, the geojson is rewinded for a proper display (default: false)
a string corresponding to the targeted variable in the properties(compulsory)
size of the largest circle (default:50)
fixmax: Max value to fix the size of the biggest circle, in order to make maps comparable (default:undefined)
fill color (default: random color)
stroke color (default: “white”)
stroke width (default: 0.5)
fill opacity (default: 1)
a boolean to avoid overlay. Dorling parameter works also (default:false) - EXPERIMENTAL
iteration: an integer to define the number of iteration for the Dorling method (default: 200)
tooltip: an array of values defining what to display within the tooltip. If you use a $, the value within the geojson is displayed. Example.
Parameters of the legend
The regularbubble type is used to draw a map by proportional circles in a regular grid, from absolute quantitative data. Source, Example and methodology.
bertin.draw({
layers: [
{
type: "regularbubble",
geojson: countries,
step:20,
values: "pop",
k: 60,
tooltip: "$value",
},
],
});
All other parameters are the same as for the bubble layer
The regularsquare type is used to draw a map by proportional squares in a regular grid, from absolute quantitative data. Source, Example and methodology.
bertin.draw({
layers: [
{
type: "regularsquare",
geojson: countries,
step:20,
values: "pop",
k: 60,
tooltip: "$value",
},
],
});
All other parameters are the same as for the square layer
The regulargrid type is a way to transform an irregular geographic mesh into a regular mesh. The values of the grid cells are obtained in proportion to the intersected surface. This representation mode is only suitable for absolute quantitative data. But you can use 2 quantitative data to compute a ratio Source, Example and methodology.
bertin.draw({
layers: [
{
type: "regulargrid",
geojson: countries,
step:20,
values: "pop",
fill:{
nbreaks: 6,
method: "quantile",
colors: "Blues"
}
tooltip: "$value",
},
],
});
All other parameters are the same as for choropleth maps
In thematic mapping, we often have to represent an absolute quantitative data with a size variation and relative quantitative data with color variations. For this we can use the bubble type and the choro type together. Example.
bertin.draw({
params: { projection: d3.geoPolyhedralWaterman() },
layers: [
{
type: "bubble",
geojson: data,
leg_round: -2,
values: "pop",
fill: {
type: "choro",
method: "quantile",
nbreaks: 5,
values: "gdppc",
pal: "RdYlGn",
},
},
],
});
In thematic mapping, we often have to represent an absolute quantitative data with a size variation and relative quantitative data with color variations. For this we can use the bubble type and the typo type together. Example.
bertin.draw({
layers: [
{
type: "bubble",
geojson: data,
values: "pop",
fill: {
type: "typo",
values: "region",
},
},
],
});
The dorling parameter can be used with the bubble type to design a Dorling cartogram. Example.
bertin.draw({
layers: [
{
type: "bubble",
geojson: data,
values: "pop",
k: k,
dorling: true,
iteration: 100,
fill: "#E95B40",
},
],
});
The dotcartogram type is a method of map representation that follows Dorling’s cartograms and dot density maps. The data from each territorial unit are dissolved in such a way that a dot represents a constant quantity, the same on the whole map. Source Example.
bertin.draw({
params: { projection: d3.geoBertin1953() },
layers: [
{
type: "dotcartogram",
geojson: data,
onedot: 200000000000,
iteration: 200,
values: "gdp",
radius: radius,
span: span,
leg_fill: "none",
leg_stroke: "black",
leg_strokeWidth: 1.5,
leg_x: 800,
leg_y: 450,
leg_title: `GDP by world region`,
leg_txt: "200 billion $",
fill: "red",
tooltip: ["$name", "$region"],
},
],
});
Parameters of the legend
The mushroom type is used to draw a map with 2 superposed proportional semi-circles. This type of representation can be used when two data with the same order of magnitude need to be compressed. Source, Example.
bertin.draw({
layers: [
{
type: "mushroom",
geojson: mygeojson,
top_values: "gdp_pct",
bottom_values: "pop_pct",
bottom_tooltip: ["name", "pop", "(thousands inh.)"],
top_tooltip: ["name", "gdp", "(million $)"],
},
],
});
Parameters of the legend
The dotdensity type allows to display a doty density layer geojson layer from polygons and attribute data. Source. Example
bertin.draw({
layers: [
{
type: "dotdensity",
geojson: *a geojson here (polygon)*,
values: *a fiel here*
dotvalue: *a number*,
}
]
})
Parameters of the legend
The spikes type is used to draw a map with spikes. Source, Example.
bertin.draw({
layers: [
{
type: "spikes",
geojson: countries,
values: "pop",
k: 60,
w: 8,
tooltip: ["$country", "$pop", "(inh.)"],
},
],
});
geojson: a geojson (compulsory)
rewind: a boolean. If true, the geojson is rewinded for a proper display (default: false)
a string corresponding to the targeted variable in the properties(compulsory)
height of the highest peak (default:50)
w: width of the spikes (default:10)
fill color (default: #a31d88)
stroke color (default: #a31d88)
stroke width (default: 0.7)
fill opacity (default: 0.3)
tooltip an array of values defining what to display within the tooltip. If you use a $, the value within the geojson is displayed.
Parameters of the legend
The ridge type allows to produce 2.5D maps by varying the height of lines. The method takes as input polygons or multi polygons. Source Example.
bertin.draw({
layers: [
{
type: "ridge",
geojson: data,
values: "pop",
step: 30,
blur: 0.4,
k: 50
},
],
});
geojson: a geojson (compulsory)
rewind: a boolean. If true, the geojson is rewinded for a proper display (default: false)
values: a string corresponding to the targeted variable in the properties
stroke color (default: “white”)
strokeWidth stroke width (default: 0.5)
fill opacity (default: 1)
stroke opacity (default: 1)
stroke-dasharray (default: “none”)
step: Gap between the points (default: 20)
k: Height of lines (default: 100)
operator: “sum” for absolute quantitative data or “mean” for relative data (default: “mean”)
geoprocessing: “intersection” (intersection between polygons and grid squares. Assignment of values in proportion to the intersected area) or “dotinpoly” (considers each grid square and assigns the value of the underlying polygon or the weighted average of intersecting polygons. ). (Default: “dotinpoly”)
The smooth type (or heatmap or contour) is a way to produce a continuous représentations from quantitative data. The algorithm is complex. The values produced do not really make sense. Explanations with the parameters. Source, Example and methodology.
bertin.draw({
layers: [
{
type: "smooth",
geojson: data,
values: "pop",
thresholds: 50,
bandwidth: 25,
colorcurve: 1,
},
],
});
Contour parameters
By default, the smooth layer is calculated from dots or centroids. But it is possible to go through a regular grid by using theses parameters.
On each layer, you can dynamically vary the thickness of the paths. This can be useful to make for example flow maps or discontinuity maps. Source
In order for each object to have the same thickness.
bertin.draw({
layers: [
{
type: "layer",
geojson: *a geojson here*,
strokeWidth: 3,
}
]
})
To vary the thickness proportionally to an quantitative data.
bertin.draw({
layers: [
{
type: "layer",
geojson: *a geojson here*,
strokeWidth: {type:"linear",values:"migration"},
}
]
})
a string corresponding to the targeted variable in the properties(compulsory)
thicken with the largest line (default:10)
Max value to fix the size of the thickest line, in order to make maps comparable (default:undefined)
Min value to fix the size of the thinest line. If true, the value is the min data. (default:0)
To vary the thickness according to classes values
bertin.draw({
layers: [
{
type: "layer",
geojson: *a geojson here*,
strokeWidth: {type:"discr",values:"migration", method: "q6"},
}
]
})
a string corresponding to the targeted variable in the properties(compulsory)
thicken with the largest line (default:10)
Number of classes (default:5)
Class breaks (default:null)
A method of classification. “quantile”, “q6”, “equal”, “msd”, “jenks”, “geometric”, “headtail” or “pretty” (default: “quantile”).
for msd method only. middle class or not (default:false).
an array definig the sizes of each classes.
for msd method only. number of sd. (default:1)
an array of thicknesses.
To vary the thickness according to qualitative data.
bertin.draw({
layers: [
{
type: "layer",
geojson: *a geojson here*,
strokeWidth: {type:"quali",values:"flow", categories: ["low", "medium", "high", "very high"]},
}
]
})
a string corresponding to the targeted variable in the properties(compulsory)
thicken with the largest line (default:10)
an array containing categories
an array definig the sizes of each classes.
for msd method only. number of sd. (default:1)
an array of thicknesses.
position in x (if this value is not filled, the legend is not displayed)
position in y (if this value is not filled, the legend is not displayed)
width of the lines (default: 30)
text of the box (default: “leg_text”)
text font size (default: 10)
color of the box (same as the layer displayed)
stroke of the box (default: “black”)
stroke-width (default: 0.5)
stroke opacity (same as the layer displayed)
color of the text (default: “#363636”)
Number of digits (default: undefined)
The footer type allows to display text under the map. This is useful to display sources. Source.
bertin.draw({
layers: [
{
type: "footer",
text: "Source: Worldbank, 2021",
fontSize: 10,
},
],
});
text to be displayed (default:””)
anchor: text anchor. start, middle, end (default:”end”)
fontSize: size of the text (default:15)
fill: color of the text (default:”#9e9696”)
background: background color (default: “white”)
The geolines type allows you to display geographic lines (equator, tropics, polar circles). Source.
bertin.draw({
layers: [
{
type: "geolines",
stroke: "black",
strokeWidth: [5, 3, 1],
},
],
});
For each parameter, you can set a single value for all lines are an array in that order: [equator, tropics, polar].
stroke color (default: “#020e21”)
strokeWidth: stroke width (default: [1.5, 1.2, 0.7])
stroke opacity (default: 1)
strokeDasharray: stroke-dasharray (default: [“none”, 5, 3])
stroke-linecap (default: “butt”)
The graticule type allows you to display the latitude and longitude lines around . Source.
bertin.draw({
layers: [
{
type: "graticule",
stroke: "#644580",
step: [20, 10],
},
],
});
stroke color (default:”white”)
stroke width (default:0.8)
stroke opacity (default:0.5)
stroke-dasharray (default:2)
step: gap between graticules. The value can be a number or an array of two values (default: [10, 10])
The hatch type only allows to add hatchings on the whole page to make it a bit prettier. Source.
bertin.draw({
layers: [
{
type: "hatch",
angle: 45,
},
],
});
The inner type allows to display a strip inside the polygon. This inner area can be used to draw preet maps with a vintage style.
bertin.draw({
layers: [
{
type: "inner",
thickness: 5,
fill:"white",
blur:4
},
],
});
The minimap type (or location) allows to display a location map showing the coverage of the map. Source. Example
bertin.draw({
layers: [
{
type: "minimap",
x: 50,
y: 50,
width:300,
frame:{fill: "yellow", stroke: "none"}
},
],
});
The rhumbs type allows to display “rhumb lines” like on old portolan charts. Source.
bertin.draw({
layers: [
{
type: "rhumbs",
position: [370, 370],
nb: 25
},
],
});
number of lines (default: 10)
position of the center in x and y (default: [height / 4, width - width / 4])
stroke color (default: “#786d6c”)
stroke color (default: 2)
stroke-opacity (default: 45)
stroke-dasharray (default:”none”)
The waterlines type only allows to display lines spaced by a defined distance. It’s just a graphic trick to make the maps look nice. Source.
bertin.draw({
layers: [
{
type: "waterlines",
geojson: world,
dist: 100,
nb: 5
},
],
});
The logo type only allows allows to display a logo on the map from an url. By default, the bertin.js logo is displayed. Source Example.
bertin.draw({
layers: [
{
type: "logo",
url: "http://myimage.png"
position: "left",
},
],
});
The header type allows to display a title above the map. Source.
bertin.draw({
layers: [
{
type: "header",
text: "Title of the map",
fontSize: 40,
},
],
});
text to be displayed (default:””)
anchor: text anchor. start, middle, end (default:”middle”)
fontSize: size of the text (default:20)
fill: color of the text (default:”#9e9696”)
background: background color (default: “white”)
The label type allows to display labels from a geojson. Source, Example.
bertin.draw({
layers: [
{
type: "label",
geojson: countries,
values: "name",
},
],
});
The missing type displays any missing data when creating a map by proportional symbols. The highlight of graphical elements (in white under the symbols) allows for clear data comprehension of gaps in data. Source.
bertin.draw({
layers: [
{
type: "missing",
geojson: countries,
values: "pop"
]
})
Parameters of the legend
The outline type is used to display the limits of the earth area in the given projection. Source.
bertin.draw({
layers: [
{
type: "outline",
fill: "#4269ad",
},
],
});
The path type is used to display any svg path Source Example
bertin.draw({
layers: [
{
type: "path",
d: "m 99.330229,64.978319 -9.724281,-1.057429 -3.946379,8.950188 -3.94638,-8.950188 -9.72428,1.057429 5.7779,-7.89276 -5.7779,-7.892759 9.72428,1.05743 3.94638,-8.950189 3.94638,8.950189 9.72428,-1.057429 -5.777901,7.892759 z",
fill:"blue",
sroke: "none",
scale: 2
},
],
});
The scalebar type allows to display a scale bar in miles or kilometers. Source.
bertin.draw({
layers: [
{
type: "scalebar",
units: "miles",
},
],
});
The shadow type allows to display a shadow under a layer to give it a relief effect. Source.
bertin.draw({
layers: [
{
type: "shadow",
geojson: JPN,
dx: 5,
dy: 5,
},
],
});
color (default: “#35383d”)
shift in x (default: 3)
shift in y (default: 3)
stdDeviation: blur (default: 1.5)
opacity (default: 0.7)
The text type simply allows you to display text anywhere on the map. Source. Example.
bertin.draw({
layers: [
{
type: "text",
text: "This is my text",
position: "bottomright",
fontSize: 20,
frame_stroke: "red",
margin: 4,
},
],
});
The tiles type allow to display a raster basemap. Source. Example.
NB: It works only with the d3.geoMercator() projection. if tiles layer is used is the draw function, the projection is automaticaly setted to d3.geoMercator(). And you can’t change it.
bertin.draw({
params: {
projection: d3.geoMercator(),
extent: *a geojson*
},
layers: [
{
type: "tiles",
style: "worldphysical"
},
],
});
style: {
provider: "OpenStreetMap contributors",
url: (x, y, z) => `https://tile.openstreetmap.org/${z}/${x}/${y}.png`,
}
The tissot type aims to draw Tissot circles to visualize the deformations due to the projection Source.
bertin.draw({
layers: [
{
type: "tissot",
step: 20
},
],
});
step between circles
fill (default: “#d91848”)
fill-opacity (default: 0.5)
stroke (default: “#d91848”)
stroke-opacity (default: 0.6)
stroke-width (default: 1.5)
The custom type (or function type) allows you to provide your own render function to create custom layer. [Example]
bertin.draw({
layers: [
{
type: "custom",
render: function (svg, map) {
svg
.append("g")
.append("rect")
.attr("x", map.width / 2)
.attr("y", map.height / 2)
.attr("height", 100)
.attr("width", 200)
.style("fill", "red");
}
},
{ geojson: world, fill: "white" },
{ type: "graticule" },
{ type: "outline" }
]
})
Or with an external function
function drawRectangle(svg, map, options) {
const { fill, stroke, strokeWidth } = options; // Will have all options (parameters) set in the curret layer object, right?
svg
.append("g")
.append("rect")
.attr("x", map.width / 2)
.attr("y", map.height / 2)
.attr("height", 100)
.attr("width", 200)
.style("fill", fill)
.style("stroke", stroke)
.style("stroke-width", strokeWidth);
}
then:
bertin.draw({
params: { extent: world, width: 1000 },
layers: [
{
type: "function",
render: drawRectangle,
fill: "red",
stroke: "blue",
strokeWidth: 10
},
{ geojson: world, fill: "white" },
{ type: "graticule" },
{ type: "outline" }
]
})
with
map.width
: the width of the map map.height
: the height of the map
map.projection
: the projection of the map map.clipid
: the unique id of the map
properties.add allows to add a new field in the att ribute table. This function return a new object and do not modify the initial object. Example. Code.
bertin.properties.add({
geojson: world,
field: "gdppc",
expression: "gdp/pop*1000"
})
properties.filter allows to filter a geojson from its attribute table.This function return a new object and do not modify the initial object. Example. Code.
bertin.properties.filter({
x: world,
expression: "pop2022 >= 100000"
})
properties.head allows to get the n top values from a given field.This function return a new object and do not modify the initial object. Example. Code.
bertin.properties.head({
geojson: world,
field: "gdp",
nb: 5
})
properties.keep allows to select one or several columns to keep in the attribute table. All other columns are deleted. This function return a new object and do not modify the initial object. Example. Code.
bertin.properties.keep({
geojson: world,
field: ["ISO3", "pop2020"]
})
properties.remove allows to remove one or several columns in the attribute table. This function return a new object and do not modify the initial object. Example. Code.
bertin.properties.remove({
geojson: world,
field: ["tmp", "FID"]
})
properties.subset allows to remove one or several columns in the attribute table. This function return a new object and do not modify the initial object. Example. Code.
bertin.properties.subset({
geojson: world,
field: "ISO3",
selection: ["USA", "CAN", "MEX"],
inverse: false
})
properties.subset allows to get a geojson attribute table Example. Code.
bertin.properties.table(*a geojson*)
properties.tail allows to get the n bottom values from a given field. This function return a new object and do not modify the initial object. Example. Code.
bertin.properties.tail({
geojson: world,
field: "gdp",
nb: 5
})
borders is a function that extract borders from polygons, with ids. Source
bertin.borders({geojson: world, id: "iso3", values: "population", type = "rel"})
bbox computes a geojson object form an array defining an extent in latitude and longitude.
bertin.bbox([
[112, -43],
[153, -9],
]);
quickdraw function displays one or more layers directly and easily. Source, Example.
bertin.quickdraw(geojson);
bertin.quickdraw(geojson, 1000, 7);
match() is a function to evaluate the quality of a join between the data and the background map. It returns a chart. Source, Example.
let testjoin = bertin.match(countries, "ISO3_CODE", maddison, "countrycode");
.matched returns an array containing matched ids
testjoin.matched;
.matched_data returns an array containing matched data ids
testjoin.matched_data;
.unmatched_data returns an array containing unmatched data ids
testjoin.unmatched_data;
.unmatched_geom returns an array containing unmatched geom ids
testjoin.unmatched_geom;
merge is a function to join a geojson and a data file. This is the first step in the mapping process. Source, Example.
const data = bertin.merge(
countries,
"ISO3_CODE",
maddison,
"countrycode",
true
);
links is a function that create links from geometries (polygons or points) and a data file (i,j,fij). Source Example.
bertin.links({
geojson: world,
geojson_id: "ISO3",
data: migr2019,
data_i: "i",
data_j: "j",
});
Depreciated. See properties.subset/
table2geo function converts a data table with lat/lon fields or a coords field to a geojson. Source, Example.
bertin.table2geo(cities, "lat", "lng");
Or
bertin.table2geo(cities, "coords");
After creating a map, you can have access to the map info (width, total height, map height, footer height, header height, projection).
mymap = bertin.draw({
params: {
projection: d3.geoBertin1953(),
width: 750,
},
layers: [...]
})
then
mymap.info
Within Observable, you can use bertin
maps as Inputs by using viewof
. In Observable, a view is a user interface element that directly controls a value in the notebook. See explanations here: https://observablehq.com/@observablehq/views.
In bertin
, you can define which layer(s) are used by specifying the viewof parameter at the layer level. It works for simple, bubble, square, dotcartogram, mushroom, regularbubble, regularsquare, regulargrid and spikes layer.
viewof map = bertin.draw({
layers: [
{
type: "bubble",
geojson: *a geojson*,
values:"pop",
viewof: true
},
{
type: "layer",
geojson: *another geojson*,
viewof: false
}
]
})
Then
map
If you do not specify any particular layer, map will return the coordinates of the mouse cursor.
Since version 1.7 of bertin, an update function function is available. It allows you to modify specific attributes and styles without having to redraw the entire map. Not everything can be modified. Only the attributes underlined in the documentation are.
To use it, you must first create a map with the draw
function add an identifier to each layer.
map = bertin.draw({
layers: [
{
id: "mylayerid",
geojson: data,
fill: "red"
}
]
})
Then you can apply the update function linked to the map to modify the styles and attributes. example
map.update({
id: "mylayerid",
attr: "fill",
value: "blue",
duration: 1000
})
NB: The update function will also allow you to show and hide the layers of your map. See an example here.
What’s available in the bertin javascript library? What types of maps can be made? Thanks to this cheat sheet, you have an overview of the “types” available in the library. All these thumbnails are generated for real with the bertin\@1.5.9 in this notebook.