{"id":17499,"date":"2019-02-08T12:10:54","date_gmt":"2019-02-08T12:10:54","guid":{"rendered":"http:\/\/www.highcharts.com\/blog\/?p=17499"},"modified":"2026-01-12T10:05:03","modified_gmt":"2026-01-12T10:05:03","slug":"topojson-in-highmaps","status":"publish","type":"post","link":"https:\/\/www.highcharts.com\/blog\/tutorials\/topojson-in-highmaps\/","title":{"rendered":"TopoJSON in Highcharts Maps"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>&nbsp;<br \/>\nHighcharts Maps has built-in support for GeoJSON, a format for defining map shapes and features. A popular extension of GeoJSON is <a href=\"https:\/\/en.wikipedia.org\/wiki\/GeoJSON#TopoJSON\">TopoJSON<\/a>. In TopoJSON, repetetive path segments are extracted and defined only once, and then referenced from the geometries. This makes the file size smaller and better suited for loading in web pages. For example, imagine a map with two neighboring countries. In GeoJSON, the border segment would be repeated for the outline of each of the countries. In TopoJSON this segment is extracted and referenced from both countries.<\/p>\n<h4>Map data<\/h4>\n<p>If you don&#8217;t have your own TopoJSON files, there are some collections available on GitHub. One of them is <a href=\"https:\/\/github.com\/deldersveld\/topojson\/\">TopoJSON Collection<\/a>, where the author has picked map sources that are believed to be licensed for reuse or which are in the public domain. For our demo we will use a Europe map from another provider, <a href=\"https:\/\/github.com\/leakyMirror\/map-of-europe\">leakyMirror<\/a>, <a href=\"https:\/\/cdn.jsdelivr.net\/gh\/leakyMirror\/map-of-europe@master\/TopoJSON\/europe.topojson\">served through jsDelivr<\/a>.<\/p>\n<h4>Convert into GeoJSON<\/h4>\n<p>In order to use TopoJSON in Highcharts Maps, we must first decode it to GeoJSON. This is very simple using the <a href=\"https:\/\/github.com\/topojson\/topojson-client\">TopoJSON Client<\/a> library.\u00a0In this case, we extract the map of Europe which is encoded into <code>topology.objects.europe<\/code>.<\/p>\n<pre> \/\/ Convert the topoJSON feature into geoJSON\r\nconst geojson = window.topojson.feature(\r\n    topology,\r\n    topology.objects.europe\r\n);<\/pre>\n<p>Now we have a <code>geojson<\/code> variable that we can apply directly into Highcharts Maps&#8217; <a href=\"https:\/\/api.highcharts.com\/highmaps\/chart.map\">chart.map<\/a> option.<\/p>\n<h4>Projection<\/h4>\n<p>However that doesn&#8217;t look good out of the box. Especially for areas of lower latitudes, the map is distorted. We want to apply a projection using <a href=\"https:\/\/www.npmjs.com\/package\/proj4\">Proj4.js<\/a>, an MIT licensed JavaScript library. In the demo we have written a helper function that translates the GeoJSON geometries into projected coordinates. Europe looks good using a Lambert Conformal Conic projection,\u00a0with a projection\u00a0center in the middle of the area. Projection of all the points in a geojson typically takes 20-30 ms depending on the resolution of the map, so if client-side performance is crucial, you should consider doing this on the server side.<\/p>\n<pre>\/\/ Apply a Lambert Conformal Conic projection to the GeoJSON\r\nproject(\r\n    geojson,\r\n    '+proj=lcc +lat_1=43 +lat_2=62 +lat_0=30 +lon_0=10'\r\n);<\/pre>\n<p>&nbsp;<\/p>\n<h4>Putting it together<\/h4>\n<p>In the final result we have a nice, projected map. In the sample we use an array of random numbers as the data values, and set <code>joinBy<\/code> to <code>null<\/code> to apply it to the countries. In a real world chart we would set <a href=\"https:\/\/api.highcharts.com\/highmaps\/series.map.joinBy\">joinBy<\/a> to link the data to the map using one of the GeoJSON\/TopoJSON identifier properties, like name, FIPS or HASC.<\/p>\n<p><iframe style=\"width: 100%; height: 560px; border: none\" src=\"https:\/\/www.highcharts.com\/samples\/embed\/maps\/chart\/topojson\"><span data-mce-type=\"bookmark\" style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" class=\"mce_SELRES_start\">\ufeff<\/span><span data-mce-type=\"bookmark\" style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" class=\"mce_SELRES_start\">\ufeff<\/span><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; Highcharts Maps has built-in support for GeoJSON, a format for defining map shapes and features. A popular extension of GeoJSON is TopoJSON. In TopoJSON, repetetive path segments are extracted and defined only once, and then referenced from the geometries. This makes the file size smaller and better suited for loading in web pages. [&hellip;]<\/p>\n","protected":false},"author":49,"featured_media":17524,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"meta_title":"","meta_description":"","hc_selected_options":[],"footnotes":""},"categories":[210],"tags":[876],"coauthors":[734],"class_list":["post-17499","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-highcharts-maps"],"_links":{"self":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/17499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/comments?post=17499"}],"version-history":[{"count":1,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/17499\/revisions"}],"predecessor-version":[{"id":29161,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/17499\/revisions\/29161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media\/17524"}],"wp:attachment":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media?parent=17499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/categories?post=17499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/tags?post=17499"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/coauthors?post=17499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}