|
@@ -1,4 +1,5 @@
|
|
|
// pages/map/map.js
|
|
|
+import request from '../../utils/request'
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
@@ -9,55 +10,10 @@ Page({
|
|
|
showlocation: "true", //显示带有方向的当前定位点
|
|
|
showcompass: "true", //显示指南针
|
|
|
enabletraffic: "false", //是否开启实时路况
|
|
|
- longitude: "103.69618", //中心经度
|
|
|
- latitude: "30.61249", //中心纬度
|
|
|
+ longitude: "103.70618", //地图中心经度
|
|
|
+ latitude: "30.51249", //地图中心纬度
|
|
|
//标记点位
|
|
|
- marks: [{
|
|
|
- id: 1,
|
|
|
- latitude: 30.61249,
|
|
|
- longitude: 103.69618,
|
|
|
- title: "崇州万达广场",
|
|
|
- iconPath: "../../images/location.png",
|
|
|
- width: 30,
|
|
|
- height: 30,
|
|
|
- callout: {
|
|
|
- content: '崇州万达广场',
|
|
|
- bgColor: '#fff',
|
|
|
- fontSize: '32rpx',
|
|
|
- display: 'ALWAYS'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- latitude: 30.62249,
|
|
|
- longitude: 103.59618,
|
|
|
- title: "崇州市牛叉村委会",
|
|
|
- iconPath: "../../images/location.png",
|
|
|
- width: 30,
|
|
|
- height: 30,
|
|
|
- callout: {
|
|
|
- content: '崇州市牛叉村委会',
|
|
|
- bgColor: '#fff',
|
|
|
- fontSize: '32rpx',
|
|
|
- display: 'ALWAYS'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- id: 3,
|
|
|
- latitude: 30.62649,
|
|
|
- longitude: 103.63618,
|
|
|
- title: "崇州市牛叉不得了村",
|
|
|
- iconPath: "../../images/location.png",
|
|
|
- width: 30,
|
|
|
- height: 30,
|
|
|
- callout: {
|
|
|
- content: '崇州市牛叉不得了村',
|
|
|
- bgColor: '#fff',
|
|
|
- fontSize: '32rpx',
|
|
|
- display: 'ALWAYS'
|
|
|
- }
|
|
|
- }
|
|
|
- ],
|
|
|
+ marks: [],
|
|
|
//搜索点位
|
|
|
searchmarks: [{
|
|
|
latitude: 30.61249,
|
|
@@ -75,8 +31,34 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad(options) {
|
|
|
+ onLoad: async function (options) {
|
|
|
+
|
|
|
+ let result = await request('/merchant/merchantAndCallout')
|
|
|
+ // console.log("结果数据:", result);
|
|
|
+ var marker = [];
|
|
|
+ for (let i = 0; i < result.length; i++) {
|
|
|
+ //console.log(result[i].status);
|
|
|
+ if (result[i].status == 1) {
|
|
|
+ marker[i] = {
|
|
|
+ id: result[i].id,
|
|
|
+ latitude: result[i].latitude,
|
|
|
+ longitude: result[i].longitude,
|
|
|
+ title: result[i].title,
|
|
|
+ iconPath: "../../images/location.png",
|
|
|
+ width: result[i].width,
|
|
|
+ height: result[i].height,
|
|
|
+ callout: result[i].callout
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // console.log(marker);
|
|
|
+ this.setData({
|
|
|
+ marks:marker,
|
|
|
+ longitude:marker[0].longitude,
|
|
|
+ latitude:marker[0].latitude
|
|
|
+ })
|
|
|
let marks = this.data.marks
|
|
|
+ // console.log(marks);
|
|
|
var arr = new Array(marks.length)
|
|
|
for (let i = 0; i < marks.length; i++) {
|
|
|
let latitude = marks[i].latitude
|
|
@@ -175,12 +157,22 @@ Page({
|
|
|
//点击标记点的事件
|
|
|
bmakt(e) {
|
|
|
// console.log(e.markerId);
|
|
|
- var index = e.markerId - 1;
|
|
|
+ var id = e.markerId;
|
|
|
let marks = this.data.marks
|
|
|
- //拉起外部地图,并传递经纬度和名称
|
|
|
+ var index
|
|
|
+ for(let i = 0;i < marks.length;i++){
|
|
|
+ if(id == marks[i].id){
|
|
|
+ index = i
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let lati = Number(marks[index].latitude)
|
|
|
+ let longti = Number(marks[index].longitude)
|
|
|
+ console.log(lati,longti);
|
|
|
+ // console.log(typeof(lati));
|
|
|
+ // //拉起外部地图,并传递经纬度和名称
|
|
|
wx.openLocation({
|
|
|
- latitude: marks[index].latitude,
|
|
|
- longitude: marks[index].longitude,
|
|
|
+ latitude: lati,
|
|
|
+ longitude: longti,
|
|
|
name: marks[index].title
|
|
|
})
|
|
|
},
|
|
@@ -192,12 +184,12 @@ Page({
|
|
|
},
|
|
|
|
|
|
//返回按钮点击事件
|
|
|
- returnBack(){
|
|
|
+ returnBack() {
|
|
|
let points = this.data.points
|
|
|
const map = wx.createMapContext('map');
|
|
|
map.includePoints({
|
|
|
- points:points,
|
|
|
- padding:[40,40,40,40]
|
|
|
+ points: points,
|
|
|
+ padding: [40, 40, 40, 40]
|
|
|
});
|
|
|
},
|
|
|
|