wangzhibo
2025-10-23 cad64c1de2c45856b0774933c5801b05b64984e8
1
"use strict";const t=require("../../../../common/vendor.js"),e=require("../../../../pages/guide/markers.js"),o=require("../../../../pages/guide/routes.js"),a=require("../../../../common/assets.js");function s(t){this.key=t.key,this.requestConfig={key:t.key,s:"rsx",platform:"WXJS",appname:t.key,sdkversion:"1.2.0",logversion:"2.0"}}s.prototype.getWxLocation=function(e,o){t.index.getLocation({type:"gcj02",success:function(e){var a=e.longitude+","+e.latitude;t.index.setStorage({key:"userLocation",data:a}),o(a)},fail:function(e){t.index.getStorage({key:"userLocation",success:function(t){t.data&&o(t.data)}})}})},s.prototype.getRegeo=function(e){function o(o){var s=a.requestConfig;t.index.request({url:"https://restapi.amap.com/v3/geocode/regeo",data:{key:a.key,location:o,extensions:"all",s:s.s,platform:s.platform,appname:a.key,sdkversion:s.sdkversion,logversion:s.logversion},method:"GET",header:{"content-type":"application/json"},success:function(t){var a,s,i,r,n,c,d,p,l;t.data.status&&"1"==t.data.status?(s=(a=t.data.regeocode).addressComponent,i=[],r="",a&&a.roads[0]&&a.roads[0].name&&(r=a.roads[0].name+"附近"),n=o.split(",")[0],c=o.split(",")[1],a.pois&&a.pois[0]&&(r=a.pois[0].name+"附近",(d=a.pois[0].location)&&(n=parseFloat(d.split(",")[0]),c=parseFloat(d.split(",")[1]))),s.provice&&i.push(s.provice),s.city&&i.push(s.city),s.district&&i.push(s.district),s.streetNumber&&s.streetNumber.street&&s.streetNumber.number?(i.push(s.streetNumber.street),i.push(s.streetNumber.number)):(p="",a&&a.roads[0]&&a.roads[0].name&&(p=a.roads[0].name),i.push(p)),i=i.join(""),l=[{iconPath:e.iconPath,width:e.iconWidth,height:e.iconHeight,name:i,desc:r,longitude:n,latitude:c,id:0,regeocodeData:a}],e.success(l)):(null==e?void 0:e.fail)&&e.fail({errCode:t.data.infocode,errMsg:t.data.info})},fail:function(t){e.fail({errCode:"0",errMsg:t.errMsg||""})}})}var a=this;e.location?o(e.location):a.getWxLocation(e,(function(t){o(t)}))},s.prototype.getWeather=function(e){function o(o){var i="base";e.type&&"forecast"==e.type&&(i="all"),t.index.request({url:"https://restapi.amap.com/v3/weather/weatherInfo",data:{key:a.key,city:o,extensions:i,s:s.s,platform:s.platform,appname:a.key,sdkversion:s.sdkversion,logversion:s.logversion},method:"GET",header:{"content-type":"application/json"},success:function(t){var o,a,s;t.data.status&&"1"==t.data.status?t.data.lives?(o=t.data.lives)&&o.length>0&&(o=o[0],(a={city:{text:"城市",data:(s=o).city},weather:{text:"天气",data:s.weather},temperature:{text:"温度",data:s.temperature},winddirection:{text:"风向",data:s.winddirection+"风"},windpower:{text:"风力",data:s.windpower+"级"},humidity:{text:"湿度",data:s.humidity+"%"}}).liveData=o,e.success(a)):t.data.forecasts&&t.data.forecasts[0]&&e.success({forecast:t.data.forecasts[0]}):e.fail({errCode:t.data.infocode,errMsg:t.data.info})},fail:function(t){e.fail({errCode:"0",errMsg:t.errMsg||""})}})}var a=this,s=a.requestConfig;e.city?o(e.city):a.getWxLocation(e,(function(i){var r;r=i,t.index.request({url:"https://restapi.amap.com/v3/geocode/regeo",data:{key:a.key,location:r,extensions:"all",s:s.s,platform:s.platform,appname:a.key,sdkversion:s.sdkversion,logversion:s.logversion},method:"GET",header:{"content-type":"application/json"},success:function(t){var a,s;t.data.status&&"1"==t.data.status?((s=t.data.regeocode).addressComponent?a=s.addressComponent.adcode:s.aois&&s.aois.length>0&&(a=s.aois[0].adcode),o(a)):e.fail({errCode:t.data.infocode,errMsg:t.data.info})},fail:function(t){e.fail({errCode:"0",errMsg:t.errMsg||""})}})}))},s.prototype.getPoiAround=function(e){function o(o){var i={key:a.key,location:o,s:s.s,platform:s.platform,appname:a.key,sdkversion:s.sdkversion,logversion:s.logversion};e.querytypes&&(i.types=e.querytypes),e.querykeywords&&(i.keywords=e.querykeywords),t.index.request({url:"https://restapi.amap.com/v3/place/around",data:i,method:"GET",header:{"content-type":"application/json"},success:function(t){var o,a,s,i;if(t.data.status&&"1"==t.data.status){if((t=t.data)&&t.pois){for(o=[],a=0;a<t.pois.length;a++)s=0==a?e.iconPathSelected:e.iconPath,o.push({latitude:parseFloat(t.pois[a].location.split(",")[1]),longitude:parseFloat(t.pois[a].location.split(",")[0]),iconPath:s,width:22,height:32,id:a,name:t.pois[a].name,address:t.pois[a].address});i={markers:o,poisData:t.pois},e.success(i)}}else e.fail({errCode:t.data.infocode,errMsg:t.data.info})},fail:function(t){e.fail({errCode:"0",errMsg:t.errMsg||""})}})}var a=this,s=a.requestConfig;e.location?o(e.location):a.getWxLocation(e,(function(t){o(t)}))},s.prototype.getStaticmap=function(t){function e(e){s.push("location="+e),t.zoom&&s.push("zoom="+t.zoom),t.size&&s.push("size="+t.size),t.scale&&s.push("scale="+t.scale),t.markers&&s.push("markers="+t.markers),t.labels&&s.push("labels="+t.labels),t.paths&&s.push("paths="+t.paths),t.traffic&&s.push("traffic="+t.traffic);var o=i+s.join("&");t.success({url:o})}var o,a=this,s=[],i="https://restapi.amap.com/v3/staticmap?";s.push("key="+a.key),o=a.requestConfig,s.push("s="+o.s),s.push("platform="+o.platform),s.push("appname="+o.appname),s.push("sdkversion="+o.sdkversion),s.push("logversion="+o.logversion),t.location?e(t.location):a.getWxLocation(t,(function(t){e(t)}))},s.prototype.getInputtips=function(e){var o=this,a=o.requestConfig,s={key:o.key,s:a.s,platform:a.platform,appname:o.key,sdkversion:a.sdkversion,logversion:a.logversion};e.location&&(s.location=e.location),e.keywords&&(s.keywords=e.keywords),e.type&&(s.type=e.type),e.city&&(s.city=e.city),e.citylimit&&(s.citylimit=e.citylimit),t.index.request({url:"https://restapi.amap.com/v3/assistant/inputtips",data:s,method:"GET",header:{"content-type":"application/json"},success:function(t){t&&t.data&&t.data.tips&&e.success({tips:t.data.tips})},fail:function(t){e.fail({errCode:"0",errMsg:t.errMsg||""})}})},s.prototype.getDrivingRoute=function(e){var o=this,a=o.requestConfig,s={key:o.key,s:a.s,platform:a.platform,appname:o.key,sdkversion:a.sdkversion,logversion:a.logversion};e.origin&&(s.origin=e.origin),e.destination&&(s.destination=e.destination),e.strategy&&(s.strategy=e.strategy),e.waypoints&&(s.waypoints=e.waypoints),e.avoidpolygons&&(s.avoidpolygons=e.avoidpolygons),e.avoidroad&&(s.avoidroad=e.avoidroad),t.index.request({url:"https://restapi.amap.com/v3/direction/driving",data:s,method:"GET",header:{"content-type":"application/json"},success:function(t){t&&t.data&&t.data.route&&e.success({paths:t.data.route.paths,taxi_cost:t.data.route.taxi_cost||""})},fail:function(t){e.fail({errCode:"0",errMsg:t.errMsg||""})}})},s.prototype.getWalkingRoute=function(e){var o=this,a=o.requestConfig,s={key:o.key,s:a.s,platform:a.platform,appname:o.key,sdkversion:a.sdkversion,logversion:a.logversion};e.origin&&(s.origin=e.origin),e.destination&&(s.destination=e.destination),t.index.request({url:"https://restapi.amap.com/v3/direction/walking",data:s,method:"GET",header:{"content-type":"application/json"},success:function(t){t&&t.data&&t.data.route&&e.success({paths:t.data.route.paths})},fail:function(t){e.fail({errCode:"0",errMsg:t.errMsg||""})}})},s.prototype.getTransitRoute=function(e){var o=this,a=o.requestConfig,s={key:o.key,s:a.s,platform:a.platform,appname:o.key,sdkversion:a.sdkversion,logversion:a.logversion};e.origin&&(s.origin=e.origin),e.destination&&(s.destination=e.destination),e.strategy&&(s.strategy=e.strategy),e.city&&(s.city=e.city),e.cityd&&(s.cityd=e.cityd),t.index.request({url:"https://restapi.amap.com/v3/direction/transit/integrated",data:s,method:"GET",header:{"content-type":"application/json"},success:function(t){if(t&&t.data&&t.data.route){var o=t.data.route;e.success({distance:o.distance||"",taxi_cost:o.taxi_cost||"",transits:o.transits})}},fail:function(t){e.fail({errCode:"0",errMsg:t.errMsg||""})}})},s.prototype.getRidingRoute=function(e){var o=this,a=o.requestConfig,s={key:o.key,s:a.s,platform:a.platform,appname:o.key,sdkversion:a.sdkversion,logversion:a.logversion};e.origin&&(s.origin=e.origin),e.destination&&(s.destination=e.destination),t.index.request({url:"https://restapi.amap.com/v4/direction/bicycling",data:s,method:"GET",header:{"content-type":"application/json"},success:function(t){t&&t.data&&t.data.data&&e.success({paths:t.data.data.paths})},fail:function(t){e.fail({errCode:"0",errMsg:t.errMsg||""})}})};const i={name:"amap",props:{longitude:{type:String,default:""},latitude:{type:String,default:""},mapKey:{require:!0,type:String,default:""},marker:{type:Object,default:()=>{}},disable:{type:Boolean,default:!1},isPolygons:{type:Boolean,default:!1},polygons:{type:Array,default:()=>[]},top:{type:[String,Number],default:30},isCustomBar:{type:Boolean,default:!1}},data(){var t,e,o;return{statusBarH:0,customBarH:0,addressMap:"",searchValue:"",markers:[],amapPlugin:null,key:null==(t=this.$props)?void 0:t.mapKey,center_lat:null==(e=this.$props)?void 0:e.latitude,center_lon:null==(o=this.$props)?void 0:o.longitude,center_scale:18,regeocodeData:{},searchList:[],markerShow:{scenic:!1,toilet:!0,parking:!0,food:!0,shop:!0,hospital:!1,police:!1}}},onShow(){this._mapContext||this.$nextTick((()=>{this._mapContext=t.index.createMapContext("map",this)}))},created(){this.init();let e=this;t.index.getSystemInfo({success:function(o){var a,s;if(e.statusBarH=o.statusBarHeight+5,null==(s=(a=t.index).getMenuButtonBoundingClientRect)?void 0:s.call(a)){let o=t.index.getMenuButtonBoundingClientRect();e.customBarH=o.height+5}else e.customBarH=30}})},methods:{changeMarkers(){var t;this.markers[0]={...null==(t=this.$props)?void 0:t.marker,longitude:this.center_lon,latitude:this.center_lat}},init(){var e,o;this.amapPlugin=new s({key:this.key});const a={longitude:null==(e=this.$props)?void 0:e.longitude,latitude:null==(o=this.$props)?void 0:o.latitude};if(a.latitude&&a.longitude)this.getCurrentLocation({detail:a});else{const e=this;t.index.getLocation({type:"gcj02",isHighAccuracy:!0,success:t=>{a.latitude=t.latitude,a.longitude=t.longitude,e.getCurrentLocation({detail:a})}})}},poitap(t){console.log(t)},getCurrentLocation(t){this.searchValue="";const{latitude:e,longitude:o}=t.detail;console.log(o),console.log(e),e&&o&&this.getRegeo([o,e],(t=>{this.searchList=t}))},getInputtips(){this.amapPlugin.getInputtips({key:this.key,keywords:this.searchValue,location:this.center_lon+","+this.center_lat,success:t=>{this.searchList=t.tips.filter((t=>{var e;return(null==(e=null==t?void 0:t.id)?void 0:e.length)&&(null==t?void 0:t.location)}))}})},getRegeo(t,e){this.center_lat=t[1],this.center_lon=t[0],this.changeMarkers(),this.amapPlugin.getRegeo({location:this.center_lon+","+this.center_lat,success:t=>{const{regeocodeData:o}=t[0];this.addressMap=o.formatted_address,this.regeocodeData=o,this.$emit("changeMarker",this.getConfirmData()),e&&e(o.pois)}})},searchMap(){this.getInputtips()},getCurrentSingleLocation(t){let e=t.location.split(",");this.searchValue=t.name,this.getRegeo(e)},close(){this.$emit("confirm")},getConfirmData(){var t;const{pois:e,addressComponent:{province:o,district:a,township:s}}=this.regeocodeData,i=(null==(t=null==e?void 0:e[0])?void 0:t.name)||o+a+s;return{...this.regeocodeData,title:i,latitude:this.center_lat,longitude:this.center_lon,address:this.addressMap}},submit(t){this.$props.disable||this.addressMap&&"{}"!=JSON.stringify(this.regeocodeData)&&this.$emit("confirm",this.getConfirmData())},gotoHome(){this.checkMapContext();const e=this;console.log(this._mapContext),t.index.getLocation({type:"gcj02",isHighAccuracy:!0,success:t=>{console.log(t),e.center_lat=t.latitude,e.center_lon=t.longitude,e.center_scale=18,e._mapContext.moveToLocation({latitude:t.latitude,longitude:t.longitude})}}),this.addMarkers()},checkMapContext(){this._mapContext||(this._mapContext=t.index.createMapContext("map",this))},toggleMarker(t){this.markerShow[t]=!this.markerShow[t],this.addMarkers()},addMarkers(){const t=[];console.log(e.mapMarkers),e.mapMarkers.forEach((e=>{const o=e.type;if(this.markerShow[o]){const{iconPath:a,width:s,height:i,label:r,pois:n}=e;n.forEach(((e,n)=>{t.push({id:e.id,iconPath:a,width:s,height:i,longitude:e.longitude,latitude:e.latitude,label:{...r,content:e.name||`${o} ${n+1}`}})}))}})),this.checkMapContext(),this._mapContext.addMarkers({markers:t,clear:!0,complete(t){console.log("addMarkers",t)}})},showRoute(t){this.checkMapContext();const e=o.mapRoutes.find((e=>e.routeid===t)),a=[];if(o.mapRoutes.forEach((t=>{a.push(t.markerid)})),!e)return void console.error("Route not found:",t);console.log(e);const s=e.pois;if(!s||0===s.length)return void console.error("No POIs found for route:",t);try{this._mapContext.removeMarkers({markerIds:a})}catch(r){console.warn("删除 marker 时出现异常:",r)}const i={id:e.markerid,iconPath:e.iconPath,width:e.width,height:e.height,longitude:s[0].longitude,latitude:s[0].latitude};this._mapContext.addMarkers({markers:[i],clear:!1,success:()=>{console.log("新路线 marker 已添加"),this._mapContext.moveAlong({markerId:e.markerid,path:e.pois,duration:e.duration,autoRotate:!0})},fail:t=>console.error("添加 marker 失败:",t)})}}};const r=t._export_sfc(i,[["render",function(e,o,s,i,r,n){return{a:t.o((t=>n.showRoute("route1"))),b:t.o((t=>n.showRoute("route2"))),c:t.o((t=>n.showRoute("route3"))),d:a._imports_0,e:t.o(((...t)=>n.gotoHome&&n.gotoHome(...t))),f:t.f(r.markerShow,((e,o,a)=>({a:`/static/maps/${o}${e?"":"_"}.png`,b:o,c:t.o((t=>n.toggleMarker(o)),o)}))),g:r.center_lat,h:r.center_lon,i:r.center_scale,j:r.markers,k:t.o(((...t)=>n.getCurrentLocation&&n.getCurrentLocation(...t))),l:s.isPolygons?s.polygons:[],m:t.o(((...t)=>n.poitap&&n.poitap(...t))),n:t.s(s.isCustomBar&&{height:r.customBarH+"px",paddingTop:r.statusBarH+"px",backgroundColor:"transparent",top:s.top+"px"})}}],["__scopeId","data-v-0bdbab9a"]]);wx.createComponent(r);