index.htm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Highmaps Example</title>
  6. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  7. <style type="text/css">
  8. #container {
  9. height: 500px;
  10. min-width: 310px;
  11. max-width: 1500px;
  12. margin: 0 auto;
  13. }
  14. .loading {
  15. margin-top: 10em;
  16. text-align: center;
  17. color: gray;
  18. }
  19. </style>
  20. <script type="text/javascript">
  21. $(function () {
  22. var H = Highcharts,
  23. map = H.maps['countries/us/us-all'],
  24. chart;
  25. // Add series with state capital bubbles
  26. $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=us-capitals.json&callback=?', function (json) {
  27. var data = [];
  28. $.each(json, function () {
  29. this.z = this.population;
  30. data.push(this);
  31. });
  32. $('#container').highcharts('Map', {
  33. title: {
  34. text: 'Highmaps lat/lon demo'
  35. },
  36. tooltip: {
  37. formatter: function () {
  38. return this.point.capital + ', ' + this.point.parentState + '<br>Lat: ' + this.point.lat + ' Lon: ' + this.point.lon + '<br>Population: ' + this.point.population;
  39. },
  40. crosshairs: [{
  41. zIndex: 5,
  42. dashStyle: 'dot',
  43. snap: false,
  44. color: 'gray'
  45. }, {
  46. zIndex: 5,
  47. dashStyle: 'dot',
  48. snap: false,
  49. color: 'gray'
  50. }]
  51. },
  52. series: [{
  53. name: 'Basemap',
  54. mapData: map,
  55. borderColor: '#606060',
  56. nullColor: 'rgba(200, 200, 200, 0.2)',
  57. showInLegend: false
  58. }, {
  59. name: 'Separators',
  60. type: 'mapline',
  61. data: H.geojson(map, 'mapline'),
  62. color: '#101010',
  63. enableMouseTracking: false,
  64. showInLegend: false
  65. }, {
  66. type: 'mapbubble',
  67. dataLabels: {
  68. enabled: true,
  69. format: '{point.capital}'
  70. },
  71. name: 'Cities',
  72. data: data,
  73. maxSize: '12%',
  74. color: H.getOptions().colors[0]
  75. }]
  76. });
  77. chart = $('#container').highcharts();
  78. });
  79. // Display custom label with lat/lon next to crosshairs
  80. $('#container').mousemove(function (e) {
  81. var position;
  82. if (chart) {
  83. if (!chart.lab) {
  84. chart.lab = chart.renderer.text('', 0, 0)
  85. .attr({
  86. zIndex: 5
  87. })
  88. .css({
  89. color: '#505050'
  90. })
  91. .add();
  92. }
  93. e = chart.pointer.normalize(e);
  94. position = chart.fromPointToLatLon({
  95. x: chart.xAxis[0].toValue(e.chartX),
  96. y: chart.yAxis[0].toValue(e.chartY)
  97. });
  98. chart.lab.attr({
  99. x: e.chartX + 5,
  100. y: e.chartY - 22,
  101. text: 'Lat: ' + position.lat.toFixed(2) + '<br>Lon: ' + position.lon.toFixed(2)
  102. });
  103. }
  104. });
  105. $('#container').mouseout(function () {
  106. if (chart && chart.lab) {
  107. chart.lab.destroy();
  108. chart.lab = null;
  109. }
  110. });
  111. });
  112. </script>
  113. </head>
  114. <body>
  115. <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js"></script>
  116. <script src="../../js/highmaps.js"></script>
  117. <script src="../../js/modules/exporting.js"></script>
  118. <script src="http://code.highcharts.com/mapdata/countries/us/us-all.js"></script>
  119. <div id="container"></div>
  120. </body>
  121. </html>