Commit 9452bb645386a34981ec6f42f4cd2dedc42341b8

Authored by wangfan
1 parent e4fff4ca

fixbug year

... ... @@ -10,8 +10,8 @@ Page({
*/
data: {
map: {
//latitude: 23.099994,
//longitude: 113.324520,
latitude: 23.099994,
longitude: 113.324520,
scale: mapScale,
height: 300,
},
... ... @@ -48,11 +48,11 @@ Page({
},
onReady: function () {
this.mapCtx = wx.createMapContext('map')
this.mapCtx.moveToLocation({
success:(res)=>{
console.log('moveToLocation',res)
}
})
// this.mapCtx.moveToLocation({
// success:(res)=>{
// console.log('moveToLocation',res)
// }
// })
},
/**
* 生命周期函数--监听页面显示
... ... @@ -62,7 +62,7 @@ Page({
this.setData({
[`map.height`]: getApp().system.windowHeight,
})
//this.getMarkers();
this.getPos();
},
/**
... ... @@ -99,7 +99,6 @@ Page({
onShareAppMessage: function () {
},
/*
getPos(){
this._getPos().then(res => {
console.log('wx.getLocation.then', res);
... ... @@ -110,8 +109,15 @@ Page({
this.setData({
map: map,
})
this.getMarkers();
//this.getMapPos();
this.mapCtx.getRegion({
success:(res)=>{
console.log('regionchange.getRegion',res)
if(res.southwest.latitude!=this.mapData.region.southwest.latitude) {
this.mapData.region = res
this.getMarkers();
}
},
})
}).catch((e) => {
console.log('wx.getLocation.catch', e);
if ('getLocation:fail auth deny' == e.errMsg) {
... ... @@ -132,7 +138,7 @@ Page({
wx.getLocation({
type: 'gcj02',
success: (res) => {
success('getLocation',res)
success(res)
},
fail: (res) => {
fail(res)
... ... @@ -143,7 +149,7 @@ Page({
});
})
},
*/
showModal(e){
wx.openSetting()
},
... ... @@ -152,13 +158,13 @@ Page({
this.mapCtx.getScale({
success:(res)=>{
this.mapData.scale=res.scale;
console.log('getScale',res,this.data.map.scale)
console.log('regionchange.getScale',res,this.data.map.scale)
},
})
this.mapCtx.getCenterLocation({
success:(res)=>{
console.log('getCenterLocation',res)
console.log('regionchange.getCenterLocation',res)
this.mapData.latitude=res.latitude;
this.mapData.longitude=res.longitude;
if(this.mapData.lat=='' && res.latitude.toString().length>6 && res.longitude.toString().length>6){
... ... @@ -169,7 +175,7 @@ Page({
});
this.mapCtx.getRegion({
success:(res)=>{
console.log('getRegion',res)
console.log('regionchange.getRegion',res)
if(res.southwest.latitude!=this.mapData.region.southwest.latitude) {
this.mapData.region = res
this.getMarkers();
... ... @@ -182,22 +188,26 @@ Page({
this.mapCtx.getScale({
success:(res)=>{
this.mapData.scale=res.scale;
console.log('getScale',res,this.data.map.scale)
console.log('mapUpdated.getScale',res,this.data.map.scale)
},
})
this.mapCtx.getCenterLocation({
success:(res)=>{
console.log('getCenterLocation',res)
console.log('mapUpdated.getCenterLocation',res)
this.mapData.latitude=res.latitude;
this.mapData.longitude=res.longitude;
if(this.mapData.lat=='' && res.latitude.toString().length>6 && res.longitude.toString().length>6){
this.mapData.lat=res.latitude;
this.mapData.lng=res.longitude;
}
},
});
this.mapCtx.getRegion({
success:(res)=>{
console.log('getRegion',res)
console.log('mapUpdated.getRegion',res)
if(res.southwest.latitude!=this.mapData.region.southwest.latitude){
this.mapData.region=res
this.getMarkers();
//this.getMarkers();
}
},
... ... @@ -218,11 +228,18 @@ Page({
wx.hideTabBar();
},
getMarkers(){
let cmap=this.data.map;
let map = this.mapData;
//console.log('getMarkers',map.region);
if(!map.region.northeast.latitude) {
return setTimeout(()=>{
this.getMarkers();
},300)
}
let markers = [];
App.Reserve.SellerList({
lat: map.lat,
lng: map.lng,
lat: cmap.latitude,
lng: cmap.longitude,
offset: 0,
rows: 10000,
distance: 100000,
... ... @@ -309,33 +326,6 @@ Page({
sellerBoxEvent(e){
wx.showTabBar();
},
//根据中心点计算坐标范围
getMapPos(){
let map = this.data.map;
let latitude = parseFloat(map.latitude);
let longitude = parseFloat(map.longitude);
let w2 = getApp().system.windowWidth / 2
let h2 = getApp().system.windowHeight / 2
let ys = w2 * map.scale / 1000000;
let xs = h2 * map.scale / 1000000;
let polygons = [
{
points: [
{latitude: latitude - xs, longitude: longitude + ys},
{latitude: latitude + xs, longitude: longitude + ys},
{latitude: latitude - xs, longitude: longitude - ys},
{latitude: latitude + xs, longitude: longitude - ys},
],
strokeWidth: 5,
strokeColor: '#00000055',
fillColor: '#00000088'
}
];
this.setData({
polygons: polygons,
})
this.getMarkers()
},
moveToLocation(){
this.setData({
[`map.scale`]:mapScale,
... ...
... ... @@ -2,6 +2,7 @@
<view class="page">
<view class="flex-vc map">
<map id="map" scale="{{map.scale}}"
longitude="{{map.longitude}}" latitude="{{map.latitude}}"
markers="{{markers}}" polygons="{{polygons}}"
bindmarkertap="markertap"
bindregionchange="regionchange"
... ...