Advanced lat/long
author(s): Øystein Moseng Torstein Hønsi
by John Dow
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js"></script>
<script src="https://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/maps/modules/data.js"></script>
<script src="https://code.highcharts.com/maps/modules/exporting.js"></script>
<script src="https://code.highcharts.com/maps/modules/offline-exporting.js"></script>
<script src="https://code.highcharts.com/maps/modules/accessibility.js"></script>
<div id="container"></div>
CSS
#container {
height: 500px;
min-width: 310px;
max-width: 800px;
margin: 0 auto;
}
.loading {
margin-top: 10em;
text-align: center;
color: gray;
}
JavaScript
(async () => {
const topology = await fetch(
'https://code.highcharts.com/mapdata/countries/us/us-all.topo.json'
).then(response => response.json());
const data = await fetch(
'https://cdn.jsdelivr.net/gh/highcharts/[email protected]/samples/data/us-capitals.json'
).then(response => response.json());
data.forEach(p => {
p.z = p.population;
});
const H = Highcharts;
const chart = Highcharts.mapChart('container', {
title: {
text: 'Highcharts Maps lon/lat demo'
},
tooltip: {
pointFormat: '{point.capital}, {point.parentState}<br>' +
'Lon: {point.lon}<br>' +
'Lat: {point.lat}<br>' +
'Population: {point.population}'
},
xAxis: {
crosshair: {
zIndex: 5,
dashStyle: 'dot',
snap: true,
color: 'gray'
}
},
yAxis: {
crosshair: {
zIndex: 5,
dashStyle: 'dot',
snap: true,
color: 'gray'
}
},
series: [{
name: 'Basemap',
mapData: topology,
accessibility: {
exposeAsGroupOnly: true
},
borderColor: '#606060',
nullColor: 'rgba(200, 200, 200, 0.2)',
showInLegend: false
}, {
type: 'mapbubble',
dataLabels: {
enabled: true,
format: '{point.capital}'
},
accessibility: {
point: {
valueDescriptionFormat: '{point.capital}, {point.parentState}. Population {point.population}. Latitude {point.lat:.2f}, longitude {point.lon:.2f}.'
}
},
name: 'State capital cities',
data: data,
maxSize: '12%',
color: H.getOptions().colors[0]
...