map.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <script type="text/javascript" src="../s/raphael/raphael-min.js"></script>
  2. <script type="text/javascript" src="../s/map/geomap-0.5.4.js"></script>
  3. <div id="map" style="width:100%;height:100%;margin-top:40px;">
  4. </div>
  5. <div id="tooltip" style="position:absolute;padding:10px;background:#fff;border:5px solid #708090;display:none;">
  6. </div>
  7. <script>
  8. var cities = {
  9. '北京': {y:39.90,x:116.42},
  10. '上海': {y:31.14,x:121.29},
  11. '香港': {y:22.39,x:114.1},
  12. '台北': {y:25.03,x:121.30}
  13. };
  14. //实例化一个GeoMap对象
  15. var map = new GeoMap({
  16. //指定地图渲染位置
  17. container: '#map'
  18. });
  19. var color,
  20. city,
  21. p,
  22. arr = map.canvas.set(),
  23. tooltip = $('#tooltip');
  24. //ajax获取地图数据
  25. $.ajax({
  26. url: '../s/map/china.geo.json',
  27. dataType: 'json'
  28. }).done(function(json){
  29. //地图对象加载数据
  30. map.load(json);
  31. //渲染
  32. map.render();
  33. map.shapes.hover(function(e){
  34. this[0].setAttribute('fill', 'yellow');
  35. e = $.event.fix(e);
  36. var self = this,
  37. top = e.pageY,
  38. left = e.pageX;
  39. tooltip.html(self.data('properties').name).css({
  40. "top" : top,
  41. "left" : left + 10,
  42. "line-height" : "200%",
  43. "font-size": "12px"
  44. }).show();
  45. }, function(e) {
  46. this[0].setAttribute('fill', 'white');
  47. tooltip.empty().hide();
  48. });
  49. });
  50. </script>