// pages/1/page1.js
Page({
  data: {
      longitude: 115.826611, //经度
      latitude: 39.672935, //维度
      scale: 15, //地图默认缩放等级
      markers: [], //点位数据
      showModal: false, //弹框显隐
      modalData: {}, //详情信息
  },

  onLoad: function () {
      //初始化地图
      this.mapCtx = wx.createMapContext('map');
      //加载点位数据
      this.loadMarkers();
  },

  loadMarkers: function () {
      //模拟点位数据，可以用接口请求获取真实数据
      let markers = [{
              id: 1,
              longitude: 115.815736,
              latitude: 39.675859,
              iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/云水洞.jpg',
              url:'/pages/2/page2',
          },
          {
              id: 2,
              longitude: 115.827153,
              latitude: 39.675562,
              iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/2.jpg'
          },
          {
              id: 3,
              longitude: 115.821417,
              latitude: 39.663736,
              iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/3.jpg'
          },
          {
            id: 4,
            longitude: 115.822318,
            latitude: 39.672731,
            iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/望佛台.jpg',
            url:'/pages/3/page3',
         },
         {
          id: 5,
          longitude: 115.821187,
          latitude: 39.663428,
          iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/5.jpg',
       },
       {
        id: 6,
        longitude: 115.821797,
        latitude: 39.664537,
        iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/6.jpg',
     },
     {
      id: 7,
      longitude: 115.822378,
      latitude: 39.665101,
      iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/7.jpg',
   }, 
   {
    id: 9,
    longitude: 115.826658,
    latitude: 39.670876,
    iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/9.jpg',
 },    
 {
  id: 10,
  longitude: 115.826917,
  latitude: 39.674998,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/10.jpg',
}, 
{
  id: 11,
  longitude: 115.828262,
  latitude: 39.675978,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/11.jpg',
},   
{
  id: 12,
  longitude: 115.828698,
  latitude: 39.676776,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/12.jpg',
},
{
  id: 13,
  longitude: 115.825339,
  latitude: 39.677772,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/13.jpg',
},
{
  id: 14,
  longitude: 115.826978,
  latitude: 39.676819,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/14.jpg',
},
{
  id: 15,
  longitude: 115.822209,
  latitude: 39.672925,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/15.jpg',
},
{
  id: 16,
  longitude: 115.823574,
  latitude: 39.674955,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/16.jpg',
},
{
  id: 17,
  longitude: 115.826095,
  latitude: 39.675027,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/17.jpg',
},
{
  id: 18,
  longitude: 115.820159,
  latitude: 39.673257,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/18.jpg',
},
{
  id: 19,
  longitude: 115.818848,
  latitude: 39.674592,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/19.jpg',
},
{
  id: 20,
  longitude: 115.816239,
  latitude: 39.675833,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/20.jpg',
},
{
  id: 21,
  longitude: 115.817548,
  latitude: 39.676506,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/21.jpg',
  url:'/pages/4/page4',
},
{
  id: 22,
  longitude: 115.827715,
  latitude: 39.67347,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/视频.jpg',
  url:'/pages/5/page5',
},
{
  id: 23,
  longitude: 115.822209,
  latitude: 39.67487,
  iconPath: 'cloud://cloud1-1gyrfhlpd08770de.636c-cloud1-1gyrfhlpd08770de-1319290214/image111/123.jpg',
  url:'/pages/9/page9',
},
      ];
      //生成 markers 列表，用于在地图上展示
      let markersData = markers.map(marker => {
          return {
              id: marker.id,
              longitude: marker.longitude,
              latitude: marker.latitude,
              iconPath: marker.iconPath,
              url:marker.url,
              width: 40,
              height: 40,
          };
      });
      this.setData({
          markers: markersData
      });
  },
  // 点击标记点时触发
  markertap(e) {
    // 获取被点击的标记点id
    const { markerId } = e.detail;
    
    // 根据标记点id获取对应的标记点对象
    const marker = this.data.markers.find(item => item.id === markerId);
    
    // 跳转到指定的页面
    if (marker && marker.url) {
      wx.navigateTo({
        url: marker.url,
      });
    }
  }
})
