@ -1,77 +0,0 @@
|
||||
// map.js
|
||||
let schoolData = require('../../resources/gis-school')
|
||||
Page({
|
||||
data: {
|
||||
centerX:113.3245211,
|
||||
centerY:23.10229,
|
||||
markers: [],
|
||||
controls: [{
|
||||
id: 1,
|
||||
iconPath: '/image/location-control.png',
|
||||
position: {
|
||||
left: 0,
|
||||
top:10,
|
||||
width: 40,
|
||||
height: 40
|
||||
},
|
||||
clickable: true
|
||||
}]
|
||||
},
|
||||
onReady: function (e) {
|
||||
// 使用 wx.createMapContext 获取 map 上下文
|
||||
this.mapCtx = wx.createMapContext('myMap')
|
||||
},
|
||||
onLoad: function () {
|
||||
console.log('地图定位!')
|
||||
let that = this
|
||||
wx.getLocation({
|
||||
type: 'gcj02', //返回可以用于wx.openLocation的经纬度
|
||||
success:(res)=>{
|
||||
console.log(res)
|
||||
let latitude = res.latitude;
|
||||
let longitude = res.longitude;
|
||||
let marker=this.createMarker(res);
|
||||
this.setData({
|
||||
centerX:longitude,
|
||||
centerY:latitude,
|
||||
markers:this.getSchoolMarkers()
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
regionchange(e) {
|
||||
console.log(e.type)
|
||||
},
|
||||
markertap(e) {
|
||||
console.log(e)
|
||||
},
|
||||
controltap(e) {
|
||||
console.log(e.controlId)
|
||||
this.moveToLocation()
|
||||
},
|
||||
getSchoolMarkers(){
|
||||
let markers=[];
|
||||
for(let item of schoolData){
|
||||
let marker=this.createMarker(item);
|
||||
markers.push(marker)
|
||||
}
|
||||
return markers;
|
||||
},
|
||||
moveToLocation: function () {
|
||||
this.mapCtx.moveToLocation()
|
||||
},
|
||||
createMarker(point){
|
||||
let latitude = point.latitude;
|
||||
let longitude = point.longitude;
|
||||
let marker= {
|
||||
iconPath: "/image/location.png",
|
||||
id:point.id || 0,
|
||||
name:point.name || '',
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
width: 25,
|
||||
height: 48
|
||||
};
|
||||
return marker;
|
||||
}
|
||||
})
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"navigationBarTitleText": "地图标注"
|
||||
}
|
@ -1 +0,0 @@
|
||||
<map id="map" scale="5" controls="{{controls}}" bindcontroltap="controltap" markers="{{markers}}" bindmarkertap="markertap" bindregionchange="regionchange" show-location style="width: 100%; height: 580px;"></map>
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 156 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 173 KiB After Width: | Height: | Size: 173 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 906 B After Width: | Height: | Size: 906 B |
Before Width: | Height: | Size: 155 KiB After Width: | Height: | Size: 155 KiB |
Before Width: | Height: | Size: 328 KiB After Width: | Height: | Size: 328 KiB |
Before Width: | Height: | Size: 181 KiB After Width: | Height: | Size: 181 KiB |
After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 139 KiB |
@ -0,0 +1,36 @@
|
||||
var amapFile = require('../../utils/amap-wx.js');
|
||||
var app = getApp();
|
||||
|
||||
Page({
|
||||
data: {
|
||||
city:"天津",
|
||||
weather:"晴",
|
||||
temperature:"10",
|
||||
windpower:"18级",
|
||||
winddirection:"南",
|
||||
humidity:"5",
|
||||
},
|
||||
onLoad: function(options){
|
||||
var that = this;
|
||||
var myAmapFun = new amapFile.AMapWX({key:'78a99442f6e5cad3bfb832e33bdcf629'});
|
||||
myAmapFun.getWeather({
|
||||
success: function(res){
|
||||
//成功回调
|
||||
console.log("调取天气接口成功", res)
|
||||
// 一定要在接口里进行赋值,否则接口数据还未返回,页面就已经将数据取走进行显示
|
||||
that.setData({
|
||||
city: res.city.data,
|
||||
weather: res.weather.data,
|
||||
temperature: res.temperature.data,
|
||||
windpower: res.windpower.data,
|
||||
winddirection: res.winddirection.data,
|
||||
humidity: res.humidity.data
|
||||
})
|
||||
},
|
||||
fail: function(info){
|
||||
//失败回调
|
||||
console.log(info)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|