This short tutorial will show how you can create a Globe out of your map using Orthographic projection.
As you may already know, each map can be displayed in a number of ways - projections. (more about it here )
Each one has it’s own advantages and disadvantages. However, only one can be used to create a Globe-like representation of the world - Orthographic.
To set this projection we use map’s projection property:
chart.projection = new am4maps.projections.Orthographic();
chart.projection = new am4maps.projections.Orthographic();
"projection": "Orthographic",
This alone is enough to convert your regular flat map into a globe!
Normally, the our newly created globe will have its zero longitude in the middle.
You can set the initial start position using deltaLongitude setting.
It works by adjusting the middle one way or another by longitude degrees.
chart.deltaLongitude = -60;
chart.deltaLongitude = -60;
A globe with curved countries “in the air” looks kinda weird. To make it look more like a real globe, let’s add a fill, or rather “background series”.
The whole process is described in great detail in “Background series ”. We’re just going to repeat the code here for our convenience.
chart.backgroundSeries.mapPolygons.template.polygon.fill = am4core.color("#aadaff");
chart.backgroundSeries.mapPolygons.template.polygon.fillOpacity = 1;
chart.backgroundSeries.mapPolygons.template.polygon.fill = am4core.color("#aadaff");
chart.backgroundSeries.mapPolygons.template.polygon.fillOpacity = 1;
OK, just one last enhancement: map grid. It will give our map an event more “globy” effect.
Again, check out “Map grid ” in main Map Chart article for a thorough guidance. We’re just leave you with a TL/DR; version.
var graticuleSeries = chart.series.push(new am4maps.GraticuleSeries());
graticuleSeries.mapLines.template.line.stroke = am4core.color("#67b7dc");
graticuleSeries.mapLines.template.line.strokeOpacity = 0.2;
graticuleSeries.fitExtent = false;
var graticuleSeries = chart.series.push(new am4maps.GraticuleSeries());
graticuleSeries.mapLines.template.line.stroke = am4core.color("#67b7dc");
graticuleSeries.mapLines.template.line.strokeOpacity = 0.2;
graticuleSeries.fitExtent = false;
"type": "GraticuleSeries",
We’ve fitted the following demo with a slider, to see how changing deltaLongitude affects our globe:
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
var chart = am4core . create ( " chartdiv " , am4maps . MapChart );
chart . geodata = am4geodata_worldLow ;
chart . projection = new am4maps . projections . Orthographic ();
// Create map polygon series
var polygonSeries = chart . series . push ( new am4maps . MapPolygonSeries ());
// Make map load polygon (like country names) data from GeoJSON
polygonSeries . useGeodata = true ;
var polygonTemplate = polygonSeries . mapPolygons . template ;
polygonTemplate . tooltipText = " {name} " ;
polygonTemplate . fill = am4core . color ( " #74B266 " );
// Create hover state and set alternative fill color
var hs = polygonTemplate . states . create ( " hover " );
hs . properties . fill = am4core . color ( " #367B25 " );
var label = chart . chartAndLegendContainer . createChild ( am4core . Label );
label . text = " chart.deltaLongitude = 0 " ;
label . padding ( 5 , 10 , 5 , 10 );
label . background . fillOpacity = 0.05 ;
label . background . fill = am4core . color ( " #000 " );
var slider = chart . chartAndLegendContainer . createChild ( am4core . Slider );
slider . margin ( 20 , 0 , 20 , 0 );
slider . valign = " bottom " ;
slider . events . on ( " rangechanged " , function ( ev ) {
var deltaLongitude = 360 * ev . target . start - 180 ;
chart . deltaLongitude = deltaLongitude ;
" chart.deltaLongitude = " +
chart . numberFormatter . format ( deltaLongitude , " [green]#.|[red]#.|[#555]# " );
var graticuleSeries = chart . series . push ( new am4maps . GraticuleSeries ());
graticuleSeries . mapLines . template . line . stroke = am4core . color ( " #67b7dc " );
graticuleSeries . mapLines . template . line . strokeOpacity = 0.2 ;
graticuleSeries . fitExtent = false ;
chart . backgroundSeries . mapPolygons . template . polygon . fill = am4core . color ( " #aadaff " );
chart . backgroundSeries . mapPolygons . template . polygon . fillOpacity = 1 ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Orthographic projection orthographic-projection
Map Chart allows configuring the globe to rotate instead of moving when using mouse or touch, using its panBehavior property.
And, here’s another demo that shows rotation of the globe by dragging the map itself:
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
var chart = am4core . create ( " chartdiv " , am4maps . MapChart );
chart . panBehavior = " rotateLongLat " ;
chart . geodata = am4geodata_worldLow ;
chart . projection = new am4maps . projections . Orthographic ();
// Create map polygon series
var polygonSeries = chart . series . push ( new am4maps . MapPolygonSeries ());
polygonSeries . north = 90 ;
// Make map load polygon (like country names) data from GeoJSON
polygonSeries . useGeodata = true ;
var polygonTemplate = polygonSeries . mapPolygons . template ;
polygonTemplate . tooltipText = " {name} " ;
polygonTemplate . fill = am4core . color ( " #74B266 " );
// Create hover state and set alternative fill color
var hs = polygonTemplate . states . create ( " hover " );
hs . properties . fill = am4core . color ( " #367B25 " );
var graticuleSeries = chart . series . push ( new am4maps . GraticuleSeries ());
graticuleSeries . mapLines . template . line . stroke = am4core . color ( " #67b7dc " );
graticuleSeries . mapLines . template . line . strokeOpacity = 0.2 ;
graticuleSeries . fitExtent = false ;
chart . backgroundSeries . mapPolygons . template . polygon . fill = am4core . color ( " #aadaff " );
chart . backgroundSeries . mapPolygons . template . polygon . fillOpacity = 1 ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Orthographic projection (dragging) orthographic-projection-dragging
Before you go, let’s talk about Map line series .
Using lines on the map in Orthographic projection presents certain challenges, because line might start and end on the “invisible” side of the globe: one’s that facing away from viewer.
Images that are “out of the view” will be automatically hidden, but what about lines?
We’d expect them to be shown and be cut off when they cross the threshold of the “horizon”.
The truth is that only MapLineSeries support this functionality, and only when shortestDistance = true (default setting).
Other line series like MapArcSeries and MapSplineSeries are not supported.
Consider a multi-point line that goes from Paris to Mexico City, then continues to Honolulu. This is how using different map line series will look like:
All line types produce correct result in that they reach their target coordinates. However only MapLineSeries ar being correctly cut off at the “horizon”.
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
var chart = am4core . create ( " chartdiv " , am4maps . MapChart );
chart . projection = new am4maps . projections . Orthographic ();
chart . panBehavior = " rotateLongLat " ;
chart . deltaLongitude = 10 ;
chart . deltaLatitude = - 20 ;
chart . geodata = am4geodata_worldLow ;
// Create map polygon series
var polygonSeries = chart . series . push ( new am4maps . MapPolygonSeries ());
polygonSeries . north = 90 ;
// Make map load polygon (like country names) data from GeoJSON
polygonSeries . useGeodata = true ;
var polygonTemplate = polygonSeries . mapPolygons . template ;
polygonTemplate . tooltipText = " {name} " ;
polygonTemplate . fill = am4core . color ( " #74B266 " );
// Create hover state and set alternative fill color
var hs = polygonTemplate . states . create ( " hover " );
hs . properties . fill = am4core . color ( " #367B25 " );
var graticuleSeries = chart . series . push ( new am4maps . GraticuleSeries ());
graticuleSeries . mapLines . template . line . stroke = am4core . color ( " #67b7dc " );
graticuleSeries . mapLines . template . line . strokeOpacity = 0.2 ;
graticuleSeries . fitExtent = false ;
chart . backgroundSeries . mapPolygons . template . polygon . fill = am4core . color ( " #aadaff " );
chart . backgroundSeries . mapPolygons . template . polygon . fillOpacity = 1 ;
var lineSeries = chart . series . push ( new am4maps . MapLineSeries ());
lineSeries . mapLines . template . stroke = am4core . color ( " #e03e96 " );
lineSeries . mapLines . template . strokeWidth = 4 ;
{ latitude: 48.856614 , longitude: 2.352222 },
{ latitude: 19.432608 , longitude: - 99.133209 },
{ latitude: 21.306944 , longitude: - 157.858337 }
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Orthographic projection (lines) orthographic-projection-lines