微信小程序地图找房

var app = getApp();
var config = require('../../config.js');
var url = '/MCommunity:getAllCommunity';

Page({
    data: {
        scale: 10,
        tmpScale: 10,
        location: {
            latitude: 39.90846,
            longitude: 116.397447
        },
        markers: []
    },

    onLoad: function (options) {
        var that = this;
        wx.hideShareMenu();
        wx.showLoading({
            title: '加载中',
        });
        loadData(that);
    },
    bindregionchange:function(e){
        var that = this;
        var MapContext = wx.createMapContext('map1');
        MapContext.getScale(
            {
                success:res => {
                    console.log(res)
                    that.setData({tmpScale:res.scale})
                    console.log(that.data.tmpScale)
                    console.log('aaa')
                    wx.showLoading({
                        title: '加载中',
                    });
                    loadData(that);
                }
            }
        )
    }
});

function loadData(that){
    var param = {};
    param.scale = that.data.tmpScale;
    app.ajaxPost(url, param, function (data) {
        var markers = [];
        wx.hideLoading();
        console.log(data)
        data.forEach(element => {
            console.log(element)
            markers.push(
                {
                    'id':element.document_id,
                    'latitude': element.latitude,
                    'longitude': element.longitude,
                    'iconPath': '/bc/image/point2.gif',
                    'callout':{
                        'content':element.name+"["+element.count+"]",
                        'color':"#ffffff",
                        'bgColor':'#07c160',
                        'padding':5,
                        'fontSize':"14",
                        'borderRadius':"6",
                        'textAlign':"center",
                        'display':'ALWAYS',
                        'anchorY':10
                    }
                }
            )
        });
        console.log(markers)
        that.setData({ markers: markers});
      })
  }
<view class="map-container">
    <map id="map1" class="map" markers="{{markers}}" latitude="{{location.latitude}}" longitude="{{location.longitude}}" 
    scale="{{scale}}" min-scale="10" max-scale="14" bindregionchange="bindregionchange"></map>
</view>


//        if($param['scale'] <= 10 ){
//            $result = $this->houseDistrict($param);
//        }elseif($param['scale'] <= 12){
//            $result = $this->houseRegion($param);
//        }else{
//            $result = $this->houseCommunity($param);
//        }


打赏

看恩吧
网站不承担任何有关评论的责任
  • 最新评论
  • 总共条评论
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