index.js 2.7 KB

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