123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083 |
- /**
- * @fileoverview 打印 模块
- * @author Song.Huang
- * @version 1.0.0
- */
- var routeSearchFDTT = function () {
- /** 必经点+规避点路线规划
- * [getNaviPathPro description]
- * @param {[type]} options [viaAry(第一个为起点,最后一个为终点,中间的为必经点) avoidAry(规避点数组)]
- * @param {[type]} callbackFunc [description]
- * @return {[type]} [description]
- */
- this.getNaviPath = function (options, callbackFunc) {
- var sUrl = onemapUrlConfig.routeSearchDataUrl +
- '?via=' + JSON.stringify(options.viaAry) +
- '&avoid=' + JSON.stringify((options.avoidAry || []));
- $.ajax({
- url: sUrl,
- type: 'GET',
- dataType: 'jsonp'
- })
- .done(function (data) {
- callbackFunc(data);
- })
- .fail(function () {});
- }
- };
- var routeSearchNew = function () {
- /** 必经点+规避点路线规划
- * [getNaviPathPro description]
- * @param {[type]} options [viaAry(第一个为起点,最后一个为终点,中间的为必经点) avoidAry(规避点数组)]
- * @param {[type]} callbackFunc [description]
- * @return {[type]} [description]
- */
- this.getNaviPath = function (options, callbackFunc) {
- var pointArr = [];
- for (var i = 0; i < options.viaAry.length; i++) {
- pointArr.push(L.latLng(options.viaAry[i][1], options.viaAry[i][0]));
- }
- window.routingControl = L.Routing.control(
- L.extend({}, {
- waypoints: pointArr,
- //geocoder: L.Control.Geocoder.nominatim(),
- routeWhileDragging: true,
- reverseWaypoints: true,
- showAlternatives: true,
- simplifyGeometry: false,
- geometryOnly: true,
- altLineOptions: {
- styles: [{
- color: 'black',
- opacity: 0.15,
- weight: 9
- },
- {
- color: 'white',
- opacity: 0.8,
- weight: 6
- },
- {
- color: 'blue',
- opacity: 0.5,
- weight: 2
- }
- ]
- },
- callback: callbackFunc
- }))
- };
- }
- // var routeSearchF = function () {
- // /** 必经点+规避点路线规划
- // * [getNaviPathPro description]
- // * @param {[type]} options [viaAry(第一个为起点,最后一个为终点,中间的为必经点) avoidAry(规避点数组)]
- // * @param {[type]} callbackFunc [description]
- // * @return {[type]} [description]
- // */
- // this.getNaviPath = function (options, callbackFunc) {
- // var orig, dest, mid, afUrl;
- // var viaAryLength = options.viaAry.length;
- // if (viaAryLength < 3) {
- // afUrl = '?token=25cc55a69ea7422182d00d6b7c0ffa93&source=1&sPoint=' + options.viaAry[0] +
- // '&ePoint=' + options.viaAry[1] +
- // '&st=' + options.searchType;
- // } else if (viaAryLength >= 3) {
- // var midData; {
- // for (var i = 1; i < viaAryLength - 1; i++) {
- // var curmidData = JSON.stringify(options.viaAry[i]).replace('[', '').replace(']', '');
- // if (i === 1) {
- // midData = curmidData;
- // } else {
- // midData = midData + ";" + curmidData;
- // }
- // }
- // }
- // afUrl = '?token=25cc55a69ea7422182d00d6b7c0ffa93&source=1&sPoint=' + options.viaAry[0] +
- // '&ePoint=' + options.viaAry[viaAryLength - 1] +
- // '&wayPoints=' + midData +
- // '&st=' + options.searchType;
- // }
- // var sUrl = onemapUrlConfig.siWeiRouteDataUrl + '/service/route/driving2' +
- // afUrl;
- // $.ajax({
- // url: sUrl,
- // type: 'GET',
- // dataType: 'json'
- // })
- // .done(function (data) {
- // var segArr = new Array();
- // var coorArr = new Array();
- // var coors = "";
- // var doorArr = new Array();
- // if (data.data.rows.length > 0) {
- // for (var i = 0; i < data.data.rows[0].item.length; i++) {
- // if (data.data.rows[0].item[i].routelatlon) {
- // coorArr[i] = data.data.rows[0].item[i].routelatlon.replace(/;/g, ",");
- // } else {
- // coorArr[i] = data.data.rows[0].item[i].turnlatlon.replace(/;/g, ",");
- // }
- // var roadLength;
- // var roadOld = data.data.rows[0].item[i].distance;
- // roadLength = parseFloat(data.data.rows[0].item[i].distance);
- // segArr[i] = {
- // "accessorialInfo": "",
- // "action": "",
- // "coor": coorArr[i],
- // "coorAry": coorArr[i].split(","),
- // "direction": 0.0,
- // "driveTime": "",
- // "form": "",
- // "grade": "",
- // "roadLength": roadLength,
- // "roadName": data.data.rows[0].item[i].streetName,
- // "soundID": "",
- // "textInfo": data.data.rows[0].item[i].strguide,
- // "videoID": ""
- // }
- // if (data.data.rows[0].item[i].routelatlon) {
- // coors += data.data.rows[0].item[i].routelatlon.replace(/;/g, ",");
- // } else {
- // coors += data.data.rows[0].item[i].turnlatlon.replace(/;/g, ",");
- // }
- // }
- // var cbData = {
- // "code": 0,
- // "data": {
- // "bounds": options.viaAry[0] + "," + options.viaAry[viaAryLength - 1],
- // "cache": false,
- // "coors": coors,
- // "count": parseInt(data.data.rows[0].count),
- // "message": "ok",
- // //"searchtime": parseInt(data.lines.time),
- // "segmengList": segArr
- // }
- // }
- // } else {
- // callbackFunc({
- // "code": 0,
- // "data": []
- // })
- // }
- // callbackFunc(cbData);
- // })
- // .fail(function () {});
- // }
- // };
- var addressSearchF = function () {
- /**
- * 通过缩放等级和坐标查询位置信息
- * @param {[type]} options [latLng(经纬度数组[纬度,经度]) zoom(地图缩放比例)]
- * @param {[type]} callbackFunc [description]
- * @return {[type]} [description]
- */
- this.getAddressInfo = function (options, callbackFunc) {
- var sUrl = onemapUrlConfigNetwork.addressSearchDataUrl + '/v1.0/address/near/' +
- '?z=' + options.zoom +
- '&lon=' + options.latLng[1] +
- '&lat=' + options.latLng[0];
- $.ajax({
- url: sUrl,
- type: 'GET',
- dataType: 'jsonp'
- })
- .done(function (data) {
- callbackFunc(data);
- })
- .fail(function () {});
- }
- };
- /**
- * 打印
- * @exports printer
- * @type {Object}
- */
- var printer = {
- /**
- * 初始化
- * @type {Function}
- */
- init: function () {
- var _this = this;
- // if (map23DConfig.netType == 1) {
- // $.each(map23DConfigIntranet, function (i, t) {
- // map23DConfig[i] = t
- // })
- // $.each(onemapUrlConfigIntranet, function (i, t) {
- // onemapUrlConfig[i] = t
- // })
- // } else {
- // $.each(map23DConfigNetwork, function (i, t) {
- // map23DConfig[i] = t
- // })
- // $.each(onemapUrlConfigNetwork, function (i, t) {
- // onemapUrlConfig[i] = t
- // })
- // }
- //解析URL判断打印类型
- _this._urlParse();
- //系统初始化路径服务
- // if (map23DConfig.routType == 'New') {
-
- // }
- routeSearchF = routeSearchNew
-
- },
- /**
- * url解析
- * @type {Function}
- * @private
- */
- _urlParse: function () {
- var _this = this;
- switch (_this._getQueryString('m')) {
- case 'directions': //路线规划
- directionsPrint.init({
- mapType: _this._getQueryString('map').split('|')[0],
- mapZoom: parseFloat(_this._getQueryString('map').split('|')[1]),
- mapCenter: [parseFloat(_this._getQueryString('map').split('|')[2]), parseFloat(_this._getQueryString('map').split('|')[3])],
- zoom: parseFloat(_this._getQueryString('dir').split('|')[4]),
- startPoint: [parseFloat(_this._getQueryString('dir').split('|')[0]), parseFloat(_this._getQueryString('dir').split('|')[1])],
- stopPoint: [parseFloat(_this._getQueryString('dir').split('|')[2]), parseFloat(_this._getQueryString('dir').split('|')[3])],
- startName: _this._getQueryString('place').split('|')[0],
- stopName: _this._getQueryString('place').split('|')[1],
- acrossPoints: JSON.parse(_this._getQueryString('across')),
- searchType: JSON.parse(_this._getQueryString('searchType')),
- avoidPoints: JSON.parse(_this._getQueryString('avoid')),
- thematicUrl: _this._getQueryString('thematic') ? CryptoJS.enc.Base64.parse(_this._getQueryString('thematic')).toString(CryptoJS.enc.Utf8) : false,
- plan: JSON.parse(_this._getQueryString('plan')) ? Number(_this._getQueryString('plan')) : 0
- //CryptoJS.enc.Base64.parse([_this._getQueryString('thematic')]).toString(CryptoJS.enc.Utf8)
- });
- break;
- }
- },
- /**
- * Url解析
- * @type {Function}
- * @param name {String} 参数键
- * @returns {string} 参数值
- * @private
- */
- _getQueryString: function (name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
- var r = window.location.search.substr(1).match(reg);
- if (r != null) return decodeURI(r[2]);
- return '';
- }
- };
- /**路线打印
- * @exports directionsPrint
- * @type {Object}
- */
- //http://www.domain.com/print.html?
- // m=directions 模块类型
- // &dir=39.99605985169435|116.24221801757812|39.916582935817154|116.4166259765625|15 起点坐标|终点坐标|坐标查询缩放比例
- // &map=1|10|39.9|116.3 类型|缩放比例|lat|lon
- var directionsPrint = {
- /**
- * 默认参数
- * @type {Object}
- */
- options: {
- mapType: 1, //地图底图类型
- mapZoom: 10, //地图缩放比
- mapCenter: [0, 0], //地图中心点
- zoom: 19, //起始点查点zoom
- startPoint: [0, 0], //起点
- stopPoint: [0, 0], //终点
- startName: '',
- stopName: '',
- acrossPoints: [], //途经点
- avoidPoints: [], //规避点
- searchType: 1,
- plan: 0
- },
- /**路径点集合
- * @type {Object}
- * @default {}
- */
- _markerObjs: {},
- /**
- * 初始化 获取起点/终点坐标-查询起点/终点信息-查询路线信息-画路径-列表路径点
- * @type {Function}
- * @param options {Object}
- * @see options
- */
- init: function (options) {
- var _this = this;
- for (var o in options) {
- if (options[o] !== null) {
- _this.options[o] = options[o];
- }
- }
- var _step = 0;
- //设置标题
- _this.title = $('<p>从<strong class="f">' + options.startName + '</strong>到<strong class="t">' + options.stopName + '</strong>的路线</p>').appendTo($('#title'));
- //地图初始化
- _this._mapShow();
- //设置起始点图标
- _this._setMarkers({
- type: 'start',
- latLng: _this.options.startPoint
- });
- _this._getPointAddress(_this.options.zoom, {
- lat: _this.options.startPoint[0],
- lng: _this.options.startPoint[1]
- }, function (data) {
- _this.startPointInfo = {
- region: data.region,
- address: _this.options.startName
- };
- _this.startMarker.bindPopup(_this.startPointInfo.address, {
- maxWidth: 100,
- minWidth: 100
- });
- //_this.title.find('.f').append(data.address);
- _this._markerObjs[100001] = {
- actionType: 'ico_p_2',
- popInfo: _this.startPointInfo.address,
- center: [_this.startMarker.getLatLng().lat, _this.startMarker.getLatLng().lng]
- };
- if (_step === 1) {
- //获取路线信息
- _this._getDirectionsLine();
- } else {
- _step++;
- }
- });
- for (var i = 0, l = _this.options.acrossPoints.length; i < l; i++) {
- _this._setMarkers({
- type: 'across',
- latLng: _this.options.acrossPoints[i]
- });
- }
- for (var i = 0, l = _this.options.avoidPoints.length; i < l; i++) {
- _this._setMarkers({
- type: 'avoid',
- latLng: _this.options.avoidPoints[i]
- });
- }
- _this._setMarkers({
- type: 'stop',
- latLng: _this.options.stopPoint
- });
- _this._getPointAddress(_this.options.zoom, {
- lat: _this.options.stopPoint[0],
- lng: _this.options.stopPoint[1]
- }, function (data) {
- _this.stopPointInfo = {
- region: data.region,
- address: _this.options.stopName
- };
- _this.stopMarker.bindPopup(_this.stopPointInfo.address, {
- maxWidth: 100,
- minWidth: 100
- });
- //_this.title.find('.t').append(data.address);
- _this._markerObjs[100002] = {
- actionType: 'ico_p_1',
- popInfo: _this.stopPointInfo.address,
- center: [_this.stopMarker.getLatLng().lat, _this.stopMarker.getLatLng().lng]
- };
- if (_step === 1) {
- //获取路线信息
- _this._getDirectionsLine();
- } else {
- _step++;
- }
- });
- //打印按钮事件
- $('#btnPrint').removeAttr('disabled').removeClass('disabled').bind('click', function () {
- $('#remarks p').append($('#remarks textarea').val());
- window.print();
- });
- //
- $('#printOption').empty().append('<p class="line">为所有路段显示:<a id="abtnHideAllPointMap" href="javascript:void(0);">仅文本</a> | <a id="abtnShowAllPointMap" href="javascript:void(0);">地图</a> <label><input type="checkbox" id="checkBigMapShow" checked />包含大图</label> </p>');
- $('#abtnHideAllPointMap').bind('click', function () {
- $('.abtn-show-text').each(function () {
- $(this).click();
- });
- });
- $('#abtnShowAllPointMap').bind('click', function () {
- $('.abtn-show-map').each(function () {
- $(this).click();
- });
- });
- $('#checkBigMapShow').bind('click', function () {
- if ($(this).is(':checked')) {
- $('#mapHolder').show();
- $('#directionsResult').css({
- pageBreakBefore: "always"
- });
- } else {
- $('#mapHolder').hide();
- $('#directionsResult').css({
- pageBreakBefore: "auto"
- });
- }
- });
- },
- /**
- * 显示专题图数据
- * @private
- */
- _setThematic: function () {
- var _this = this;
- if (_this.options.thematicUrl) {
- L.tileLayer(_this.options.thematicUrl).addTo(_this._map);
- }
- },
- /**
- * 获取坐标对应的地名
- * @type {Function}
- * @param zoom {Number}
- * @param latLng {Object}
- * @param callBack_func {Function}
- * @private
- */
- _getPointAddress: function (zoom, latLng, callBack_func) {
- var addressSearch = new addressSearchF();
- addressSearch.getAddressInfo({
- zoom: zoom,
- latLng: [latLng.lat, latLng.lng]
- }, function (data) {
- data = data.data;
- if (data.hasOwnProperty('address')) {
- if (data.address.length == 0) {
- data.address = "未知地点";
- }
- }
- callBack_func(data);
- })
- },
- /**
- * 获取路线
- * @type {Function}
- * @private
- */
- _getDirectionsLine: function () {
- var _this = this;
- var via = [];
- var avoid = [];
- via.push([_this.options.startPoint[1], _this.options.startPoint[0]]);
- for (var viaItem in _this.options.acrossPoints) {
- if (_this.options.acrossPoints.hasOwnProperty(viaItem)) {
- via.push([_this.options.acrossPoints[viaItem][1], _this.options.acrossPoints[viaItem][0]]);
- }
- }
- via.push([_this.options.stopPoint[1], _this.options.stopPoint[0]]);
- for (var avoidItem in _this.options.avoidPoints) {
- if (_this.options.avoidPoints.hasOwnProperty(avoidItem)) {
- avoid.push([_this.options.avoidPoints[avoidItem].latlng.lng, _this.options.avoidPoints[avoidItem].latlng.lat]);
- }
- }
- var searchOptions = {
- viaAry: via,
- searchType: _this.options.searchType
- };
- var routeSearch = new routeSearchF();
- routeSearch.getNaviPath(searchOptions, function (data) {
- // data = data.data;
- // if (!data.hasOwnProperty('segmengList')) {
- // alert('此线路无路径数据,无法规划路径!');
- // return false;
- // }
- // _this._directionsDataResult = data;
- // _this._drawCarPolyline({
- // opacity: 0.8,
- // lineNum: 0,
- // color: '#0099ff',
- // weight: 6
- // });
- //界面重置
- if (data.length == 0) {
- setNotResultHtml('此线路无路径数据,无法规划路径!');
- return false;
- }
- _this.navigationResult = [];
- for (var i = 0; i < data.length; i++) {
- var minlon = 0,
- maxlon = 0,
- minlat = 0,
- maxlat = 0;
- var polyline = '',
- allPolyline = '';
- _this.navigationResult.push({});
- //路径 全部点位(路径过长时,点位过多,渲染速度慢)
- for (var k = 0; k < data[i].coordinates.length; k++) {
- var lng = data[i].coordinates[k].lng
- var lat = data[i].coordinates[k].lat
- if (k == 0) {
- minlon = data[i].coordinates[k].lng
- maxlon = data[i].coordinates[k].lng
- minlat = data[i].coordinates[k].lat
- maxlat = data[i].coordinates[k].lat
- } else {
- if (lng < minlon) {
- minlon = lng
- }
- if (lng > maxlon) {
- maxlon = lng
- }
- if (lat < minlat) {
- minlat = lat
- }
- if (lat > maxlat) {
- maxlat = lat
- }
- }
- allPolyline += lng + ',' + lat + ",";
- }
- _this.navigationResult[i].coors = allPolyline;
- _this.navigationResult[i].coordinates = data[i].coordinates;
- _this.navigationResult[i].totalDistance = data[i].summary.totalDistance //米
- _this.navigationResult[i].totalTime = data[i].summary.totalTime //秒
- _this.navigationResult[i].segmengList = data[i].instructions //文字导航
- _this.navigationResult[i].bounds = {
- minlon: minlon - (maxlon - minlon) / 5,
- maxlon: maxlon + (maxlon - minlon) / 5,
- minlat: minlat - (maxlat - minlat) / 5,
- maxlat: maxlat + (maxlat - minlat) / 5,
- }; //缩放范围
- _this.navigationResult[i].center = {
- lon: (maxlon + minlon) / 2,
- lat: (maxlat + minlat) / 2
- }
- }
- _this._directionsDataResult = _this.navigationResult[_this.options.plan]
- _this._drawCarPolyline({
- opacity: 0.8,
- lineNum: 0,
- color: '#0099ff',
- weight: 6
- });
- _this._parseResultData();
- });
- },
- /**
- * 地图初始化
- * @type {Function}
- * @private
- */
- _mapShow: function () {
- var _this = this;
- $('#mapHolder').css({
- height: '800px'
- });
- //默认为线划图
- var layerName = 'gh';
- //var layer2Name = 'satellite-address';
- switch (_this.options.mapType) {
- case 'gm': //线划
- layerName = 'gm';
- break;
- case 'gh': //影像
- layerName = 'gh';
- break;
- case 'gr': //影像
- layerName = 'gr';
- break;
- case 'gt': //地形
- layerName = 'gt';
- break;
- }
- _this._mapOptions = {
- layers: [
- L.tileLayer(map23DConfig.tileServerUrl + '/' + layerName + '?l={z}&x={x}&y={y}', {
- minZoom: 1,
- maxZoom: 19,
- subdomains: map23DConfig.tileSubdomains || '',
- noWrap: true
- }),
- // L.tileLayer(map23DConfig.tileServerUrl + '/go?l={z}&x={x}&y={y}', {
- // minZoom: 1,
- // maxZoom: 19,
- // subdomains: map23DConfig.tileSubdomains || '',
- // noWrap: true
- // }),
- ], //map23DConfig.tileServerUrl+'/'+layerName+'?l={z}&x={x}&y={y}',
- center: _this.options.mapCenter,
- zoom: _this.options.mapZoom,
- maxZoom: 19,
- minZoom: 1,
- zoomControl: false
- };
- _this._map = new L.Map(
- 'mapHolder',
- _this._mapOptions
- );
- //添加相应的专题图
- _this._setThematic();
- },
- /**
- * @type {Object}
- * @param obj
- * @private
- */
- _makeMarker: function (obj) {
- },
- /**
- * 解析数据 填充节点
- * @type {Function}
- * @private
- */
- _parseResultData: function () {
- var _this = this;
- var list = $('<div id="lineList"></div>');
- var directionsResult = $('<div id="directionsResult"></div>');
- directionsResult.append(list);
- //填充起点
- var startLi = $('' +
- '<div class="line-point clearfix ge" id="startPoint">' +
- '<dl>' +
- '<dt class="action"><img src="/images/route/ico_p_2.png"/></dt>' +
- '<dd>' +
- '<p class="ac">' + _this.startPointInfo.address + '</p>' +
- '<p class="ti">' + _this.startPointInfo.region + '</p>' +
- '</dd>' +
- '</dl>' +
- '<div class="point-map" id="pMap100001"></div>' +
- '<div class="op">' +
- '显示:<a class="abtn-show-text" href="javascript:void(0)">仅文本</a> | <a class="abtn-show-map" href="javascript:void(0)" pid="100001">地图</a>' +
- '</div>' +
- '</div>');
- list.append(startLi);
- //填充规划点
- var lineMeter = 0;
- for (var i = 0, l = _this._directionsDataResult.segmengList.length; i < l; i++) {
- var item = _this._directionsDataResult.segmengList[i];
- var actionType = 'C';
- if (!item.modifier || item.modifier == 'Straight') { //直行
- actionType = 'C';
- }
- if (item.modifier == 'Left') { //左转
- actionType = 'TL';
- }
- if (item.modifier == 'Right') { //右转
- actionType = 'TR';
- }
- if (item.modifier == 'Uturn') {
- actionType = 'TU';
- }
- //item.coorAry = item.coor.split(',');
- lineMeter += item.distance;
- // var actionType = 'C';
- // if (item.textInfo.indexOf('直行') >= 0) {
- // actionType = 'C';
- // }
- // if (item.textInfo.indexOf('左转') >= 0) {
- // actionType = 'TL';
- // }
- // if (item.textInfo.indexOf('稍向左转') >= 0) {
- // actionType = 'TSLL';
- // }
- // if (item.textInfo.indexOf('向左急转') >= 0) {
- // actionType = 'TSHL';
- // }
- // if (item.textInfo.indexOf('右转') >= 0) {
- // actionType = 'TR';
- // }
- // if (item.textInfo.indexOf('稍向右转') >= 0) {
- // actionType = 'TSLR';
- // }
- // if (item.textInfo.indexOf('向右急转') >= 0) {
- // actionType = 'TSHR';
- // }
- // if (item.textInfo.indexOf('保持左行') >= 0) {
- // actionType = 'KL';
- // }
- // if (item.textInfo.indexOf('保持右行') >= 0) {
- // actionType = 'KR';
- // }
- // if (item.textInfo.indexOf('前方掉头') >= 0) {
- // actionType = 'TU';
- // }
- // if (item.textInfo.indexOf('前方右侧掉头') >= 0) {
- // actionType = 'TRU';
- // }
- // if (item.textInfo.indexOf('EXIT0') >= 0) {
- // actionType = 'EXIT';
- // }
- var lng = _this.navigationResult[_this.options.plan].coordinates[item.index].lng
- var lat = _this.navigationResult[_this.options.plan].coordinates[item.index].lat
- var nlng = _this.formatDegree(lng);
- var nlat = _this.formatDegree(lat);
- //var nLatlng = L.Util.formatHMS([item.coorAry[1], item.coorAry[0]]);
- //var ge = (i % 2) ? 'ge' : '';
- var ge = 'ge';
- var li = $('' +
- '<div pid="' + i + '" class="line-point clearfix ' + ge + '">' +
- '<dl>' +
- '<dt class="action"><img src="/images/route/D-' + actionType + '.png"/></dt>' +
- '<dt class="step">' + (i + 1) + '.</dt>' +
- '<dd>' +
- '<p class="ac">' + item.text + '<span>(' + nlng + ' , ' + nlat + ')</span></p>' +
- '<p class="ti">约' + Math.ceil(item.time / 60) + '分钟</p>' +
- '</dd>' +
- '</dl>' +
- '<p class="dir-length">移动 ' + Math.floor(item.distance / 1000 * 100) / 100 + '公里<br/><span>总距离 ' + Math.floor(lineMeter / 1000 * 100) / 100 + '公里</span></p>' +
- '<div class="point-map" id="pMap' + i + '"></div>' +
- '<div class="op">' +
- '显示:<a class="abtn-show-text" href="javascript:void(0)">仅文本</a> | <a class="abtn-show-map" href="javascript:void(0)" pid="' + i + '">地图</a>' +
- '</div>' +
- '</div>');
- list.append(li);
- _this._markerObjs[i] = {
- actionType: 'ico_p_3-' + actionType,
- popInfo: item.text,
- center: [lat, lng]
- };
- }
- //填充终点
- var stopLi = $('' +
- '<div class="line-point clearfix ge" id="stopPoint">' +
- '<dl>' +
- '<dt class="action"><img src="/images/route/ico_p_1.png"/></dt>' +
- '<dd>' +
- '<p class="ac">' + _this.stopPointInfo.address + '</p>' +
- '<p class="ti">' + _this.stopPointInfo.region + '</p>' +
- '</dd>' +
- '</dl>' +
- '<div class="point-map" id="pMap100002"></div>' +
- '<div class="op">' +
- '显示:<a class="abtn-show-text" href="javascript:void(0)">仅文本</a> | <a class="abtn-show-map" href="javascript:void(0)" pid="100002">地图</a>' +
- '</div>' +
- '</div>');
- list.append(stopLi);
- $('#contentWrap').empty().append(directionsResult);
- $('#contentWrap').append('<div class="note">' +
- '<p>实际情况会因道路施工、交通状况、天气或其他事件而与当前路径规划不同,请根据实际情况相应调整计划路线。同时请遵守关于您的路线的所有路标和指示牌。</p>' +
- '</div>');
- $('#title').append('<p>总路程:' + Math.floor(lineMeter / 1000 * 100) / 100 + '公里</p>');
- //绑定 文本|地图 切换事件
- $('.abtn-show-text').bind('click', function () {
- $(this).parent().parent().find(".point-map").hide();
- });
- $('.abtn-show-map').bind('click', function () {
- if ($(this).attr('show') === 'true') {
- $(this).parent().parent().find(".point-map").show();
- } else {
- $(this).parent().parent().find(".point-map").show();
- _this._setPointMap({
- pointNum: parseInt($(this).attr('pid')),
- mapWrap: 'pMap' + $(this).attr('pid')
- });
- $(this).attr('show', 'true');
- }
- });
- $('.line-point').bind('mouseenter', function () {
- $(this).addClass('hover');
- $(this).find('.op').show();
- }).bind('mouseleave', function () {
- $(this).removeClass('hover');
- $(this).find('.op').hide();
- });
- },
- formatDegree: function (value) {
- value = Math.abs(value);
- var v1 = Math.floor(value); //度
- var v2 = Math.floor((value - v1) * 60); //分
- var v3 = Math.round((value - v1) * 3600 % 60); //秒
- return v1 + '°' + v2 + '\'' + v3 + '"';
- },
- /**
- * 在地图上画出驾车路线
- * @type {Function}
- * @param options {Object}
- * @private
- */
- _drawCarPolyline: function (options) {
- var _this = this;
- var points = _this._directionsDataResult.coors;
- //转换为可用坐标
- var pArray = points.split(',');
- var pointLatLng = [];
- var dDouble = true;
- var temp = [];
- for (var i = 0, l = pArray.length; i < l; i++) {
- if (dDouble) {
- temp = [];
- temp.push(pArray[i]);
- dDouble = false;
- } else {
- temp.unshift(pArray[i]);
- dDouble = true;
- temp = L.latLng(temp);
- pointLatLng.push(temp);
- }
- }
- _this.pointLatLng = pointLatLng;
- //划起点,终点连线
- L.polyline([_this.options.startPoint, pointLatLng[0]], {
- color: '#FFFFFF',
- weight: options.weight + 2,
- opacity: 1
- }).addTo(_this._map);
- L.polyline([_this.options.stopPoint, pointLatLng[pointLatLng.length - 1]], {
- color: '#FFFFFF',
- weight: options.weight + 2,
- opacity: 1
- }).addTo(_this._map);
- L.polyline([_this.options.startPoint, pointLatLng[0]], {
- color: '#FF6600',
- weight: options.weight - 1,
- opacity: options.opacity,
- dashArray: '1,10'
- }).addTo(_this._map);
- L.polyline([_this.options.stopPoint, pointLatLng[pointLatLng.length - 1]], {
- color: '#FF6600',
- weight: options.weight - 1,
- opacity: options.opacity,
- dashArray: '1,10'
- }).addTo(_this._map);
- //划线
- _this._roadPolylineBg = L.polyline(pointLatLng, {
- color: '#FFFFFF',
- weight: options.weight + 2,
- opacity: 1
- });
- _this._roadPolylineBg.addTo(_this._map);
- _this._roadPolyline = L.polyline(pointLatLng, {
- color: options.color,
- weight: options.weight,
- opacity: options.opacity
- });
- _this._roadPolyline.addTo(_this._map);
- _this._map.fitBounds(_this._roadPolyline.getBounds());
- },
- /**
- * 在地图上描绘点
- * @type {Function}
- * @param options {Object}
- * @private
- */
- _setMarkers: function (options) {
- var _this = this;
- switch (options.type) {
- case 'start':
- var iconUrl = '/images/route/ico_p_2.png';
- _this.startMarker = new L.Marker(
- options.latLng, {
- icon: L.icon({
- iconUrl: iconUrl,
- iconSize: [25, 25],
- iconAnchor: [12, 24],
- popupAnchor: [0, -12]
- })
- }
- );
- _this.startMarker.addTo(_this._map);
- break;
- case 'across':
- var iconUrl = '/images/route/ico_p_4.png';
- var acrossMarker = new L.Marker(
- options.latLng, {
- icon: L.icon({
- iconUrl: iconUrl,
- iconSize: [25, 25],
- iconAnchor: [12, 24],
- popupAnchor: [0, -12]
- })
- }
- );
- acrossMarker.addTo(_this._map);
- break;
- case 'avoid':
- var iconUrl = '/images/route/ico_p_5.png';
- var avoidMarker = new L.Marker(
- options.latLng, {
- icon: L.icon({
- iconUrl: iconUrl,
- iconSize: [25, 25],
- iconAnchor: [12, 24],
- popupAnchor: [0, -12]
- })
- }
- );
- avoidMarker.addTo(_this._map);
- break;
- case 'stop':
- var iconUrl = '/images/route/ico_p_1.png';
- _this.stopMarker = new L.Marker(
- options.latLng, {
- icon: L.icon({
- iconUrl: iconUrl,
- iconSize: [25, 25],
- iconAnchor: [12, 24],
- popupAnchor: [0, -12]
- })
- }
- );
- _this.stopMarker.addTo(_this._map);
- break;
- }
- },
- /**
- *设置路径点地图 初始化地图-添加规划路径-添加当前路径点信息(图标+文字提示)
- * @type {Function}
- * @param options {Object} {pointNum,mapWrap}
- * @private
- */
- _setPointMap: function (options) {
- var _this = this;
- //地图初始化
- var layerName = 'gh';
- //var layer2Name = 'satellite-address';
- switch (_this.options.mapType) {
- case 'gm': //线划
- layerName = 'gm';
- break;
- case 'gr': //影像
- layerName = 'gr';
- break;
- case 'gh': //影像
- layerName = 'gh';
- break;
- case 'gt': //地形
- layerName = 'gt';
- break;
- }
- var mapOptions = {
- layers: [
- L.tileLayer(map23DConfig.tileServerUrl + '/' + layerName + '?l={z}&x={x}&y={y}', {
- minZoom: 1,
- maxZoom: 19,
- subdomains: map23DConfig.tileSubdomains || '',
- noWrap: true
- })
- ],
- center: _this._markerObjs[options.pointNum].center,
- zoom: 16,
- maxZoom: 19,
- minZoom: 1,
- zoomControl: false
- };
- var pointMap = new L.Map(
- options.mapWrap,
- mapOptions
- );
- //如果是影像图,添加地名图层
- // if(_this.options.mapType === '2'){
- // L.tileLayer.builtIn.getTileLayer(layer2Name).addTo(pointMap);
- // }
- //添加缩放控件
- L.control.zoom({
- position: 'topright'
- }).addTo(pointMap);
- //添加相应的专题图
- if (_this.options.thematicUrl) {
- L.tileLayer(_this.options.thematicUrl).addTo(pointMap);
- }
- //添加路径点
- var marker = new L.Marker(_this._markerObjs[options.pointNum].center, {
- icon: L.icon({
- iconUrl: '/images/route/' + _this._markerObjs[options.pointNum].actionType + '.png',
- iconSize: [16, 16],
- iconAnchor: [8, 8],
- popupAnchor: [0, -8]
- })
- })
- .bindPopup(_this._markerObjs[options.pointNum].popInfo, {
- closeButton: false,
- maxWidth: 100,
- minWidth: 100
- });
- marker.addTo(pointMap);
- //添加规划路径图
- L.polyline(_this.pointLatLng, {
- color: '#0099ff',
- weight: 6,
- opacity: 0.8
- }).addTo(pointMap);
- }
- };
|