// 创建地址解析器实例
                var myGeo = new BMap.Geocoder();
                // 将地址解析结果显示在地图上, 需要2个地址 用Deferred控制
                var point1, point2; // 起点 和终点

                var dtd1 = $.Deferred();
                var dtd2 = $.Deferred();
                if (options.start && options.end) {
                    //蒙板加载中
                    $("#" + options.target).RouMask();
            //调用 addParsePoint 方法 传入Deferred对象 当对个Deferred对象状态都为resolve时, $.when的done方法才会执行
$.when(addParsePoint(dtd1, options.start, "start"), addParsePoint(dtd2, options.end, "end")).done(function () { var driving = new BMap.DrivingRoute(map, { renderOptions: { map: map, autoViewport: true } }); driving.search(point1, point2); //关闭蒙板 $("#" + options.target).RouMask("close"); }) }; //获取坐标 function addParsePoint(dtd, addName, t) { myGeo.getPoint(addName, function (point) { if (point) { if (t == "end") { point2 = point; } else { point1 = point; } //完成 dtd.resolve(); //map.centerAndZoom(point, 16); //map.addOverlay(new BMap.Marker(point)); } }, "全国"); return dtd; }// end addParsePoint

  

相关文章:

  • 2021-09-08
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-06-17
  • 2021-11-12
  • 2021-08-04
猜你喜欢
  • 2021-08-01
  • 2021-11-08
  • 2022-01-19
  • 2021-10-22
  • 2021-07-15
  • 2022-12-23
  • 2022-02-20
相关资源
相似解决方案