|
@@ -171,7 +171,7 @@ Page({
|
|
|
const now = Date.now();
|
|
|
if (now - lastTapTime < 1000) return;
|
|
|
lastTapTime = now;
|
|
|
-
|
|
|
+
|
|
|
const { latitude, longitude } = e.detail;
|
|
|
|
|
|
wx.qqmapsdk.reverseGeocoder({
|
|
@@ -179,8 +179,6 @@ Page({
|
|
|
success: (res) => {
|
|
|
const address = res.result.address_component;
|
|
|
const locationDesc = res.result.location_description || '';
|
|
|
-
|
|
|
- // 多维度判断陆地条件
|
|
|
const isValidLand = (
|
|
|
address.nation === '中国' &&
|
|
|
!['香港', '澳门', '台湾'].includes(address.province) &&
|
|
@@ -188,75 +186,65 @@ Page({
|
|
|
!locationDesc.includes('海域') && // 排除描述含海域的关键词
|
|
|
address.district !== '' // 排除无区县信息区域
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
if (isValidLand) {
|
|
|
- console.log('有效陆地点击', latitude, longitude);
|
|
|
- let minDistance = Infinity;
|
|
|
- let closestPoint = null;
|
|
|
+ wx.showLoading({ title: '计算中...' });
|
|
|
|
|
|
- this.excelData.forEach(item => {
|
|
|
- const distance = this.calculateDistance(
|
|
|
- latitude, longitude,
|
|
|
- item.latitude, item.longitude
|
|
|
- );
|
|
|
-
|
|
|
- if (distance < minDistance) {
|
|
|
- minDistance = distance;
|
|
|
- closestPoint = item;
|
|
|
+ // 调用克里金插值接口
|
|
|
+ wx.request({
|
|
|
+ url: 'https://soilgd.com:5000/kriging_interpolation',
|
|
|
+ method: 'POST',
|
|
|
+ header: { 'Content-Type': 'application/json' },
|
|
|
+ data: {
|
|
|
+ file_name: 'emissions.xlsx',
|
|
|
+ emission_column: 'dust_emissions',
|
|
|
+ points: [[longitude, latitude]] // 注意顺序:经度在前
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ wx.hideLoading();
|
|
|
+ if (res.statusCode === 200 && res.data.interpolated_concentrations) {
|
|
|
+ const value = res.data.interpolated_concentrations[0];
|
|
|
+
|
|
|
+ // 创建临时标记
|
|
|
+ const tempMarker = {
|
|
|
+ id: 0,
|
|
|
+ latitude,
|
|
|
+ longitude,
|
|
|
+ iconPath: "../../assets/taddar/marker.png",
|
|
|
+ width: 40,
|
|
|
+ height: 40,
|
|
|
+ callout: {
|
|
|
+ content: `经度: ${longitude.toFixed(4)}\n纬度: ${latitude.toFixed(4)}\npH值: ${value.toFixed(2)}`,
|
|
|
+ display: "ALWAYS",
|
|
|
+ fontSize: 14,
|
|
|
+ color: "#333",
|
|
|
+ bgColor: "#fff",
|
|
|
+ borderColor: "#07c160",
|
|
|
+ borderRadius: 8,
|
|
|
+ borderWidth: 2,
|
|
|
+ padding: 12,
|
|
|
+ anchorY: -10
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 更新标记数组
|
|
|
+ const markers = this.data.markers
|
|
|
+ .filter(m => m.id !== 0)
|
|
|
+ .concat(tempMarker);
|
|
|
+ this.setData({ markers });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ wx.hideLoading();
|
|
|
+ wx.showToast({ title: '计算失败', icon: 'none' });
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
- // 创建临时标记
|
|
|
- const tempMarker = {
|
|
|
- id: 0, // 使用特殊ID标识临时标记
|
|
|
- latitude,
|
|
|
- longitude,
|
|
|
- iconPath: "../../assets/taddar/marker.png", // 建议使用不同图标
|
|
|
- width: 40,
|
|
|
- height: 40,
|
|
|
- callout: {
|
|
|
- content: `经度: ${longitude.toFixed(4)}\n纬度: ${latitude.toFixed(4)}\npH值: ${closestPoint ? closestPoint.dust_emissions.toFixed(2) : '无数据'}`,
|
|
|
- display: "ALWAYS",
|
|
|
- fontSize: 14,
|
|
|
- color: "#333",
|
|
|
- bgColor: "#fff",
|
|
|
- borderColor: "#07c160",
|
|
|
- borderRadius: 8,
|
|
|
- borderWidth: 2,
|
|
|
- padding: 12,
|
|
|
- anchorY: -10
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // 更新标记数组(保留原有标记,替换临时标记)
|
|
|
- const markers = this.data.markers
|
|
|
- .filter(m => m.id !== 0)
|
|
|
- .concat(tempMarker);
|
|
|
-
|
|
|
- this.setData({ markers });
|
|
|
} else {
|
|
|
- wx.showToast({
|
|
|
- title: '非有效陆地区域',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
+ wx.showToast({ title: '非有效陆地区域', icon: 'none' });
|
|
|
}
|
|
|
},
|
|
|
fail: (err) => console.error('接口错误:', err)
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- // 新增距离计算方法
|
|
|
- calculateDistance(lat1, lng1, lat2, lng2) {
|
|
|
- const rad = (angle) => angle * Math.PI / 180;
|
|
|
- const R = 6371; // 地球半径(千米)
|
|
|
-
|
|
|
- const dLat = rad(lat2 - lat1);
|
|
|
- const dLng = rad(lng2 - lng1);
|
|
|
-
|
|
|
- const a = Math.sin(dLat/2) * Math.sin(dLat/2) +
|
|
|
- Math.cos(rad(lat1)) * Math.cos(rad(lat2)) *
|
|
|
- Math.sin(dLng/2) * Math.sin(dLng/2);
|
|
|
-
|
|
|
- return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
|
|
- },
|
|
|
});
|