|
@@ -6,11 +6,12 @@ Page({
|
|
*/
|
|
*/
|
|
data: {
|
|
data: {
|
|
subkey: 'U7XBZ-KCDLU-AUOVO-BO64B-BQ6F2-HNFEI',
|
|
subkey: 'U7XBZ-KCDLU-AUOVO-BO64B-BQ6F2-HNFEI',
|
|
- showlocation: "true",
|
|
|
|
- showcompass: "true",
|
|
|
|
- enabletraffic: "true",
|
|
|
|
- longitude: "103.69618",
|
|
|
|
- latitude: "30.61249",
|
|
|
|
|
|
+ showlocation: "true", //显示带有方向的当前定位点
|
|
|
|
+ showcompass: "true", //显示指南针
|
|
|
|
+ enabletraffic: "false", //是否开启实时路况
|
|
|
|
+ longitude: "103.69618", //中心经度
|
|
|
|
+ latitude: "30.61249", //中心纬度
|
|
|
|
+ //标记点位
|
|
marks: [{
|
|
marks: [{
|
|
id: 1,
|
|
id: 1,
|
|
latitude: 30.61249,
|
|
latitude: 30.61249,
|
|
@@ -18,61 +19,76 @@ Page({
|
|
title: "崇州万达广场",
|
|
title: "崇州万达广场",
|
|
iconPath: "../../images/location.png",
|
|
iconPath: "../../images/location.png",
|
|
width: 30,
|
|
width: 30,
|
|
- height: 30
|
|
|
|
|
|
+ height: 30,
|
|
|
|
+ callout: {
|
|
|
|
+ content: '崇州万达广场',
|
|
|
|
+ bgColor: '#fff',
|
|
|
|
+ fontSize: '32rpx',
|
|
|
|
+ display: 'ALWAYS'
|
|
|
|
+ }
|
|
},
|
|
},
|
|
{
|
|
{
|
|
id: 2,
|
|
id: 2,
|
|
latitude: 30.62249,
|
|
latitude: 30.62249,
|
|
longitude: 103.59618,
|
|
longitude: 103.59618,
|
|
- title: "牛叉村",
|
|
|
|
|
|
+ title: "崇州市牛叉村委会",
|
|
iconPath: "../../images/location.png",
|
|
iconPath: "../../images/location.png",
|
|
width: 30,
|
|
width: 30,
|
|
- height: 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'
|
|
|
|
+ }
|
|
}
|
|
}
|
|
],
|
|
],
|
|
|
|
+ //搜索点位
|
|
searchmarks: [{
|
|
searchmarks: [{
|
|
latitude: 30.61249,
|
|
latitude: 30.61249,
|
|
longitude: 103.69618,
|
|
longitude: 103.69618,
|
|
- title: "中心位置",
|
|
|
|
- iconPath: "../../images/location.png",
|
|
|
|
- width: 30,
|
|
|
|
- height: 30
|
|
|
|
- }],
|
|
|
|
- searchmark: [{
|
|
|
|
- latitude: 0,
|
|
|
|
- longitude: 0,
|
|
|
|
title: "",
|
|
title: "",
|
|
iconPath: "../../images/location.png",
|
|
iconPath: "../../images/location.png",
|
|
width: 30,
|
|
width: 30,
|
|
height: 30
|
|
height: 30
|
|
}],
|
|
}],
|
|
- searchContent:''
|
|
|
|
|
|
+ points: [], //可视页面显示的点数组,通过遍历marks获得
|
|
|
|
+ searchContent: '', //搜索内容
|
|
|
|
+ showSearch: false //是否展示搜索内容区
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
onLoad(options) {
|
|
onLoad(options) {
|
|
-
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- //选择位置
|
|
|
|
- chooseLocation() {
|
|
|
|
- var that = this;
|
|
|
|
- wx.chooseLocation({
|
|
|
|
- success(res) {
|
|
|
|
- console.log(res);
|
|
|
|
- that.setData({
|
|
|
|
- searchmarks: [{
|
|
|
|
- latitude: res.latitude,
|
|
|
|
- longitude: res.longitude,
|
|
|
|
- title: res.name,
|
|
|
|
- iconPath: "../../images/location.png",
|
|
|
|
- width: 30,
|
|
|
|
- height: 30
|
|
|
|
- }]
|
|
|
|
- })
|
|
|
|
|
|
+ let marks = this.data.marks
|
|
|
|
+ var arr = new Array(marks.length)
|
|
|
|
+ for (let i = 0; i < marks.length; i++) {
|
|
|
|
+ let latitude = marks[i].latitude
|
|
|
|
+ let longitude = marks[i].longitude
|
|
|
|
+ arr[i] = {
|
|
|
|
+ longitude,
|
|
|
|
+ latitude
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ // console.log(arr);
|
|
|
|
+ this.setData({
|
|
|
|
+ points: arr
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
|
|
@@ -85,92 +101,104 @@ Page({
|
|
// map.moveToLocation();
|
|
// map.moveToLocation();
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ // 输入框聚焦时的事件
|
|
|
|
+ getList() {
|
|
|
|
+ this.setData({
|
|
|
|
+ showSearch: true,
|
|
|
|
+ searchContent: ''
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ //定义模糊查找的函数
|
|
|
|
+ findTarget(list, keyword, attribute = "name") {
|
|
|
|
+ const reg = new RegExp(keyword)
|
|
|
|
+ const arr = []
|
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
|
+ if (reg.test(list[i][attribute])) {
|
|
|
|
+ arr.push(list[i])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return arr
|
|
|
|
+ },
|
|
|
|
|
|
//获取输入的搜索数据
|
|
//获取输入的搜索数据
|
|
- getSearchInput(e){
|
|
|
|
|
|
+ getSearchInput(e) {
|
|
// console.log(e.detail.value);
|
|
// console.log(e.detail.value);
|
|
this.setData({
|
|
this.setData({
|
|
- searchContent:e.detail.value
|
|
|
|
|
|
+ searchContent: e.detail.value
|
|
})
|
|
})
|
|
// console.log(this.data.searchContent);
|
|
// console.log(this.data.searchContent);
|
|
|
|
+ let marks = this.data.marks
|
|
|
|
+ let searchContent = this.data.searchContent
|
|
|
|
+ let arr = this.findTarget(marks, searchContent, 'title')
|
|
|
|
+ if (arr.length) {
|
|
|
|
+ this.setData({
|
|
|
|
+ searchmarks: arr
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ // console.log(this.data.searchmarks);
|
|
},
|
|
},
|
|
|
|
|
|
- //搜索按钮功能
|
|
|
|
- toSearch(){
|
|
|
|
- var that = this
|
|
|
|
|
|
+
|
|
|
|
+ // 点击搜索待选区选项的事件
|
|
|
|
+ myChosed(e) {
|
|
|
|
+ // console.log(e.currentTarget.dataset.index);
|
|
|
|
+ let index = e.currentTarget.dataset.index
|
|
let marks = this.data.marks
|
|
let marks = this.data.marks
|
|
|
|
+ let searchmarks = this.data.searchmarks
|
|
let searchContent = this.data.searchContent
|
|
let searchContent = this.data.searchContent
|
|
- if(!searchContent){
|
|
|
|
- wx.showModal({
|
|
|
|
- title:'搜索失败',
|
|
|
|
- content: '您还没有输入要搜索的内容,无法进行搜索',
|
|
|
|
|
|
+ if (!searchContent) {
|
|
|
|
+ this.setData({
|
|
|
|
+ searchContent: marks[index].title,
|
|
|
|
+ showSearch: false
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ this.setData({
|
|
|
|
+ searchContent: searchmarks[index].title,
|
|
|
|
+ showSearch: false
|
|
})
|
|
})
|
|
- return
|
|
|
|
- }
|
|
|
|
- var flag = false
|
|
|
|
- var length = searchContent.length
|
|
|
|
-
|
|
|
|
- // console.log(length);
|
|
|
|
- for(let i = 0;i < length;i++){
|
|
|
|
- var mText = marks[i].title
|
|
|
|
- for(let x = 0,y = length - i;y <= length;x++,y++){
|
|
|
|
- var sContent = searchContent.substring(x,y)
|
|
|
|
- // if(mText.contains(sContent)){
|
|
|
|
- // wx.showModal({
|
|
|
|
- // content: '找到了',
|
|
|
|
- // })
|
|
|
|
- // }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
- // for(let i = 0;i < marks.length;i++){
|
|
|
|
- // console.log(marks[i].title);
|
|
|
|
- // if(searchContent == marks[i].title){
|
|
|
|
- // that.setData({
|
|
|
|
- // searchmarks: [{
|
|
|
|
- // latitude: marks[i].latitude,
|
|
|
|
- // longitude: marks[i].longitude,
|
|
|
|
- // title: marks[i].title,
|
|
|
|
- // iconPath: "../../images/location.png",
|
|
|
|
- // width: 30,
|
|
|
|
- // height: 30
|
|
|
|
- // }]
|
|
|
|
- // })
|
|
|
|
- // flag = true
|
|
|
|
- // console.log(flag);
|
|
|
|
- // break
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // if(!flag){
|
|
|
|
- // wx.showModal({
|
|
|
|
- // title: '未找到',
|
|
|
|
- // content:'您输入的目标未找到,请您核实后重新输入'
|
|
|
|
- // })
|
|
|
|
- // }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- //拉起外部导航
|
|
|
|
- goLocat() {
|
|
|
|
- wx.getLocation({
|
|
|
|
- type: 'gcj02',
|
|
|
|
- success: (res) => {
|
|
|
|
- console.log(res);
|
|
|
|
- // this.setData({
|
|
|
|
- // latitude: res.latitude,
|
|
|
|
- // longitude: res.longitude
|
|
|
|
- // })
|
|
|
|
- wx.openLocation({
|
|
|
|
- latitude: res.latitude,
|
|
|
|
- longitude: res.longitude,
|
|
|
|
-
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ let arr = this.findTarget(marks, this.data.searchContent, 'title')
|
|
|
|
+ this.setData({
|
|
|
|
+ searchmarks: arr
|
|
|
|
+ })
|
|
|
|
+ // console.log(this.data.searchContent);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ //点击蒙层的事件
|
|
|
|
+ shut() {
|
|
|
|
+ this.setData({
|
|
|
|
+ showSearch: false
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
|
|
//点击标记点的事件
|
|
//点击标记点的事件
|
|
bmakt(e) {
|
|
bmakt(e) {
|
|
- console.log(e.markerId);
|
|
|
|
- this.goLocat()
|
|
|
|
|
|
+ // console.log(e.markerId);
|
|
|
|
+ var index = e.markerId - 1;
|
|
|
|
+ let marks = this.data.marks
|
|
|
|
+ //拉起外部地图,并传递经纬度和名称
|
|
|
|
+ wx.openLocation({
|
|
|
|
+ latitude: marks[index].latitude,
|
|
|
|
+ longitude: marks[index].longitude,
|
|
|
|
+ name: marks[index].title
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ //我的位置点击事件
|
|
|
|
+ myLocate() {
|
|
|
|
+ const map = wx.createMapContext('map');
|
|
|
|
+ map.moveToLocation();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ //返回按钮点击事件
|
|
|
|
+ returnBack(){
|
|
|
|
+ let points = this.data.points
|
|
|
|
+ const map = wx.createMapContext('map');
|
|
|
|
+ map.includePoints({
|
|
|
|
+ points:points,
|
|
|
|
+ padding:[40,40,40,40]
|
|
|
|
+ });
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|