mapboxGL和高德API结合实现路径规划

您所在的位置:网站首页 地图路径规划怎么做的 mapboxGL和高德API结合实现路径规划

mapboxGL和高德API结合实现路径规划

2024-07-13 14:15:26| 来源: 网络整理| 查看: 265

概述

本文将mapboxGL和高德地图API结合起来,实现路径规划。

效果

效果

实现

API

高德地图路径规划API说明如上图,有行走、公交、驾车等多种路径,本文以行走为例来说明。

实现逻辑

添加点、线图层 map.on('load', function() { var geojson = { 'type': 'FeatureCollection', 'features': [] }; map.addSource('path', { type: 'geojson', data: geojson }); map.addSource('points', { type: 'geojson', data: geojson }); map.addLayer({ id: 'path', type: 'line', source: 'path', 'paint': { 'line-color': '#4ddc26', 'line-width': 5 } }); map.addLayer({ id: 'points', type: 'circle', source: 'points', 'paint': { 'circle-color': [ 'match', ['get', 'type'], '起', '#62b500', '#f54336' // 无匹配值 ], 'circle-radius': 13 } }); map.addLayer({ 'id': 'label', 'type': 'symbol', 'source': 'points', 'layout': { 'text-field': ['get', 'type'], "text-size": 12 }, paint: { 'text-color': '#ffffff' } }) }) 开始路径查询 startDraw() { that.isDraw = true; that.points = []; map.getCanvas().style.cursor = 'crosshair'; var geojson = { 'type': 'FeatureCollection', 'features': [] }; map.getSource('path').setData(geojson); map.getSource('points').setData(geojson); } 注册点击事件 map.on('click', e => { var lngLat = e.lngLat; if(that.isDraw) { that.points.push([lngLat.lng, lngLat.lat]); that.drawPoints(); if(that.points.length === 2) { that.getRoute(); } } }); 路径查询与渲染 getRoute() { that.isDraw = false; map.getCanvas().style.cursor = ''; const url = 'https://restapi.amap.com/v3/direction/walking'; var start = that.points[0].map(res => { return res.toFixed(5); }); var end = that.points[1].map(res => { return res.toFixed(5); }); var params = { key: that.key, origin: start.join(','), destination: end.join(',') }; $.get(url, params, res => { that.paths = res.route.paths; var geojson = { 'type': 'FeatureCollection', 'features': [] }; for(var i = 0;i var step = steps[j]; var polyline = step.polyline; polyline = polyline.split(';'); polyline = polyline.map(p => { return p.split(',').map(Number); }); var feat = { type: 'Feature', properties: {}, geometry: { type: 'LineString', coordinates: polyline } }; geojson.features.push(feat); } } map.getSource('path').setData(geojson); }) }, drawPoints() { var geojson = { 'type': 'FeatureCollection', 'features': [] } for(var i = 0;i type: 'Feature', geometry: { type: 'Point', coordinates: p }, properties: { 'type': type } }) } map.getSource('points').setData(geojson); }


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