如何js代码动态修改map上controls的位置
发布于 6 年前 作者 gyang 7549 次浏览 来自 问答

我在地图上放了两个按钮,需要根据屏幕大小调整放置的位置,以保证在所有设备都出现在底部,要怎么实现?

代码如下:

<map id=“map” latitude="{{latitude}}" longitude="{{longitude}}" controls="{{controls}}" show-location=“true”/>

  data: {
    latitude: 52.984402,
    longitude: 133.728972,
    controls: [
      {
        id: 1,
        iconPath: ‘…/images/open.png’,
        position: {          left: 10,          top: 500,          width: 105,          height: 35
        },
        clickable: true
      },
      {
        id: 2,
        iconPath: ‘…/images/pay.png’,
        position: {          left: 300,          top: 500,          width: 105,          height: 35
        },
        clickable: true
      }
    ]
  }

onLoad: function (options) {
    var that = this
    wx.getLocation({
      type: ‘wgs84’,
      success: function (res) {
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude
        })
      }
    })

    var info = wx.getSystemInfoSync();
    //在这里动态修改两个control的left和top值
  },

回到顶部