1.0.5 • Published 4 years ago

eurostat-map.js v1.0.5

Weekly downloads
1
License
EUPL-1.2
Repository
github
Last release
4 years ago

eurostat-map.js

Reusable library to quickly create and customise web maps showing Eurostat data directly retrieved from Eurostat database.

Examples

Population density (see the code)
Population density map with dot pattern (see the code)
Population map with proportional circles (see the code)
Population change (see the code)
NUTS typology as a categorical map (see the code)

Documentation - API

Map creation

Create a map with var map = eurostatmap.map(); and customise it with the methods below.

Most of these methods follow the pattern map.myMethod(value): If a value is specified, the method sets the parameter value and return the map object itself. If no value is specified, the method returns the current value of the parameter.

Once the parameters have been set or changed, the map needs to be built or updated using one of these methods.

Map definition

MethodTypeDefault valueDescription
map.svgId(value)String"map"The id of the SVG element of the HTML page where to draw the map.
map.type(value)String"ch"The type of map. Possible values are "ch" for choropleth maps, "ps" for proportional symbols and "ct" for categorical maps. See below for a description of these map types.
map.width(value)int800The width of the map in pixel.
map.datasetCode(value)String"demo_r_d3dens"The Eurostat database code of the statistical variable. See here to find them.
map.filters(value)Object{ lastTimePeriod : 1 }The Eurostat dimension codes to filter/select the chosen statistical variable. See here or here to find them.
map.precision(value)int2The precision of the statistical variable to retrieve (number of decimal places).
map.csvDataSource(value)ObjectnullTo load statistical data from a CSV file, set this parameter with an object { url: "", geoCol: "", valueCol: ""} where url is the URL to get the file, geoCol is the column where the NUTS_ID is specified, and valueCol is the column containing the statistical values.
map.statData(value)Objectnull-
map.scale(value)String"20M"The simplification level of the map, among "10M", "20M", "60M". The most simplified version is "60M".
map.scaleExtent(value)Array1,3The zoom extent. The first value within 0,1 defines the maximum zoom out - the second value within 1,infinity defines the maximum zoom in. Set to null or 1,1 to forbid zooming.
map.proj(value)String"3035"The map projection EPSG code. Possible values are given in Nuts2json.
map.nutsLvl(value)int3The nuts level to show on the map, from 0 (national level) to 3 (more local level). Note that not all NUTS levels are always available for Eurostat databases.
map.NUTSyear(value)int2016The version of the NUTS dataset to use. Possible values are given in Nuts2json. Note that the default value will be adjusted in the future depending on the NUTS legislation in force.
map.lg(value)String"en"The language code, for multilingual maps.
map.tooltipText(value)FunctionA default function.A function returning the text to show in a tooltip which appears when the mouse passes over map features. Set to null if no tooltip is needed.
map.tooltipShowFlags(value)String"short"Set to null, 0 or false if no flag should be shown in the tooltip. Set to "short" to show the flag as a letter. Set to "long" to show the flag as a text.
map.unitText(value)String""The text of the unit to show in the tooltip.

For choropleth maps

A choropleth map shows areas colored or patterned in proportion to a statistical variable. These maps should be used to show intensive statistical variables such as proportions, ratios, densities, rates of change, percentages, etc. Here is an example with color value, another with a diverging color scheme, and a last one with a texture pattern.

To show a choropleth map, type should be set to "ch". The following parameters are then considered:

MethodTypeDefault valueDescription
map.classifMethod(value)String"quantile"The classification method. Possible values are "quantile", "equinter" for equal intervals, and "threshold" for user defined threshol (see threshold method).
map.threshold(value)Array0If classifMethod = "threshold", the breaks of the classification.
map.makeClassifNice(value)booleantrueMake nice break values. Works only for classifMethod = "equinter".
map.clnb(value)int7The number of classes. When classifMethod = "threshold", this parameter is inferred from the number of breaks specified.
map.colorFun(value)Functiond3.interpolateYlOrBrThe color function, as defined in d3-scale-chromatic
map.classToFillStyleCH(value)FunctionSee descriptionA function returning a fill style for each class number. The default values is the function returned by eurostatmap.getColorLegend(colorFun()).
map.filtersDefinitionFun(value)Functionfunction() {}A function defining SVG filter elements. To be used to defined fill patterns.
map.noDataFillStyle(value)String"lightgray"The fill style to be used for regions where no data is available.
map.noDataText(value)String"No data available"The text to show for regions where no data is available.

