index.htm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. #demo-wrapper {
  9. max-width: 1000px;
  10. margin: 0 auto;
  11. height: 560px;
  12. }
  13. #mapBox {
  14. width: 80%;
  15. float: left;
  16. }
  17. #container {
  18. height: 500px;
  19. }
  20. #sideBox {
  21. float: right;
  22. width: 16%;
  23. margin: 100px 1% 0 1%;
  24. padding-left: 1%;
  25. border-left: 1px solid silver;
  26. display: none;
  27. }
  28. #infoBox {
  29. margin-top: 10px;
  30. }
  31. .or-view-as {
  32. margin: 0.5em 0;
  33. }
  34. #up {
  35. height: 20px;
  36. max-width: 400px;
  37. margin: 0 auto;
  38. }
  39. #up a {
  40. cursor: pointer;
  41. padding-left: 40px;
  42. }
  43. .selector {
  44. height: 40px;
  45. max-width: 400px;
  46. margin: 0 auto;
  47. position: relative;
  48. }
  49. .selector .prev-next {
  50. position: absolute;
  51. padding: 0 10px;
  52. font-size: 30px;
  53. line-height: 20px;
  54. background: white;
  55. font-weight: bold;
  56. color: #999;
  57. top: -2px;
  58. display: none;
  59. border: none;
  60. }
  61. .selector .custom-combobox {
  62. display: block;
  63. position: absolute;
  64. left: 40px;
  65. right: 110px;
  66. }
  67. .selector .custom-combobox .custom-combobox-input {
  68. position: absolute;
  69. font-size: 14px;
  70. color: silver;
  71. border-radius: 0;
  72. height: 24px;
  73. display: block;
  74. background: url(http://api.highcharts.com/resources/images/search.png) 5px 5px no-repeat white;
  75. padding: 1px 5px 1px 30px;
  76. width: 100%;
  77. }
  78. .selector .custom-combobox .ui-autocomplete-input:focus {
  79. color: black;
  80. }
  81. .selector .custom-combobox .ui-autocomplete-input.valid {
  82. color: black;
  83. }
  84. .selector .custom-combobox-toggle {
  85. position: absolute;
  86. display: block;
  87. right: -78px;
  88. border-radius: 0;
  89. }
  90. .selector #btn-next-map {
  91. right: -12px;
  92. }
  93. .ui-autocomplete {
  94. max-height: 500px;
  95. overflow: auto;
  96. }
  97. .ui-autocomplete .option-header {
  98. font-style: italic;
  99. font-weight: bold;
  100. margin: 5px 0;
  101. font-size: 1.2em;
  102. color: gray;
  103. }
  104. .loading {
  105. margin-top: 10em;
  106. text-align: center;
  107. color: gray;
  108. }
  109. .ui-button-icon-only .ui-button-text {
  110. height: 26px;
  111. padding: 0 !important;
  112. background: white;
  113. }
  114. #infoBox .button {
  115. border: none;
  116. border-radius: 3px;
  117. background: #a4edba;
  118. padding: 5px;
  119. color: black;
  120. text-decoration: none;
  121. font-size: 12px;
  122. white-space: nowrap;
  123. cursor: pointer;
  124. margin: 0 3px;
  125. line-height: 30px;
  126. }
  127. @media (max-width: 768px) {
  128. #demo-wrapper {
  129. width: auto;
  130. height: auto;
  131. }
  132. #mapBox {
  133. width: auto;
  134. float: none;
  135. }
  136. #container {
  137. height: 310px;
  138. }
  139. #sideBox {
  140. float: none;
  141. width: auto;
  142. margin-top: 0;
  143. border-left: none;
  144. border-top: 1px solid silver;
  145. }
  146. /*
  147. .selector {
  148. width: 300px;
  149. }
  150. .selector .custom-combobox .custom-combobox-input {
  151. width: 190px;
  152. }
  153. .selector .custom-combobox-toggle {
  154. left: 226px;
  155. }
  156. .selector #btn-next-map {
  157. left: 310px;
  158. }
  159. */
  160. }
  161. </style>
  162. <script type="text/javascript">
  163. $(function () {
  164. /**
  165. * This is a complicated demo of Highmaps, not intended to get you up to speed
  166. * quickly, but to show off some basic maps and features in one single place.
  167. * For the basic demo, check out http://www.highcharts.com/maps/demo/geojson instead.
  168. */
  169. // Base path to maps
  170. var baseMapPath = "http://code.highcharts.com/mapdata/",
  171. showDataLabels = false, // Switch for data labels enabled/disabled
  172. mapCount = 0,
  173. searchText,
  174. mapOptions = '';
  175. // Populate dropdown menus and turn into jQuery UI widgets
  176. $.each(Highcharts.mapDataIndex, function (mapGroup, maps) {
  177. if (mapGroup !== "version") {
  178. mapOptions += '<option class="option-header">' + mapGroup + '</option>';
  179. $.each(maps, function (desc, path) {
  180. mapOptions += '<option value="' + path + '">' + desc + '</option>';
  181. mapCount += 1;
  182. });
  183. }
  184. });
  185. searchText = 'Search ' + mapCount + ' maps';
  186. mapOptions = '<option value="custom/world.js">' + searchText + '</option>' + mapOptions;
  187. $("#mapDropdown").append(mapOptions).combobox();
  188. // Change map when item selected in dropdown
  189. $("#mapDropdown").change(function () {
  190. var $selectedItem = $("option:selected", this),
  191. mapDesc = $selectedItem.text(),
  192. mapKey = this.value.slice(0, -3),
  193. svgPath = baseMapPath + mapKey + '.svg',
  194. geojsonPath = baseMapPath + mapKey + '.geo.json',
  195. javascriptPath = baseMapPath + this.value,
  196. isHeader = $selectedItem.hasClass('option-header');
  197. // Dim or highlight search box
  198. if (mapDesc === searchText || isHeader) {
  199. $('.custom-combobox-input').removeClass('valid');
  200. location.hash = '';
  201. } else {
  202. $('.custom-combobox-input').addClass('valid');
  203. location.hash = mapKey;
  204. }
  205. if (isHeader) {
  206. return false;
  207. }
  208. // Show loading
  209. if ($("#container").highcharts()) {
  210. $("#container").highcharts().showLoading('<i class="fa fa-spinner fa-spin fa-2x"></i>');
  211. }
  212. // When the map is loaded or ready from cache...
  213. function mapReady() {
  214. var mapGeoJSON = Highcharts.maps[mapKey],
  215. data = [],
  216. parent,
  217. match;
  218. // Update info box download links
  219. $("#download").html(
  220. '<a class="button" target="_blank" href="http://jsfiddle.net/gh/get/jquery/1.11.0/' +
  221. 'highslide-software/highcharts.com/tree/master/samples/mapdata/' + mapKey + '">' +
  222. 'View clean demo</a>' +
  223. '<div class="or-view-as">... or view as ' +
  224. '<a target="_blank" href="' + svgPath + '">SVG</a>, ' +
  225. '<a target="_blank" href="' + geojsonPath + '">GeoJSON</a>, ' +
  226. '<a target="_blank" href="' + javascriptPath + '">JavaScript</a>.</div>'
  227. );
  228. // Generate non-random data for the map
  229. $.each(mapGeoJSON.features, function (index, feature) {
  230. data.push({
  231. key: feature.properties['hc-key'],
  232. value: index
  233. });
  234. });
  235. // Show arrows the first time a real map is shown
  236. if (mapDesc !== searchText) {
  237. $('.selector .prev-next').show();
  238. $('#sideBox').show();
  239. }
  240. // Is there a layer above this?
  241. match = mapKey.match(/^(countries\/[a-z]{2}\/[a-z]{2})-[a-z0-9]+-all$/);
  242. if (/^countries\/[a-z]{2}\/[a-z]{2}-all$/.test(mapKey)) { // country
  243. parent = {
  244. desc: 'World',
  245. key: 'custom/world'
  246. };
  247. } else if (match) { // admin1
  248. parent = {
  249. desc: $('option[value="' + match[1] + '-all.js"]').text(),
  250. key: match[1] + '-all'
  251. };
  252. }
  253. $('#up').html('');
  254. if (parent) {
  255. $('#up').append(
  256. $('<a><i class="fa fa-angle-up"></i> ' + parent.desc + '</a>')
  257. .attr({
  258. title: parent.key
  259. })
  260. .click(function () {
  261. $('#mapDropdown').val(parent.key + '.js').change();
  262. })
  263. );
  264. }
  265. // Instantiate chart
  266. $("#container").highcharts('Map', {
  267. title: {
  268. text: null
  269. },
  270. mapNavigation: {
  271. enabled: true
  272. },
  273. colorAxis: {
  274. min: 0,
  275. stops: [
  276. [0, '#EFEFFF'],
  277. [0.5, Highcharts.getOptions().colors[0]],
  278. [1, Highcharts.Color(Highcharts.getOptions().colors[0]).brighten(-0.5).get()]
  279. ]
  280. },
  281. legend: {
  282. layout: 'vertical',
  283. align: 'left',
  284. verticalAlign: 'bottom'
  285. },
  286. series: [{
  287. data: data,
  288. mapData: mapGeoJSON,
  289. joinBy: ['hc-key', 'key'],
  290. name: 'Random data',
  291. states: {
  292. hover: {
  293. color: Highcharts.getOptions().colors[2]
  294. }
  295. },
  296. dataLabels: {
  297. enabled: showDataLabels,
  298. formatter: function () {
  299. return mapKey === 'custom/world' || mapKey === 'countries/us/us-all' ?
  300. (this.point.properties && this.point.properties['hc-a2']) :
  301. this.point.name;
  302. }
  303. },
  304. point: {
  305. events: {
  306. // On click, look for a detailed map
  307. click: function () {
  308. var key = this.key;
  309. $('#mapDropdown option').each(function () {
  310. if (this.value === 'countries/' + key.substr(0, 2) + '/' + key + '-all.js') {
  311. $('#mapDropdown').val(this.value).change();
  312. }
  313. });
  314. }
  315. }
  316. }
  317. }, {
  318. type: 'mapline',
  319. name: "Separators",
  320. data: Highcharts.geojson(mapGeoJSON, 'mapline'),
  321. nullColor: 'gray',
  322. showInLegend: false,
  323. enableMouseTracking: false
  324. }]
  325. });
  326. showDataLabels = $("#chkDataLabels").attr('checked');
  327. }
  328. // Check whether the map is already loaded, else load it and
  329. // then show it async
  330. if (Highcharts.maps[mapKey]) {
  331. mapReady();
  332. } else {
  333. $.getScript(javascriptPath, mapReady);
  334. }
  335. });
  336. // Toggle data labels - Note: Reloads map with new random data
  337. $("#chkDataLabels").change(function () {
  338. showDataLabels = $("#chkDataLabels").attr('checked');
  339. $("#mapDropdown").change();
  340. });
  341. // Switch to previous map on button click
  342. $("#btn-prev-map").click(function () {
  343. $("#mapDropdown option:selected").prev("option").prop("selected", true).change();
  344. });
  345. // Switch to next map on button click
  346. $("#btn-next-map").click(function () {
  347. $("#mapDropdown option:selected").next("option").prop("selected", true).change();
  348. });
  349. // Trigger change event to load map on startup
  350. if (location.hash) {
  351. $('#mapDropdown').val(location.hash.substr(1) + '.js');
  352. } else { // for IE9
  353. $($('#mapDropdown option')[0]).attr('selected', 'selected');
  354. }
  355. $('#mapDropdown').change();
  356. });
  357. </script>
  358. </head>
  359. <body>
  360. <script src="../../js/highmaps.js"></script>
  361. <script src="http://code.highcharts.com/mapdata/index.js?1"></script>
  362. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js"></script>
  363. <script src="http://www.highcharts.com/samples/maps/demo/all-maps/jquery.combobox.js"></script>
  364. <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet">
  365. <link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
  366. <div id="demo-wrapper">
  367. <div id="mapBox">
  368. <div id="up"></div>
  369. <div class="selector">
  370. <button id="btn-prev-map" class="prev-next"><i class="fa fa-angle-left"></i></button>
  371. <select id="mapDropdown" class="ui-widget combobox"></select>
  372. <button id="btn-next-map" class="prev-next"><i class="fa fa-angle-right"></i></button>
  373. </div>
  374. <div id="container"></div>
  375. </div>
  376. <div id="sideBox">
  377. <input type="checkbox" id="chkDataLabels" checked='checked' />
  378. <label for="chkDataLabels" style="display: inline">Data labels</label>
  379. <div id="infoBox">
  380. <h4>This map</h4>
  381. <div id="download"></div>
  382. </div>
  383. </div>
  384. </div>
  385. </body>
  386. </html>