"use strict"; const common_vendor = require("../../../common/vendor.js"); if (!Array) { const _component_van_button = common_vendor.resolveComponent("van-button"); _component_van_button(); } const _sfc_main = { __name: "home", setup(__props) { const GUANGZHOU_CENTER = { latitude: 23.12911, longitude: 113.26436 }; const GUANGZHOU_POIS = [ { id: 1, name: "广州塔", latitude: 23.10641, longitude: 113.32466 }, { id: 2, name: "白云山", latitude: 23.19746, longitude: 113.30249 }, { id: 3, name: "越秀公园", latitude: 23.13927, longitude: 113.26436 }, { id: 4, name: "沙面岛", latitude: 23.10788, longitude: 113.24365 }, { id: 5, name: "陈家祠", latitude: 23.12632, longitude: 113.24849 }, { id: 6, name: "北京路", latitude: 23.12389, longitude: 113.26799 }, { id: 7, name: "上下九", latitude: 23.11696, longitude: 113.24899 }, { id: 8, name: "荔枝博览园", latitude: 22.99405, longitude: 113.32486 }, { id: 9, name: "中山纪念堂", latitude: 23.13146, longitude: 113.26336 }, { id: 10, name: "海心沙", latitude: 23.11446, longitude: 113.32136 } ]; const qqmapsdk = common_vendor.ref(null); const mapContext = common_vendor.ref(null); const center = common_vendor.ref(GUANGZHOU_CENTER); const allMarkers = common_vendor.ref([]); const clusters = common_vendor.ref([]); const includePoints = common_vendor.ref([]); const currentZoom = common_vendor.ref(16); const initMap = () => { qqmapsdk.value = new common_vendor.QQMapWX({ key: "Q5GBZ-2LP6I-LOKGM-UE3UC-TXH7Z-WCFG2" // key }); }; const loadPoints = () => { allMarkers.value = GUANGZHOU_POIS.map((item) => ({ ...item, iconPath: "../../../static/map/point.png", width: 30, height: 30, callout: { content: item.name, color: "#ffffff", bgColor: "#007AFF", padding: 5, borderRadius: 4, display: "ALWAYS" } })); updateClusters(); }; const updateClusters = () => { if (currentZoom.value >= 15) { clusters.value = allMarkers.value; } else { const clusterRadius = 60 / currentZoom.value; const clustered = []; allMarkers.value.forEach((marker) => { let isClustered = false; clustered.forEach((cluster) => { const distance = getDistance( cluster.latitude, cluster.longitude, marker.latitude, marker.longitude ); if (distance < clusterRadius) { isClustered = true; cluster.markers.push(marker); cluster.callout.content = `${cluster.markers.length}个地点`; } }); if (!isClustered) { clustered.push({ ...marker, markers: [marker], callout: { ...marker.callout, content: marker.name } }); } }); clusters.value = clustered.map((cluster) => ({ id: cluster.id, latitude: cluster.latitude, longitude: cluster.longitude, iconPath: cluster.markers.length > 1 ? "../../../static/map/point.png" : "../../../static/map/point.png", width: cluster.markers.length > 1 ? 40 : 30, height: cluster.markers.length > 1 ? 40 : 30, callout: cluster.callout, clusterData: cluster.markers })); } includePoints.value = allMarkers.value.map((m) => ({ latitude: m.latitude, longitude: m.longitude })); }; const getDistance = (lat1, lng1, lat2, lng2) => { const toRad = (d) => d * Math.PI / 180; const R = 6371; const dLat = toRad(lat2 - lat1); const dLng = toRad(lng2 - lng1); const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return R * c * 1e3; }; const onRegionChange = (e) => { if (e.type === "end") { common_vendor.index.createMapContext("myMap").getScale({ success: (res) => { currentZoom.value = res.scale; updateClusters(); } }); } }; common_vendor.onMounted(() => { mapContext.value = common_vendor.index.createMapContext("myMap", this); initMap(); loadPoints(); if (mapContext.value && mapContext.value.getRegion) { mapContext.value.getRegion({ success: (res) => common_vendor.index.__f__("log", "at pages/tabBar/home/home.vue:270", "地图范围:", res), fail: (err) => common_vendor.index.__f__("error", "at pages/tabBar/home/home.vue:271", "地图异常:", err) }); } }); return (_ctx, _cache) => { return { a: center.value.latitude, b: center.value.longitude, c: clusters.value, d: [], e: includePoints.value, f: common_vendor.o(onRegionChange), g: common_vendor.p({ type: "primary" }), h: _ctx.duration }; }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-15dac74a"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/tabBar/home/home.js.map