For proportional symbol map

A proportional symbol map shows symbols (typically circles) sized in proportion to a statistical variable. These maps should be used to show statistical extensive variables such as quantities, populations, numbers, etc. Here is an example.

To show a proportional symbol map, type should be set to "ps". The following parameters are then considered:

MethodTypeDefault valueDescription
map.psMaxSize(value)number30The maximum size of the symbol, in pixel.
map.psMinSize(value)number0.8The minimum size of the symbol, for non null values, in pixel.
map.psMinValue(value)number0The minimum value of the range domain.
map.psFill(value)String"#B45F04"The fill color or pattern of the symbol.
map.psFillOpacity(value)number0.7The opacity of the symbol, from 0 to 1.
map.psStroke(value)String"#fff"The stroke color of the symbol.
map.psStrokeWidth(value)number0.5The width of the stroke.

For categorical maps

A categorical map shows areas according to categories. Here is an example of such map.

To show a categorical map, type should be set to "ct". The following parameters are then considered:

MethodTypeDefault valueDescription
map.classToFillStyleCT(value)ObjectnullAn object giving the fill style depending on the class code.
map.classToText(value)ObjectnullAn object giving the legend label text depending on the class code.
map.filtersDefinitionFun(value)Functionfunction() {}A function defining SVG filter elements. To be used to defined fill patterns.
map.noDataFillStyle(value)String"lightgray"The fill style to be used for regions where no data is available.
map.noDataText(value)String"No data available"The text to show for regions where no data is available.

Some styling customisation

MethodTypeDefault valueDescription
map.nutsrgFillStyle(value)String"#eee"The fill style of the NUTS regions, used for proportional symbol maps only.
map.nutsrgSelectionFillStyle(value)String"#purple"The fill style of the selected NUTS regions.
map.nutsbnStroke(value)Object{0:"#777", 1:"#777", 2:"#777", 3:"#777", oth:"#444", co:"#1f78b4"}The stroke style of the NUTS boundaries, depending on the NUTS level, if it is a border with another country ('oth') and if it is coastal ('co')
map.nutsbnStrokeWidth(value)Object{0:1, 1:0.2, 2:0.2, 3:0.2, oth:1, co:1}The stroke width of the NUTS boundaries, depending on the NUTS level, if it is a border with another country ('oth') and if it is coastal ('co').
map.cntrgFillStyle(value)String"lightgray"The fill style of the countries.
map.cntrgSelectionFillStyle(value)String"darkgray"The fill style of the selected countries.
map.cntbnStroke(value)Object{def:"#777", co:"#1f78b4"}The stroke style of the country boundaries. 'co' is for coastal boundaries, 'def' for other boundaries.
map.cntbnStrokeWidth(value)Object{def:1, co:1}The stroke width of the country boundaries. 'co' is for coastal boundaries, 'def' for other boundaries.
map.seaFillStyle(value)String"#b3cde3"The fill style of the sea areas.
map.drawCoastalMargin(value)booleantrueSet to true to show a coastal blurry margin. False otherwise.
map.coastalMarginColor(value)String"white"The color of the coastal blurry margin.
map.coastalMarginWidth(value)number12The width of the coastal blurry margin.
map.coastalMarginStdDev(value)number12The standard deviation of the coastal blurry margin.
map.drawGraticule(value)booleantrueSet to true to show the graticule (meridian and parallel lines). False otherwise.
map.graticuleStroke(value)String"gray"The stroke style of the graticule.
map.graticuleStrokeWidth(value)number1The stroke width of the graticule.

Legend customisation

