Commit c9ce94f270379beffb45cefff5910ff6ec16bae3

Authored by wangfan
1 parent c5629554

预定地图

@@ -24,6 +24,7 @@ Page({ @@ -24,6 +24,7 @@ Page({
24 height: 50 24 height: 50
25 }], 25 }],
26 seller:{}, 26 seller:{},
  27 + polygons:{},
27 }, 28 },
28 qqmapsdk:null, 29 qqmapsdk:null,
29 /** 30 /**
@@ -93,7 +94,8 @@ Page({ @@ -93,7 +94,8 @@ Page({
93 this.setData({ 94 this.setData({
94 map:map, 95 map:map,
95 }) 96 })
96 - this.getMarkers(); 97 + //this.getMarkers();
  98 + this.getMapPos();
97 }).catch(()=>{ 99 }).catch(()=>{
98 this.selectComponent('#showModal').options({ 100 this.selectComponent('#showModal').options({
99 header:'定位失败', 101 header:'定位失败',
@@ -140,15 +142,19 @@ Page({ @@ -140,15 +142,19 @@ Page({
140 this.selectComponent('#seller-box').show(); 142 this.selectComponent('#seller-box').show();
141 wx.hideTabBar(); 143 wx.hideTabBar();
142 }, 144 },
143 - getMarkers(){ 145 + getMarkers(pos){
144 let map=this.data.map; 146 let map=this.data.map;
145 let markers=[]; 147 let markers=[];
146 - for(var i=1;i<50;i++){ 148 + let count=50;
  149 + let x=(pos[1].latitude-pos[0].latitude)/count;
  150 + let y=(pos[1].longitude-pos[0].longitude)/count;
  151 + for(var i=1;i<count;i++){
  152 + let v=parseInt(Math.random()*10)%2==0?-1:1;
147 markers.push({ 153 markers.push({
148 id: i, 154 id: i,
149 iconPath: "/pages/image/ding.png", 155 iconPath: "/pages/image/ding.png",
150 - latitude: parseFloat(map.latitude) + Math.random()*(parseInt(Math.random()*10)%2==0?-1:1)/500,  
151 - longitude: parseFloat(map.longitude) +Math.random()*(parseInt(Math.random()*10)%2==0?-1:1)/500, 156 + latitude: map.latitude+(x*i*v),
  157 + longitude: map.longitude+(y*i*v),
152 width: 24, 158 width: 24,
153 height: 30, 159 height: 30,
154 title:'店铺名称t'+i, 160 title:'店铺名称t'+i,
@@ -183,8 +189,39 @@ Page({ @@ -183,8 +189,39 @@ Page({
183 markers:markers, 189 markers:markers,
184 }) 190 })
185 }, 191 },
  192 + //seller box 通知
186 sellerBoxEvent(e){ 193 sellerBoxEvent(e){
187 wx.showTabBar(); 194 wx.showTabBar();
188 - } 195 + },
  196 + //根据中心点计算坐标范围
  197 + getMapPos(){
  198 + let map=this.data.map;
  199 + let latitude=parseFloat(map.latitude);
  200 + let longitude=parseFloat(map.longitude);
  201 + let w2=getApp().system.windowWidth/2
  202 + let h2=getApp().system.windowHeight/2
  203 + let ys=w2*map.scale/1000000;
  204 + let xs=h2*map.scale/1000000;
  205 + let polygons=[
  206 + {
  207 + points:[
  208 + {latitude: latitude-xs, longitude: longitude+ys},
  209 +
  210 +
  211 + {latitude: latitude+xs, longitude: longitude+ys},
  212 + {latitude: latitude-xs, longitude: longitude-ys},
  213 +
  214 + {latitude: latitude+xs, longitude: longitude-ys},
189 215
  216 + ],
  217 + strokeWidth:5,
  218 + strokeColor:'#00000055',
  219 + fillColor:'#00000088'
  220 + }
  221 + ];
  222 + this.setData({
  223 + polygons:polygons,
  224 + })
  225 + this.getMarkers([{latitude: latitude-xs, longitude: longitude-ys},{latitude: latitude+xs, longitude: longitude+ys}])
  226 + },
190 }) 227 })
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <view class="page"> 2 <view class="page">
3 <view class="flex-vc map"> 3 <view class="flex-vc map">
4 <map id="map" longitude="{{map.longitude}}" latitude="{{map.latitude}}" scale="{{map.scale}}" 4 <map id="map" longitude="{{map.longitude}}" latitude="{{map.latitude}}" scale="{{map.scale}}"
5 - markers="{{markers}}" 5 + markers="{{markers}}" polygons="{{polygons}}"
6 bindmarkertap="markertap" 6 bindmarkertap="markertap"
7 bindregionchange="regionchange" 7 bindregionchange="regionchange"
8 bindupdated="mapUpdated" 8 bindupdated="mapUpdated"