| | |
| | | window.areaLayer = null |
| | | window.tileset = null |
| | | window.drawALineLayer = null // 导航路径图层 |
| | | window.drawALineLayerGCJ02StartLngLat = null // 导航路径图层转坐标 |
| | | window.drawALineLayerGCJ02EndLngLat = null // 导航路径图层转坐标 |
| | | |
| | | window.drawALineLayerdrawALine = null // 导航路径画线方法 |
| | | window.drawALineLayerIcon = null // 导航路径图层图标 |
| | | window.billboarddaohang = null // 导航点 |
| | |
| | | // 114.0351, |
| | | // 27.6314, |
| | | // 200.0 |
| | | data[0] + 0.0, |
| | | data[1] + 0.00028, |
| | | data[0], |
| | | data[1], |
| | | data[2] || 300 |
| | | ), |
| | | orientation: { |
| | |
| | | // 单条步行 |
| | | // 本地图使用的是WGS84坐标,而高德使用的是火星坐标GCJ02,所以需要转换参数过去 |
| | | // 返回值需要转换为WGS84坐标 |
| | | state.navigationStartLngLat = [+val.start[0], +val.start[1]] // 导航起点 |
| | | state.navigationEndLngLat = [+val.end[0], +val.end[1]] // 导航终点 |
| | | // 转换WGS84坐标为GCJ02 |
| | | window.drawALineLayerGCJ02StartLngLat = global.DC.CoordTransform.WGS84ToGCJ02( |
| | | Number(state.navigationStartLngLat[0]), |
| | | Number(state.navigationStartLngLat[1]) |
| | | ) |
| | | window.drawALineLayerGCJ02EndLngLat = global.DC.CoordTransform.WGS84ToGCJ02( |
| | | Number(state.navigationEndLngLat[0]), |
| | | Number(state.navigationEndLngLat[1]) |
| | | ) |
| | | // 获取路径,使用的是高德API |
| | | state.navigationStartLngLat = [Number(val.start[0]).toFixed(6), Number(val.start[1]).toFixed(6)] // 导航起点 |
| | | state.navigationEndLngLat = [Number(val.end[0]).toFixed(6), Number(val.end[1]).toFixed(6)] // 导航终点 |
| | | |
| | | let url = 'https://restapi.amap.com/v3/direction/walking' // 默认api步行 |
| | | // 获取路径 |
| | | const url = 'https://dev.jxpskj.com:8023/arcgis/rest/services/jglw/NAServer/%E8%B7%AF%E5%BE%84/solve' // 默认api步行 |
| | | // const url = 'https://dev.jxpskj.com:8023/arcgis/rest/services/testroad/NAServer/%E8%B7%AF%E5%BE%84/solve' // 默认api步行 |
| | | const data = { |
| | | origin: `${Number(window.drawALineLayerGCJ02StartLngLat[0]).toFixed(6)},${Number( |
| | | window.drawALineLayerGCJ02StartLngLat[1] |
| | | ).toFixed(6)}`, |
| | | destination: `${Number(window.drawALineLayerGCJ02EndLngLat[0]).toFixed(6)},${Number( |
| | | window.drawALineLayerGCJ02EndLngLat[1] |
| | | ).toFixed(6)}`, |
| | | key: '4b3e1db3211054ce5b466407cbb9d221', |
| | | output: 'json' |
| | | stops: { |
| | | features: [{ |
| | | geometry: { |
| | | x: state.navigationStartLngLat[0], |
| | | y: state.navigationStartLngLat[1] |
| | | } |
| | | }, { |
| | | geometry: { |
| | | x: state.navigationEndLngLat[0], |
| | | y: state.navigationEndLngLat[1] |
| | | } |
| | | }] |
| | | }, |
| | | returnDirections: false, |
| | | returnRoutes: true, |
| | | f: 'json' |
| | | } |
| | | let strategyType = [0] |
| | | if (val.type) { |
| | | // 切换驾车模式 |
| | | url = 'https://restapi.amap.com/v3/direction/driving' |
| | | data.strategy = 10 |
| | | strategyType = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
| | | } |
| | | // for (let index = 0; index < strategyType.length; index++) { |
| | | // data["strategy"] = strategyType[index]; |
| | | axios |
| | | .get(url, { |
| | | params: { |
| | |
| | | }) |
| | | .then((res) => { |
| | | // 回调 |
| | | const paths = res.data.route.paths |
| | | for (let i = 0; i < paths.length; i++) { |
| | | // 多条路线 |
| | | window.drawALineLayerdrawALine(paths[i]) |
| | | } |
| | | // const paths = res.data.route.paths[0].steps; |
| | | // window.drawALineLayerdrawALine (paths, res.data.route.paths[0].strategy); |
| | | }) |
| | | // } |
| | | // 包装绘画工具 |
| | | window.drawALineLayerdrawALine = (pathsour) => { |
| | | const paths = pathsour.steps |
| | | const titles = pathsour.strategy |
| | | // paths是个道路对象,其中polyline是String类型的经纬度 |
| | | let Str = state.navigationStartLngLat.join(',') + ';' // 加入起点 |
| | | for (let index = 0; index < paths.length; index++) { |
| | | const path = paths[index] |
| | | let polyline = path.polyline // 取到String类型的经纬度 |
| | | const polylineArr = polyline.split(';') // 转为数组 |
| | | const polylineArrLength = polylineArr.length // 获取长度,避免多次重复读取polylineArr.length |
| | | for (let k = 0; k < polylineArrLength; k++) { |
| | | const inPolylineArr = polylineArr[k].split(',') // 转经纬度为单独的数组 |
| | | const outIn = global.DC.CoordTransform.GCJ02ToWGS84( |
| | | // 处理火星坐标转换成WGS84 GCJ02ToWGS84 |
| | | inPolylineArr[0], |
| | | inPolylineArr[1] |
| | | ) |
| | | polylineArr[k] = outIn.join(',') // 每组经纬度转为String |
| | | } |
| | | polyline = polylineArr.join(';') // 合并转换后的经纬度合集 |
| | | |
| | | Str += polyline // 自加 |
| | | Str += ';' |
| | | } |
| | | Str += state.navigationEndLngLat.join(',') // 加入终点 |
| | | if (val.fn) { |
| | | const dataS = { |
| | | // 返回数据 |
| | | titles: titles, |
| | | Str: Str |
| | | let Str = '' // 加入起点 |
| | | res.data.routes.features[0].geometry.paths[0].forEach((item) => { |
| | | Str += `${item[0]},${item[1]};` |
| | | }) |
| | | // Str += state.navigationEndLngLat.join(',') // 加入终点 |
| | | |
| | | if (val.fn) { |
| | | const dataS = { |
| | | Str: Str |
| | | } |
| | | // console.log(Str); |
| | | state.routerS.push(dataS) |
| | | return val.fn(dataS) |
| | | } else { |
| | | dispatch('MSET_DRAWALINELAYER', Str) // 绘画线路 |
| | | } |
| | | // console.log(Str); |
| | | state.routerS.push(dataS) |
| | | return val.fn(dataS) |
| | | } else { |
| | | dispatch('MSET_DRAWALINELAYER', Str) // 绘画线路 |
| | | } |
| | | } |
| | | }) |
| | | }, |
| | | // 导航系统↑ |
| | | // 绘画线路 |
| | |
| | | commit, |
| | | dispatch |
| | | }, value) { |
| | | const Str = value[0] |
| | | // 检查是否存在路线 |
| | | commit('removePolyline') |
| | | commit('removePolylineMany') |
| | |
| | | window.drawALineLayer = new global.DC.VectorLayer('lineLayer') |
| | | global.viewer.addLayer(window.drawALineLayer) |
| | | |
| | | // 如果是添加 给第一个点加入图标 和事件 |
| | | if (value[1]) { |
| | | commit('removerPolyLineIcon') |
| | | window.drawALineLayerIcon = new global.DC.VectorLayer('pointLayer') |
| | | global.viewer.addLayer(window.drawALineLayerIcon) |
| | | const useStr = Str.split(';') |
| | | const post = useStr[useStr.length - 1].split(',') |
| | | window.positiondaohang = new global.DC.Position(post[0], post[1]) |
| | | window.billboarddaohang = new global.DC.Billboard( |
| | | window.positiondaohang, |
| | | '/zhjg/img/dingwei/dingwei1.png' |
| | | ) // 加入绘画点 |
| | | window.billboarddaohang.setStyle({ |
| | | pixelOffset: { |
| | | x: 0, |
| | | y: -17 |
| | | } // 偏移像素 |
| | | }) |
| | | // 订阅事件 |
| | | window.billboarddaohang.on(global.DC.MouseEventType.CLICK, (e) => { |
| | | if (state.pinchFlag == true) { |
| | | return |
| | | } |
| | | // console.log(e); |
| | | // return; |
| | | // 定制化窗体 |
| | | const position = e.position |
| | | const lntLat = [e.overlay._position._lng, e.overlay._position._lat] |
| | | const windowData = { |
| | | position, |
| | | lntLat, |
| | | query: { |
| | | ...(value[1] || {}), |
| | | position, |
| | | lntLat, |
| | | notAddGoOn: 'notAddGoOn' |
| | | }, |
| | | useJWD: true // 仅使用经纬度 |
| | | } |
| | | dispatch('setMobileWindows', windowData) |
| | | }) |
| | | window.drawALineLayerIcon.addOverlay(window.billboarddaohang) |
| | | } |
| | | window.polylinedaohang = new global.DC.Polyline(Str) // 加入线 |
| | | window.polylinedaohang = new global.DC.Polyline(value) // 加入线 |
| | | window.polylinedaohang.setStyle({ |
| | | width: 3, |
| | | material: window.polylinematerialdaohang, |
| | | width: 4, |
| | | material: global.DC.Color.RED, |
| | | clampToGround: true |
| | | }) |
| | | window.drawALineLayer.addOverlay(window.polylinedaohang) |