Cesium 融合高德Web API 线路规划与导航

在这里插入图片描述

<!--

 * @Author: 苹果园dog

 * @Date: 2020-11-13 14:48:40

 * @LastEditTime: 2020-11-18 10:26:31

 * @LastEditors: Please set LastEditors

 * @Description: In User Settings Edit

 * @FilePath: \web\cesiumS\cesium\cesium\mytest\高德2.html

-->

<!doctype html>

<html>

<head>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">

    <title>2</title>

        html,

        body,

        #cesiumContainer {

            width: 100%;

            height: 100%;

            margin: 0;

            padding: 0;

            overflow: hidden;

        }



        #container {

            width: 100%;

            height: 100%;

            margin: 0;

            padding: 0;

            overflow: hidden;

        }



        .testtool {

            position: absolute;

            top: 75px;

            left: 100px;

            background: gray;

        }

    </style>

</head>



<body>

    <div id="cesiumContainer"></div>

    <div class="info">

        <div class="input-item">

            <div class="input-item-prepend">

                <span class="input-item-text" style="width:8rem;">请输入关键字</span>

            </div>

            <input id='tipinput' type="text">

        </div>

        <div class="input-item">

            <div class="input-item-prepend">

                <span class="input-item-text" style="width:8rem;">请输入关键字</span>

            </div>

            <input id='tipinput2' type="text">

        </div>

        <button id="btncallapp" onclick="beginGuide()">开始导航</button>

    </div>

    <script type="text/javascript">



        let isPC = isThePC();//是PC端网页打开

        let isAndroid = isTheAndroid();//是移动端网页打开

        var viewer = init3D("cesiumContainer");

        var scene = viewer.scene;



        let coord1 = null;//起始坐标

        let coord2 = null;//终点坐标

        let input1 = document.getElementById('tipinput');

        let input2 = document.getElementById('tipinput2');

        let startPoiName = '';//起始点名称

        let endPoiName = '';//终点名称

        AMap.plugin(['AMap.Autocomplete', 'AMap.PlaceSearch'], function () {//搜索POI地址,和下面的代码可以合并

            var autoOptions = {

                input: 'tipinput'

            }

            var autoComplete = new AMap.Autocomplete(autoOptions);

            var placeSearch = new AMap.PlaceSearch({

                city: '41',

                pageSize: 1,

                pageIndex: 1,

            });

            placeSearch.search('河南省', function (status, result) {



            });

            AMap.event.addListener(autoComplete, "select", function (e) {

                startPoiName = e.poi.name;

                placeSearch.search(e.poi.name, function (status, result) {

                    console.log("e.poi.name", e.poi.name);

                    console.log("result", result);

                    let lng = result.poiList.pois[0].location.lng;

                    let lat = result.poiList.pois[0].location.lat;

                    let coord1WGS84 = coordadd.gcj02towgs84(lng, lat);

                    coord1 = [lng, lat];

                    cesiumUtil.removeEntitiesByName('daohangbill1');

                    cesiumUtil.addBillBordAirLive('daohangbill1', coord1WGS84[0], coord1WGS84[1], 0, 1, 0, 'http://ip:8083/cesium148/mytestcesium/billbords/weizhi.png', '起点', null, null, null);

                    doWork();

                });

            });

        });



        AMap.plugin(['AMap.Autocomplete', 'AMap.PlaceSearch'], function () {//搜索POI地址,和上面的代码可以合并

            var autoOptions = {

                input: 'tipinput2'

            }

            var autoComplete = new AMap.Autocomplete(autoOptions);

            var placeSearch = new AMap.PlaceSearch({

                city: '41',

                pageSize: 1,

                pageIndex: 1,

            });

            placeSearch.search('河南省', function (status, result) {



            });

            AMap.event.addListener(autoComplete, "select", function (e) {

                endPoiName = e.poi.name;

                placeSearch.search(e.poi.name, function (status, result) {

                    console.log("e.poi.name", e.poi.name);

                    console.log("result", result);

                    let lng = result.poiList.pois[0].location.lng;

                    let lat = result.poiList.pois[0].location.lat;

                    let coord2WGS84 = coordadd.gcj02towgs84(lng, lat);

                    coord2 = [lng, lat];

                    cesiumUtil.removeEntitiesByName('daohangbill2');

                    cesiumUtil.addBillBordAirLive('daohangbill2', coord2WGS84[0], coord2WGS84[1], 0, 1, 0, 'http://ip:8083/cesium148/mytestcesium/billbords/weizhi.png', '终点', null, null, null);

                    doWork();

                });

            });

        })



        function doWork() {//确定起止点后干的事情,划线,导航等。            

            getRoute(RouteType.driving, (result) => {

                if (!result) {

                    return;

                }

                console.log(result);

                let paths = result.paths[0].steps;

                let positions = [];

                for (let index = 0; index < paths.length; index++) {

                    const path = paths[index];

                    let polyline = path.polyline;

                    let polylinePoints = polyline.split(/[,]|;/);

                    positions = positions.concat(polylinePoints);

                }

                positions = positions.map(Number);

                let positionsWGS84 = [];

                for (let index = 0; index < positions.length - 1; index += 2) {

                    const pos = positions[index];

                    const pos2 = positions[index + 1];

                    let coordWGS84 = coordadd.gcj02towgs84(pos, pos2);

                    positionsWGS84 = positionsWGS84.concat(coordWGS84);

                }

                cesiumUtil.removeEntitiesByName('daohangline');

                var greenLine = viewer.entities.add({//加载线路到三维球

                    name: "daohangline",

                    polyline: {

                        positions: Cesium.Cartesian3.fromDegreesArray(positionsWGS84),

                        width: 6,

                        material: Cesium.Color.GREEN,

                        clampToGround: true,

                    },

                });

                viewer.flyTo(greenLine);

            });

        }



        //调用高德webAPI查询规划线路,这里头有详细信息,界面上后期可以丰富一下,详细行走路径,时间等。

        function getRoute(type, callback) {

            if (input1.value && input2.value) {

                if (!type) {

                    type = '';

                }

                let origin = coord1.toString();

                let destination = coord2.toString();

                $.ajax({

                    url: 'https://restapi.amap.com/v3/direction/' + type,

                    dataType: "json",

                    async: true,

                    data: {

                        origin: origin,

                        destination: destination,

                        key: 'e71dcsdc024859f4cfb328a60cb75a03b'

                    },

                    success: function (data) {

                        if (data.status < 1) {

                            callback(null);

                        } else {

                            callback(data.route);

                        }

                    },

                    error: function () {

                        callback(null);

                    }

                });

            }

        }
  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 高德地图API是一套提供地图、定位、路径规划等功能的开发接口,而Cesium是一个基于WebGL的三维地球渲染引擎。 高德地图APICesium可以结合使用,以实现更丰富的地图可视化和交互效果。具体可以通过以下方式进行结合: 1. 基于高德地图API的位置信息,可以使用Cesium在三维地球上进行标注、定位显示。通过将高德地图API获取的经纬度坐标转化为Cesium格式的位置信息,可以实现地图上的实时定位、轨迹显示等功能。 2. 高德地图的POI搜索功能可以结合Cesium的3D模型来显示检索结果,提供更直观的地图结果展示。例如搜索周边餐饮店的时候,可以通过Cesium的3D建模技术将餐馆的楼宇模型展示在地球上。 3. 高德地图的路径规划功能可以结合Cesium的路径绘制技术,将规划好的路径以三维线条的形式展示在地球上,通过Cesium导航视图功能,提供更直观的导航指引。 4. 高德地图API提供的大量地理数据,可以结合Cesium的渲染能力,制作更真实的三维地球场景。例如将高德地图的3D建筑物模型、地形数据等与Cesium的渲染引擎结合,实现更真实的地球环境效果。 总之,高德地图APICesium的结合可以提供更丰富的地图展示和交互体验,使得开发者可以在Web端构建更具有吸引力和实用性的地图应用。 ### 回答2: 高德地图APICesium是两种不同的地图工具,它们可以结合使用以提供更丰富的地理信息展示和交互体验。通过将高德地图APICesium集成,可以实现以下功能: 1. 地图数据展示:在Cesium的3D地球模型上加载高德地图的矢量数据和卫星影像数据,实现更真实的地球表面展示。 2. 实时交通信息:高德地图API提供了实时的交通信息,可以通过在Cesium地球上添加交通流量图层来显示当前道路交通情况,帮助用户规划出行路线。 3. 地理搜索和导航:借助高德地图API的地理搜索功能,可以在Cesium地球上实现地点搜索,如搜索周边的商铺、景点等,并显示在3D地球上。同时,结合高德导航接口,可以在Cesium地球上动态展示路线规划导航信息。 4. 地理围栏和地理推送:高德地图API中提供了地理围栏和地理推送的功能,可以在Cesium中实现位置监控和实时预警等功能。例如,在Cesium地球上显示设定的地理围栏,并实时监测设备位置,触发地理推送通知。 5. 数据可视化:高德地图APICesium都支持数据可视化,可以将不同的地理信息以图表、热力图、气泡等形式展示在Cesium地球上,提供更直观的数据呈现。 通过结合高德地图APICesium,可以在Cesium地球上融合高德地图的丰富数据和功能,打造出更具交互性和沉浸感的地理信息展示和应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值