93 lines
2.9 KiB
JavaScript
93 lines
2.9 KiB
JavaScript
|
"use strict";
|
||
|
const common_vendor = require("../../common/vendor.js");
|
||
|
const defaultLat = 39.9042;
|
||
|
const defaultLng = 116.4074;
|
||
|
const _sfc_main = {
|
||
|
__name: "index",
|
||
|
setup(__props) {
|
||
|
const keyword = common_vendor.ref("");
|
||
|
const pois = common_vendor.ref([]);
|
||
|
let map = null;
|
||
|
let marker = null;
|
||
|
function initMap(lat, lng) {
|
||
|
const center = new qq.maps.LatLng(lat, lng);
|
||
|
map = new qq.maps.Map(document.getElementById("map"), {
|
||
|
center,
|
||
|
zoom: 15
|
||
|
});
|
||
|
marker = new qq.maps.Marker({
|
||
|
position: center,
|
||
|
map
|
||
|
});
|
||
|
}
|
||
|
async function onSearch() {
|
||
|
const kw = keyword.value.trim();
|
||
|
if (!kw) {
|
||
|
common_vendor.index.showToast({
|
||
|
title: "请输入搜索内容",
|
||
|
icon: "none"
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
pois.value = [];
|
||
|
const center = map.getCenter();
|
||
|
const lat = center.getLat();
|
||
|
const lng = center.getLng();
|
||
|
common_vendor.index.__f__("log", "at pages/map/index.vue:70", "????", url);
|
||
|
const url = `https://apis.map.qq.com/ws/place/v1/search?keyword=${encodeURIComponent(kw)}&boundary=nearby(${lat},${lng},1000)&key=WTPBZ-L3O3T-L6SXZ-VOPZA-FU77K-MPB2G`;
|
||
|
try {
|
||
|
const res = await fetch(url);
|
||
|
const data = await res.json();
|
||
|
if (data.status === 0 && data.data && data.data.length > 0) {
|
||
|
pois.value = data.data.map((item) => ({
|
||
|
name: item.title,
|
||
|
address: item.address,
|
||
|
lat: item.location.lat,
|
||
|
lng: item.location.lng
|
||
|
}));
|
||
|
} else {
|
||
|
common_vendor.index.showToast({
|
||
|
title: "未搜索到结果",
|
||
|
icon: "none"
|
||
|
});
|
||
|
}
|
||
|
} catch (error) {
|
||
|
common_vendor.index.__f__("error", "at pages/map/index.vue:91", "搜索失败:", error);
|
||
|
common_vendor.index.showToast({
|
||
|
title: "搜索失败",
|
||
|
icon: "none"
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
function selectPoi(poi) {
|
||
|
const pos = new qq.maps.LatLng(poi.lat, poi.lng);
|
||
|
map.setCenter(pos);
|
||
|
marker.setPosition(pos);
|
||
|
}
|
||
|
common_vendor.onMounted(() => {
|
||
|
initMap(defaultLat, defaultLng);
|
||
|
});
|
||
|
return (_ctx, _cache) => {
|
||
|
return common_vendor.e({
|
||
|
a: common_vendor.o(onSearch),
|
||
|
b: keyword.value,
|
||
|
c: common_vendor.o(($event) => keyword.value = $event.detail.value),
|
||
|
d: common_vendor.o(onSearch),
|
||
|
e: pois.value.length
|
||
|
}, pois.value.length ? {
|
||
|
f: common_vendor.f(pois.value, (poi, idx, i0) => {
|
||
|
return {
|
||
|
a: common_vendor.t(poi.name),
|
||
|
b: common_vendor.t(poi.address),
|
||
|
c: idx,
|
||
|
d: common_vendor.o(($event) => selectPoi(poi), idx)
|
||
|
};
|
||
|
})
|
||
|
} : {});
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-a3704cdf"]]);
|
||
|
wx.createPage(MiniProgramPage);
|
||
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/map/index.js.map
|