123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const pages_api_luyou = require("../api/luyou.js");
- const _sfc_main = {
- data() {
- return {
- latitude: 38.818143,
- // 保定理工的纬度
- longitude: 115.484621,
- // 保定理工的经度
- scale: 14,
- markers: [],
- polylines: [],
- includePoints: [],
- // 添加要包含在地图视野内的点
- showAllMarkers: false,
- // 是否显示所有景点
- searchKeyword: "",
- selectedLocations: [],
- currentIndex: -1,
- jingdian: [],
- // 存储景点数据
- targetSpotName: "",
- // 目标景点名称
- defaultBaodingSpots: [
- {
- id: 999,
- name: "保定古莲花池",
- pinyin: "baodinggulianhuchi",
- description: "始建于唐代,是保定市著名的风景名胜区,国家AAAA级旅游景区",
- address: "河北省保定市莲池区牌坊街67号",
- city: "保定",
- category: "景区",
- latitude: 38.8743,
- longitude: 115.4646,
- image: "/static/default_attraction.jpg"
- },
- {
- id: 998,
- name: "保定直隶总督署",
- pinyin: "baodingzhilizongedushu",
- description: "中国保存最完整的清代省级衙署,是河北省重点文物保护单位",
- address: "河北省保定市莲池区东风路1399号",
- city: "保定",
- category: "景区",
- latitude: 38.87346,
- longitude: 115.47486,
- image: "/static/default_attraction.jpg"
- },
- {
- id: 997,
- name: "保定野三坡景区",
- pinyin: "baodingyesanpo",
- description: "国家AAAAA级景区,以奇峰、怪石、峡谷、溶洞和清泉著称",
- address: "河北省保定市涞水县野三坡镇",
- city: "保定",
- category: "景区",
- latitude: 39.46082,
- longitude: 115.61501,
- image: "/static/default_attraction.jpg"
- }
- ]
- };
- },
- onLoad(options) {
- if (options.lat && options.lng && options.name) {
- this.latitude = parseFloat(options.lat);
- this.longitude = parseFloat(options.lng);
- this.targetSpotName = decodeURIComponent(options.name);
- this.scale = 15;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:176", `接收到景点定位参数: ${this.targetSpotName}, 坐标: ${this.latitude}, ${this.longitude}`);
- common_vendor.index.showToast({
- title: `定位到: ${this.targetSpotName}`,
- icon: "none",
- duration: 2e3
- });
- }
- this.initMap();
- common_vendor.index.showLoading({
- title: "加载景点数据..."
- });
- this.setDefaultBaodingSpots();
- this.getJingdian();
- },
- methods: {
- // 设置默认保定景点
- setDefaultBaodingSpots() {
- this.jingdian = [...this.defaultBaodingSpots];
- this.latitude = this.defaultBaodingSpots[0].latitude;
- this.longitude = this.defaultBaodingSpots[0].longitude;
- this.createMarkersFromJingdian();
- },
- // 查询景点数据
- getJingdian() {
- pages_api_luyou.findalls().then((res) => {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:218", "API返回原始数据:", JSON.stringify(res));
- common_vendor.index.hideLoading();
- if (res && res.code === 200) {
- this.apiResponse = res;
- let data = null;
- if (res.obj) {
- data = res.obj;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:233", "数据在res.obj中, 长度:", data.length);
- } else if (res.data && res.data.obj) {
- data = res.data.obj;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:236", "数据在res.data.obj中, 长度:", data.length);
- } else if (res.data) {
- data = res.data;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:239", "数据在res.data中, 长度:", data.length);
- } else {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:241", "尝试解析完整响应");
- data = res;
- }
- let apiJingdian = [];
- if (Array.isArray(data)) {
- apiJingdian = data;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:250", "直接使用数组数据, 长度:", apiJingdian.length);
- } else {
- for (const key in data) {
- if (Array.isArray(data[key]) && data[key].length > 0) {
- apiJingdian = data[key];
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:256", `找到数组数据在${key}字段中, 长度:`, apiJingdian.length);
- break;
- }
- }
- }
- if (apiJingdian && apiJingdian.length > 0) {
- const processedApiData = apiJingdian.map((item) => {
- if (!item.latitude || !item.longitude) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:267", `景点${item.name || "未命名"}没有坐标,尝试解析其他字段`);
- if (item.latitudeStr && item.longitudeStr) {
- item.latitude = parseFloat(item.latitudeStr);
- item.longitude = parseFloat(item.longitudeStr);
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:273", `从latitudeStr/longitudeStr字段获取到坐标: ${item.latitude}, ${item.longitude}`);
- } else if (item.lat && item.lng) {
- item.latitude = parseFloat(item.lat);
- item.longitude = parseFloat(item.lng);
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:277", `从lat/lng字段获取到坐标: ${item.latitude}, ${item.longitude}`);
- }
- }
- if (item.latitude)
- item.latitude = Number(item.latitude);
- if (item.longitude)
- item.longitude = Number(item.longitude);
- return item;
- }).filter((item) => {
- const hasValidCoords = item.latitude && item.longitude && !isNaN(Number(item.latitude)) && !isNaN(Number(item.longitude));
- if (!hasValidCoords) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:291", `过滤掉无效坐标的景点: ${item.name || "未命名"}`);
- }
- return hasValidCoords;
- });
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:296", `处理后的有效API景点数据: ${processedApiData.length}个`);
- this.jingdian = [...this.defaultBaodingSpots, ...processedApiData];
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:301", "合并后总景点数据:", this.jingdian.length);
- if (this.jingdian.length > 0) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:303", "第一条数据:", JSON.stringify(this.jingdian[0]));
- }
- common_vendor.index.showToast({
- title: `成功加载${this.jingdian.length}个景点`,
- icon: "success"
- });
- this.createMarkersFromJingdian();
- if (this.targetSpotName) {
- this.selectTargetSpot();
- }
- this.adjustMapViewToShowAllSpots();
- } else {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:322", "API未返回有效景点数据,继续使用默认景点");
- common_vendor.index.showToast({
- title: "使用默认景点数据",
- icon: "none"
- });
- if (this.targetSpotName) {
- this.selectTargetSpot();
- }
- }
- } else {
- common_vendor.index.__f__("error", "at pages/custom-trip/map.vue:334", "API返回错误:", res);
- common_vendor.index.showToast({
- title: res && res.message ? res.message : "查询失败,使用默认景点",
- icon: "none"
- });
- }
- }).catch((error) => {
- common_vendor.index.hideLoading();
- common_vendor.index.__f__("error", "at pages/custom-trip/map.vue:342", "查询失败:", error);
- common_vendor.index.showToast({
- title: "加载API景点失败,使用默认景点",
- icon: "none"
- });
- });
- },
- // 调整地图视野以包含所有景点
- adjustMapViewToShowAllSpots() {
- if (!this.jingdian || this.jingdian.length === 0)
- return;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:354", "调整地图视野以显示所有景点");
- let latSum = 0;
- let lngSum = 0;
- let validSpots = 0;
- this.jingdian.forEach((spot) => {
- if (spot.latitude && spot.longitude) {
- latSum += Number(spot.latitude);
- lngSum += Number(spot.longitude);
- validSpots++;
- }
- });
- if (validSpots > 0) {
- const centerLat = latSum / validSpots;
- const centerLng = lngSum / validSpots;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:376", `设置地图中心点为所有景点的地理中心: ${centerLat}, ${centerLng}`);
- this.latitude = centerLat;
- this.longitude = centerLng;
- }
- },
- // 从景点数据创建标记
- createMarkersFromJingdian() {
- if (!this.jingdian || this.jingdian.length === 0) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:387", "景点数据为空");
- common_vendor.index.showToast({
- title: "景点数据为空",
- icon: "none"
- });
- return;
- }
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:395", "开始创建标记,景点数据长度:", this.jingdian.length);
- [...this.markers];
- const poiMarkers = this.jingdian.filter((poi) => {
- if (!poi) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:403", "发现无效的景点数据(null或undefined)");
- return false;
- }
- const hasCoords = poi.latitude && poi.longitude;
- if (!hasCoords) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:409", `景点${poi.name || "未命名"}没有有效的坐标`);
- return false;
- }
- return true;
- }).map((poi, index) => {
- try {
- const lat = Number(poi.latitude);
- const lng = Number(poi.longitude);
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:417", `处理景点 ID=${poi.id}, 名称=${poi.name}, 坐标: ${lat}, ${lng}`);
- if (isNaN(lat) || isNaN(lng)) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:421", `景点${poi.name}的坐标转换为数字后不有效`);
- return null;
- }
- const iconType = poi.category || poi.type || "attraction";
- const iconPath = this.getMarkerIcon(iconType);
- return {
- id: poi.id || index + 1,
- latitude: lat,
- longitude: lng,
- title: poi.name || poi.title,
- iconPath,
- width: 36,
- // 增大标记尺寸以提高可见度
- height: 36,
- callout: {
- content: poi.name || poi.title,
- color: "#333333",
- fontSize: 12,
- borderRadius: 4,
- padding: 5,
- display: "BYCLICK"
- }
- };
- } catch (error) {
- common_vendor.index.__f__("error", "at pages/custom-trip/map.vue:447", `处理景点${poi.name || "未命名"}时出错:`, error);
- return null;
- }
- }).filter((marker) => marker !== null);
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:452", `生成了${poiMarkers.length}个景点标记`);
- if (poiMarkers.length > 0) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:454", "示例标记:", JSON.stringify(poiMarkers[0]));
- } else {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:456", "没有有效的景点标记生成");
- this.addTestMarker();
- return;
- }
- const selectedMarkers = this.selectedLocations.map((location, index) => {
- return {
- id: 1e3 + index,
- latitude: Number(location.latitude),
- longitude: Number(location.longitude),
- title: location.name,
- iconPath: "/static/marker_selected.png",
- // 使用绝对路径
- width: 40,
- height: 40,
- label: {
- content: (index + 1).toString(),
- color: "#FFFFFF",
- fontSize: 14,
- textAlign: "center",
- anchorX: 0,
- anchorY: -10
- }
- };
- });
- this.markers = [...poiMarkers, ...selectedMarkers];
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:485", `总共有${this.markers.length}个标记点`);
- setTimeout(() => {
- this.checkMarkersVisibility();
- }, 1e3);
- },
- // 检查标记可见性
- checkMarkersVisibility() {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:495", "检查标记可见性");
- if (this.markers.length > 0) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:497", "标记数量:", this.markers.length);
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:498", "地图中心坐标:", this.latitude, this.longitude);
- const firstMarker = this.markers[0];
- if (firstMarker && firstMarker.latitude && firstMarker.longitude) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:503", "移动地图到第一个标记:", firstMarker.latitude, firstMarker.longitude);
- this.latitude = firstMarker.latitude;
- this.longitude = firstMarker.longitude;
- this.scale = 14;
- }
- }
- },
- // 初始化地图
- initMap() {
- common_vendor.index.getLocation({
- type: "gcj02",
- success: (res) => {
- this.latitude = res.latitude;
- this.longitude = res.longitude;
- },
- fail: () => {
- common_vendor.index.showToast({
- title: "获取位置信息失败,使用默认位置",
- icon: "none"
- });
- }
- });
- },
- // 根据POI类型获取不同的图标
- getMarkerIcon(type) {
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const platform = systemInfo.platform;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:535", "当前运行平台:", platform);
- const baseUrl = "/static/";
- let iconName;
- switch (type) {
- case "景区":
- case "著名景点":
- case "历史遗迹":
- case "attraction":
- iconName = "marker_attraction.png";
- break;
- case "酒店":
- case "住宿":
- case "hotel":
- iconName = "marker_hotel.png";
- break;
- case "美食":
- case "餐厅":
- case "restaurant":
- iconName = "marker_restaurant.png";
- break;
- case "购物":
- case "商场":
- case "shopping":
- iconName = "marker_shopping.png";
- break;
- default:
- iconName = "marker_default.png";
- }
- const iconPath = baseUrl + iconName;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:568", `选择的图标路径: ${iconPath}, 类型: ${type}`);
- return iconPath;
- },
- // 搜索位置
- searchLocation() {
- if (!this.searchKeyword.trim()) {
- return;
- }
- if (!this.jingdian || this.jingdian.length === 0) {
- common_vendor.index.showToast({
- title: "景点数据未加载",
- icon: "none"
- });
- return;
- }
- const result = this.jingdian.find(
- (poi) => (poi.name || "").includes(this.searchKeyword) || (poi.address || "").includes(this.searchKeyword) || (poi.description || "").includes(this.searchKeyword)
- );
- if (result && result.latitude && result.longitude) {
- this.latitude = Number(result.latitude);
- this.longitude = Number(result.longitude);
- this.scale = 15;
- common_vendor.index.showToast({
- title: `找到: ${result.name}`,
- icon: "none"
- });
- } else {
- common_vendor.index.showToast({
- title: "未找到相关位置",
- icon: "none"
- });
- }
- },
- // 点击标记
- onMarkerTap(e) {
- const markerId = e.markerId;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:613", "点击了标记:", markerId);
- if (markerId >= 1e3) {
- const index = markerId - 1e3;
- if (index >= 0 && index < this.selectedLocations.length) {
- this.currentIndex = index;
- return;
- }
- }
- const poi = this.jingdian.find((item) => item.id === markerId);
- if (poi) {
- let content = "";
- if (poi.description) {
- content += `描述: ${poi.description}
- `;
- }
- if (poi.address) {
- content += `地址: ${poi.address}
- `;
- }
- if (poi.category) {
- content += `类型: ${poi.category}
- `;
- }
- if (poi.city) {
- content += `城市: ${poi.city}
- `;
- }
- content += "是否添加到行程?";
- common_vendor.index.showModal({
- title: poi.name,
- content,
- confirmText: "添加",
- cancelText: "取消",
- success: (res) => {
- if (res.confirm) {
- const location = {
- id: poi.id,
- name: poi.name,
- latitude: Number(poi.latitude),
- longitude: Number(poi.longitude),
- address: poi.address || poi.city || "",
- type: poi.category || "attraction",
- description: poi.description || ""
- };
- this.addLocation(location);
- }
- }
- });
- }
- },
- // 添加地点到行程
- addLocation(location) {
- const exists = this.selectedLocations.some((item) => item.id === location.id);
- if (exists) {
- common_vendor.index.showToast({
- title: "该地点已在行程中",
- icon: "none"
- });
- return;
- }
- const standardizedLocation = {
- ...location,
- latitude: Number(location.latitude),
- longitude: Number(location.longitude)
- };
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:687", "添加标准化后的地点:", standardizedLocation);
- this.selectedLocations.push(standardizedLocation);
- this.currentIndex = this.selectedLocations.length - 1;
- this.updateSelectedMarkers();
- common_vendor.index.showToast({
- title: "已添加到行程",
- icon: "success"
- });
- },
- // 移除地点
- removeLocation(index) {
- this.selectedLocations.splice(index, 1);
- if (this.currentIndex >= this.selectedLocations.length) {
- this.currentIndex = this.selectedLocations.length - 1;
- }
- this.updateSelectedMarkers();
- },
- // 选择地点
- selectLocation(index) {
- this.currentIndex = index;
- const location = this.selectedLocations[index];
- this.latitude = location.latitude;
- this.longitude = location.longitude;
- },
- // 清空所有地点
- clearAllLocations() {
- if (this.selectedLocations.length === 0)
- return;
- common_vendor.index.showModal({
- title: "确认清空",
- content: "确定要清空所有已添加的地点吗?",
- success: (res) => {
- if (res.confirm) {
- this.selectedLocations = [];
- this.currentIndex = -1;
- this.updateSelectedMarkers();
- }
- }
- });
- },
- // 保存行程
- saveTrip() {
- if (this.selectedLocations.length === 0) {
- common_vendor.index.showToast({
- title: "请至少添加一个地点",
- icon: "none"
- });
- return;
- }
- try {
- common_vendor.index.setStorageSync("selectedLocations", JSON.stringify(this.selectedLocations));
- common_vendor.index.navigateTo({
- url: "/pages/custom-trip/plan-detail",
- success: () => {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:756", "成功跳转到计划详情页");
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/custom-trip/map.vue:759", "跳转到计划详情页失败:", err);
- common_vendor.index.showModal({
- title: "跳转失败",
- content: JSON.stringify(err),
- showCancel: false
- });
- }
- });
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/custom-trip/map.vue:768", "保存位置数据失败:", e);
- common_vendor.index.showToast({
- title: "操作失败,请重试",
- icon: "none"
- });
- }
- },
- // 返回上一页
- goBack() {
- common_vendor.index.navigateBack();
- },
- // 更新选中的标记
- updateSelectedMarkers() {
- this.createMarkersFromJingdian();
- this.updatePolylines();
- },
- // 更新路线连线
- updatePolylines() {
- if (this.selectedLocations.length < 2) {
- this.polylines = [];
- this.markers = this.markers.filter((marker) => marker.id < 2e3 || marker.id >= 3e3);
- return;
- }
- const points = this.selectedLocations.map((location) => {
- return {
- latitude: Number(location.latitude),
- longitude: Number(location.longitude)
- };
- });
- this.polylines = [{
- points,
- color: "#1aad19",
- width: 4,
- dottedLine: false,
- arrowLine: true,
- borderColor: "#ffffff",
- borderWidth: 1
- }];
- let distanceMarkers = [];
- for (let i = 0; i < points.length - 1; i++) {
- const startPoint = points[i];
- const endPoint = points[i + 1];
- const distance = this.calculateDistance(
- startPoint.latitude,
- startPoint.longitude,
- endPoint.latitude,
- endPoint.longitude
- );
- const distanceText = distance < 1e3 ? `${Math.round(distance)}米` : `${(distance / 1e3).toFixed(1)}公里`;
- const midPoint = {
- latitude: (startPoint.latitude + endPoint.latitude) / 2,
- longitude: (startPoint.longitude + endPoint.longitude) / 2
- };
- distanceMarkers.push({
- id: 2e3 + i,
- // 距离标记ID从2000开始
- latitude: midPoint.latitude,
- longitude: midPoint.longitude,
- iconPath: "/static/marker_default.png",
- // 使用默认图标
- width: 0,
- // 设置为0使图标不可见
- height: 0,
- // 设置为0使图标不可见
- callout: {
- content: distanceText,
- color: "#333333",
- fontSize: 12,
- borderRadius: 4,
- borderWidth: 1,
- borderColor: "#1aad19",
- bgColor: "#ffffff",
- padding: 5,
- display: "ALWAYS"
- }
- });
- }
- const otherMarkers = this.markers.filter((marker) => marker.id < 2e3 || marker.id >= 3e3);
- this.markers = [...otherMarkers, ...distanceMarkers];
- },
- // 计算两点之间的距离(使用Haversine公式)
- calculateDistance(lat1, lon1, lat2, lon2) {
- const R = 6371e3;
- const dLat = this.deg2rad(lat2 - lat1);
- const dLon = this.deg2rad(lon2 - lon1);
- const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(this.deg2rad(lat1)) * Math.cos(this.deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
- const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
- return R * c;
- },
- // 角度转弧度
- deg2rad(deg) {
- return deg * (Math.PI / 180);
- },
- // 选择目标景点(从热门目的地跳转来的)
- selectTargetSpot() {
- if (!this.targetSpotName || this.jingdian.length === 0) {
- return;
- }
- const targetSpot = this.jingdian.find(
- (spot) => spot.name === this.targetSpotName || spot.name.includes(this.targetSpotName) || this.targetSpotName.includes(spot.name) && spot.name.length > 2
- );
- if (targetSpot) {
- setTimeout(() => {
- const e = { markerId: targetSpot.id };
- this.onMarkerTap(e);
- }, 1e3);
- } else {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:908", `未找到匹配的目标景点: ${this.targetSpotName}`);
- }
- },
- // 地图加载完成后的处理
- onMapLoaded() {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:914", "地图加载完成");
- if (this.markers && this.markers.length > 0) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:918", "当前地图标记数量:", this.markers.length);
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:919", "第一个标记示例:", JSON.stringify(this.markers[0]));
- } else {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:921", "当前无地图标记");
- }
- this.refreshMarkers();
- },
- // 刷新地图标记
- refreshMarkers() {
- const validMarkers = this.markers.map((marker) => {
- const newMarker = { ...marker };
- if (typeof newMarker.latitude === "string") {
- newMarker.latitude = parseFloat(newMarker.latitude);
- }
- if (typeof newMarker.longitude === "string") {
- newMarker.longitude = parseFloat(newMarker.longitude);
- }
- if (isNaN(newMarker.latitude) || isNaN(newMarker.longitude)) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:946", `忽略无效标记: ID=${newMarker.id}, 标题=${newMarker.title}`);
- return null;
- }
- newMarker.width = 36;
- newMarker.height = 36;
- return newMarker;
- }).filter((m) => m !== null);
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:957", `刷新后有效标记数量: ${validMarkers.length}`);
- if (validMarkers.length > 0) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:959", "刷新后第一个标记:", JSON.stringify(validMarkers[0]));
- }
- this.markers = validMarkers;
- if (validMarkers.length === 0) {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:967", "没有有效标记,添加一个默认测试标记");
- this.addTestMarker();
- }
- },
- // 添加测试标记
- addTestMarker() {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:974", "添加测试标记");
- const testMarker = {
- id: 9999,
- latitude: 38.8743,
- longitude: 115.4646,
- title: "测试标记",
- width: 20,
- height: 20,
- iconPath: "/static/marker_default.png",
- callout: {
- content: "测试标记",
- color: "#333333",
- fontSize: 12,
- borderRadius: 4,
- padding: 5,
- display: "ALWAYS"
- }
- };
- this.markers = [testMarker];
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:996", "添加了测试标记:", JSON.stringify(testMarker));
- this.includePoints = [
- {
- latitude: testMarker.latitude,
- longitude: testMarker.longitude
- }
- ];
- },
- // 添加测试标记并显示
- addTestMarkerAndShow() {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:1009", "手动添加测试标记");
- const currentScale = this.scale;
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:1013", "当前缩放级别:", currentScale);
- this.addTestMarker();
- setTimeout(() => {
- if (this.markers.length > 0) {
- const marker = this.markers[0];
- this.latitude = marker.latitude;
- this.longitude = marker.longitude;
- this.scale = currentScale;
- common_vendor.index.showToast({
- title: "已添加测试标记",
- icon: "success"
- });
- }
- }, 300);
- },
- // 显示标记信息
- showMarkersInfo() {
- if (this.markers.length > 0) {
- const info = {
- 总标记数: this.markers.length,
- 第一个标记: this.markers[0]
- };
- common_vendor.index.showModal({
- title: "标记信息",
- content: JSON.stringify(info, null, 2),
- showCancel: false
- });
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:1046", "当前标记信息:", info);
- } else {
- common_vendor.index.showToast({
- title: "当前没有标记",
- icon: "none"
- });
- }
- },
- // 重新加载标记
- reloadMarkers() {
- common_vendor.index.__f__("log", "at pages/custom-trip/map.vue:1057", "重新加载标记");
- this.markers = [];
- this.createMarkersFromJingdian();
- common_vendor.index.showToast({
- title: `已重载${this.markers.length}个标记`,
- icon: "success"
- });
- },
- // 显示所有景点(手动方法)
- showAllSpots() {
- common_vendor.index.showModal({
- title: "显示所有景点",
- content: "调整地图视图以显示所有景点?这会改变地图缩放级别。",
- success: (res) => {
- if (res.confirm) {
- this.scale = 9;
- this.includePoints = this.markers.map((marker) => ({
- latitude: marker.latitude,
- longitude: marker.longitude
- }));
- this.showAllMarkers = true;
- if (this.markers.length > 0) {
- let latSum = 0, lngSum = 0;
- this.markers.forEach((marker) => {
- latSum += marker.latitude;
- lngSum += marker.longitude;
- });
- this.latitude = latSum / this.markers.length;
- this.longitude = lngSum / this.markers.length;
- common_vendor.index.showToast({
- title: "已显示所有景点",
- icon: "success"
- });
- }
- }
- }
- });
- },
- // 重置地图视图
- resetView() {
- this.showAllMarkers = false;
- this.scale = 14;
- if (this.defaultBaodingSpots.length > 0) {
- this.latitude = this.defaultBaodingSpots[0].latitude;
- this.longitude = this.defaultBaodingSpots[0].longitude;
- }
- common_vendor.index.showToast({
- title: "已重置地图视图",
- icon: "success"
- });
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
- b: $data.latitude,
- c: $data.longitude,
- d: $data.markers,
- e: $data.scale,
- f: common_vendor.o((...args) => $options.onMarkerTap && $options.onMarkerTap(...args)),
- g: $data.polylines,
- h: common_vendor.o((...args) => $options.onMapLoaded && $options.onMapLoaded(...args)),
- i: $data.showAllMarkers ? $data.includePoints : [],
- j: common_vendor.o((...args) => $options.searchLocation && $options.searchLocation(...args)),
- k: $data.searchKeyword,
- l: common_vendor.o(($event) => $data.searchKeyword = $event.detail.value),
- m: common_vendor.o((...args) => $options.addTestMarkerAndShow && $options.addTestMarkerAndShow(...args)),
- n: common_vendor.o((...args) => $options.showMarkersInfo && $options.showMarkersInfo(...args)),
- o: common_vendor.o((...args) => $options.reloadMarkers && $options.reloadMarkers(...args)),
- p: common_vendor.o((...args) => $options.showAllSpots && $options.showAllSpots(...args)),
- q: $data.showAllMarkers
- }, $data.showAllMarkers ? {
- r: common_vendor.o((...args) => $options.resetView && $options.resetView(...args))
- } : {}, {
- s: common_vendor.t($data.selectedLocations.length),
- t: $data.selectedLocations.length > 0
- }, $data.selectedLocations.length > 0 ? {
- v: common_vendor.f($data.selectedLocations, (item, index, i0) => {
- return {
- a: common_vendor.t(index + 1),
- b: common_vendor.t(item.name),
- c: common_vendor.t(item.address),
- d: common_vendor.o(($event) => $options.removeLocation(index), index),
- e: index,
- f: $data.currentIndex === index ? 1 : "",
- g: common_vendor.o(($event) => $options.selectLocation(index), index)
- };
- })
- } : {}, {
- w: common_vendor.o((...args) => $options.clearAllLocations && $options.clearAllLocations(...args)),
- x: common_vendor.o((...args) => $options.saveTrip && $options.saveTrip(...args)),
- y: $data.selectedLocations.length === 0 ? 1 : ""
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/custom-trip/map.js.map
|