index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // miniprogram/pages/ruins/index.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. chart: undefined,
  8. data: {
  9. show: false,
  10. ec: {
  11. onInit: undefined,
  12. lazyload: true
  13. },
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady: function () {
  24. this.setData({
  25. ec: {
  26. onInit: this.initChart.bind(this)
  27. }
  28. })
  29. },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow: function () {
  34. },
  35. /**
  36. * 生命周期函数--监听页面隐藏
  37. */
  38. onHide: function () {
  39. },
  40. /**
  41. * 生命周期函数--监听页面卸载
  42. */
  43. onUnload: function () {
  44. this.chart && this.chart.dispose && this.chart.dispose();
  45. },
  46. /**
  47. * 页面相关事件处理函数--监听用户下拉动作
  48. */
  49. onPullDownRefresh: function () {
  50. },
  51. /**
  52. * 页面上拉触底事件的处理函数
  53. */
  54. onReachBottom: function () {
  55. },
  56. /**
  57. * 用户点击右上角分享
  58. */
  59. onShareAppMessage: function () {
  60. },
  61. initChart: async function (canvas, width, height, dpr) {
  62. this.chart && this.chart.dispose && this.chart.dispose();
  63. this.chart = echarts.init(canvas, null, {
  64. width: width,
  65. height: height,
  66. devicePixelRatio: dpr // 像素
  67. });
  68. const db = wx.cloud.database();
  69. const _ = db.command;
  70. let list = await db.collection('map_json').where({
  71. region: _.eq("china")
  72. }).get();
  73. echarts.registerMap('CN', list.data[0].geoJson);
  74. var option = {
  75. tooltip: {
  76. show: false
  77. },
  78. "dataZoom-inside": {
  79. type: "inside"
  80. },
  81. scaleLimit: {
  82. min: 1.25 //缩放最小大小
  83. },
  84. geo: {
  85. map: "CN",
  86. roam: true,//改成true也完全没效果
  87. zoom: 1.25,
  88. scaleLimit: {
  89. //滚轮缩放的极限控制
  90. min: 1.25,
  91. max: 6,
  92. },
  93. top: "middle",
  94. label: {
  95. normal: {
  96. show: true,
  97. fontSize: "10",
  98. color: "rgb(249,80,77)",
  99. },
  100. },
  101. itemStyle: {
  102. normal: {
  103. areaColor: "rgba(0,0,0,0)",
  104. borderColor: "rgb(249,80,77)",
  105. },
  106. emphasis: {
  107. areaColor: "rgba(249,80,77,.3)",
  108. shadowOffsetX: 0,
  109. shadowOffsetY: 0,
  110. borderWidth: 0,
  111. },
  112. },
  113. },
  114. series: [
  115. ]
  116. };
  117. this.chart.setOption(option);
  118. this.chart.on("click", (params) => {
  119. wx.navigateTo({
  120. url: '/pages/provincialArea/index?title=' + params.region.name,
  121. })
  122. })
  123. return this.chart;
  124. }
  125. })