MethodTypeDefault valueDescription
map.showLegend(value)booleantrueSet to true to show a legend. False otherwise.
map.legendFontFamily(value)Stringeurostatmap.fontFamilyDefaultThe legend font.
map.legendTitleText(value)String"Legend"The legend title.
map.legendTitleFontSize(value)int20The legend title font size.
map.legendTitleWidth(value)int140The legend title text wrap, in pixel.
map.legendBoxWidth(value)int250The legend box width.
map.legendBoxHeight(value)int350The legend box height.
map.legendBoxMargin(value)int10The legend box margin, in pixel.
map.legendBoxPadding(value)int10The legend box padding, in pixel.
map.legendBoxCornerRadius(value)int10The legend box corner radius, in pixel.
map.legendBoxFill(value)String"white"The legend box fill style.
map.legendBoxOpacity(value)number0.5The legend box opacity, from 0 to 1.
map.legendCellNb(value)int4The legend cells number (used for proportional symbol maps only).
map.legendAscending(value)StringtrueThe legend cells order.
map.legendShapeWidth(value)int20The cell width (used for choropleth maps only).
map.legendShapeHeight(value)int16The cell heigth (used for choropleth maps only).
map.legendShapePadding(value)int2The distance between 2 cells, in pixel.
map.legendLabelFontSize(value)int15The label font size.
map.legendLabelDelimiter(value)String" - "The label delimiter size (used for choropleth maps only).
map.legendLabelWrap(value)int140The label text wrap length, in pixel.
map.legendLabelDecNb(value)int2The number of decimal places to show in text labels.
map.legendLabelOffset(value)int5The number of pixels between the legend shape and its label, in pixel.

Bottom text customisation

This text field is intended to be used for copyright text. It can however be customised.

MethodTypeDefault valueDescription
map.bottomText(value)String"(C)EuroGeographics (C)UN-FAO (C)Turkstat"The text. Note that the default value is mandatory.
map.bottomTextFontSize(value)int12The font size.
map.bottomTextFill(value)String"black"The text color.
map.bottomTextFontFamily(value)Stringeurostatmap.fontFamilyDefaultThe font family.
map.bottomTextPadding(value)number10The padding, in pixel.
map.bottomTextTooltipMessage(value)StringThe default disclaimer message.Set a text to be shown in a tooltip when passing over the bottom text. Set to null if no tooltip has to be shown.

Build and update

After changing some parameters, one of the following methods need to be executed:

MethodReturnsDescription
map.build()thisBuild (or rebuild) the entire map.
map.updateGeoData()thisGet new geometrical data. It should be used to update the map when parameters on the map geometries have changed.
map.updateStatData()thisGet new statistical data. It should be used to update the map when parameters on the statistical data have changed.
map.buildMapTemplate()thisUpdate the map when parameters on the map template have changed.
map.updateClassificationAndStyle()thisUpdate the map when parameters on the classification have changed.
map.updateLegend()thisUpdate the map when parameters on the legend have changed.
map.updateStyle()thisUpdate the map when parameters on the classification style have changed.

Miscellaneous

MethodReturnsDescription
map.getTime()StringReturn the time parameter of the statistical data. When a filter such as { lastTimePeriod : 1 } is used, this method allows a retrieval of the map timestamp.
map.set(options)thisRun "myMap.set(eurostatmap.getURLParameters())" to retrieve parameters defined in the URL and apply them to a map element directly.

Anything unclear or missing? Feel free to ask !

Technical details

Maps based on NUTS regions rely on Nuts2json API and TopoJSON format. Statistical data are accessed using Eurostat REST webservice for JSON-stat data. The data are decoded and queried using JSON-stat library. Maps are rendered as SVG maps using D3.js library.

Support and contribution

Feel free to ask support, fork the project or simply star it (it's always a pleasure).

Copyright

The Eurostat NUTS dataset is copyrighted. There are specific provisions for the usage of this dataset which must be respected. The usage of these data is subject to their acceptance. See the Eurostat-GISCO website for more information.

Disclaimer

The designations employed and the presentation of material on these maps do not imply the expression of any opinion whatsoever on the part of the European Union concerning the legal status of any country, territory, city or area or of its authorities, or concerning the delimitation of its frontiers or boundaries. Kosovo: This designation is without prejudice to positions on status, and is in line with UNSCR 1244/1999 and the ICJ Opinion on the Kosovo declaration of independence. Palestine: This designation shall not be construed as recognition of a State of Palestine and is without prejudice to the individual positions of the Member States on this issue.