123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145 |
- define([
- 'html!templates/tools/toolRouteSearch',
- 'modDir/service/routeSearch',
- 'modDir/service/routeSearchNew',
- 'modDir/service/addressSearch',
- 'modDir/tools/toolRoutePlaceSearch',
- 'css!styles/tools/toolRouteSearch',
- 'vendorDir/map23dlib/leaflet.eleation',
- 'vendorDir/map23dlib/d3.v3.min',
- 'css!styles/tools/toolElevation'
- ],
- function (tpcLayout, routeSearchF, routeSearchNew, addressSearchF) {
- /**
- * 模块数据 用于数据存储和外部调用
- * @type {Object}
- * 数据存放
- */
- var modValue = {
- options: {
- searchType: 0
- // searchType: 4
- },
- directionsDataResult: null, //查询结果数据
- navigationResult: {}, //导航结果(新)
- resultNum: 0, // 导航结果第几条(新)
- brushGroup: null, //路线容器
- startPoint: { //起点坐标
- latlng: null,
- name: ''
- },
- stopPoint: { //终点坐标
- latlng: null,
- name: ''
- },
- acrossIndeX: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'G', 'K', 'L', 'M'],
- amongMarkers: {}, //中间点坐标集合
- acrossPoints: {}, //途经点坐标集合
- avoidPoints: {}, //规避点坐标集合
- roadMarker: {}, //路标 包含起点、中间点、终点
- resultHtml: null,
- pointSearchType: 0, //查询起始点 0为无,1为起点,2为终点
- markerGroup: null, //地名标记图层组
- TDClickType: null,
- routSerchGroup: 'show',
- curStation: null,
- curCname: null,
- // avoidAreas:{
- // sBounds:[],
- // eBounds:[]
- // }
- avoidAreas: [] //------------规避区域----------------- }; /* * 模块状态,用于存储模块的状态 例如:收起,关闭
- };
- var status = {
- initialized: false //是否初始化
- };
- /**
- * 初始化
- * 事件监听
- * @type {Function}
- * @returns {*}
- */
- function init() {
- if (!status.initialized) {
- // if (map23DConfig.routType == 'DTT') {}
- routeSearchF = routeSearchNew;
- setLayout();
- bindEvent();
- status.initialized = true;
- modValue.markerGroup = map23DControl.group({
- action: 'add'
- });
- modValue.brushGroup = map23DControl.group({
- action: 'add'
- });
- subscribe();
- };
- /*ONEMAP.C.publisher.publish({
- modName: 'toolRouteSearch'
- }, 'topbarClick');*/
- remove({
- modName: 'toolRouteSearch'
- });
- };
- function layoutResize() {
- if (map23DData.display.map2D) {
- $("#directionsSearch .waypointWrapper").removeClass('TD');
- $('#directionsStart').val(modValue.startPoint.name.length > 0 ? modValue.startPoint.name : '输入起点');
- $('#directionsStop').val(modValue.stopPoint.name.length > 0 ? modValue.stopPoint.name : '输入终点');
- $(".waypoint .startIcon").unbind('click');
- $(".waypoint .stopIcon").unbind('click');
- } else if (map23DData.display.map3D) {
- $("#directionsSearch .waypointWrapper").addClass('TD');
- $('#directionsStart').val(modValue.startPoint.name.length > 0 ? modValue.startPoint.name : '点击左边图标激活地图选点');
- $('#directionsStop').val(modValue.stopPoint.name.length > 0 ? modValue.stopPoint.name : '点击左边图标激活地图选点');
- bindTDEvent();
- }
- };
- function bindTDEvent() {
- $(".waypoint .startIcon").unbind('click').bind('click', function () {
- if (modValue.TDClickType != 'start') {
- modValue.TDClickType = 'start';
- $(".waypoint .startIcon").addClass('active');
- $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
- $(".waypoint .stopIcon").removeClass('active');
- ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
- ONEMAP.C.publisher.subscribe(TDClickSetPoint, 'map3DclickNew');
- } else {
- modValue.TDClickType = null;
- $(".waypoint .startIcon").removeClass('active');
- ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
- }
- })
- $("#acrossPointsList .across-li .acrossIcon").unbind('click').bind('click', function () {
- var cid = $(this).parent().parent().attr('cid');
- if (modValue.TDClickType != 'addacross' || modValue.curTDAcrossId != cid) {
- modValue.TDClickType = 'addacross';
- modValue.curTDAcrossId = cid;
- $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
- $(this).addClass('active');
- $(".waypoint .stopIcon").removeClass('active');
- $(".waypoint .startIcon").removeClass('active');
- ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
- ONEMAP.C.publisher.subscribe(TDClickSetPoint, 'map3DclickNew');
- } else {
- modValue.TDClickType = null;
- modValue.curTDAcrossId = null;
- $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
- ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
- }
- })
- $(".waypoint .stopIcon").unbind('click').bind('click', function () {
- if (modValue.TDClickType != 'stop') {
- modValue.TDClickType = 'stop';
- $(".waypoint .stopIcon").addClass('active');
- $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
- $(".waypoint .startIcon").removeClass('active');
- ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
- ONEMAP.C.publisher.subscribe(TDClickSetPoint, 'map3DclickNew');
- } else {
- modValue.TDClickType = null;
- $(".waypoint .stopIcon").removeClass('active');
- ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
- }
- })
- };
- function TDClickDelPoint(options) {
- if (options.feature.name.split('_')[0] == 'marker23D') {
- delAcrossPoint(options.feature.name);
- }
- };
- function TDClickSetPoint(options) {
- if (options.latlng.x != 0 || options.latlng.y != 0) {
- var latlng = new L.LatLng(options.latlng.y, options.latlng.x);
- if (modValue.TDClickType == 'start') {
- setStartPoint(latlng);
- $(".waypoint .startIcon").removeClass('active');
- } else if (modValue.TDClickType == 'stop') {
- setStopPoint(latlng);
- $(".waypoint .stopIcon").removeClass('active');
- } else if (modValue.TDClickType == 'addacross') {
- setAcrossPoint(latlng, null, modValue.curTDAcrossId);
- modValue.curTDAcrossId = null;
- $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
- }
- modValue.TDClickType = null;
- ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
- }
- }
- function setLayout() {
- $("#routSearchContent .cover-content").empty().append(tpcLayout);
- if (map23DData.display.map2D) {
- $("#directionsSearch .waypointWrapper").removeClass('TD');
- $('#directionsStart').val(modValue.startPoint.name.length > 0 ? modValue.startPoint.name : '输入起点');
- $('#directionsStop').val(modValue.stopPoint.name.length > 0 ? modValue.stopPoint.name : '输入终点');
- } else if (map23DData.display.map3D) {
- $("#directionsSearch .waypointWrapper").addClass('TD');
- $('#directionsStart').val(modValue.startPoint.name.length > 0 ? modValue.startPoint.name : '点击左边图标激活地图选点');
- $('#directionsStop').val(modValue.stopPoint.name.length > 0 ? modValue.stopPoint.name : '点击左边图标激活地图选点');
- bindTDEvent();
- }
- //滚动条初始
- $('#roadViewListWrap').mCustomScrollbar({
- scrollInertia: 1000
- });
- $("#pointSearchResult").mCustomScrollbar({
- scrollInertia: 1000
- });
- $("#directionsSearch .waypointWrapper .across-points-content").mCustomScrollbar({
- scrollInertia: 1000
- });
- $('<div id="routeElevationWrap" class="cover-panel"><iframe frameborder="0" class="cover-iframe"></iframe><div class="cover-content"><button class="btn close">X</button><div id="routeElevationShow"></div></div></div>').appendTo('body');
- //拖拽
- $("#routSearchContent .header").dragmove($('#routSearchContent'));
- };
- /**
- * 监听事件
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(cleanDirections, 'cleanMap');
- ONEMAP.C.publisher.subscribe(layoutResize, 'change23D');
- //PubSub.subscribe('map3D.featureClick', show3DWeather);
- };
- function unSubscribe() {
- ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
- };
- function controlMyLayer(options) {
- switch (options.action) {
- case 'remove':
- cleanDirections();
- remove({
- modName: 'clear'
- });
- break;
- case 'opacity':
- setGropOpacity(options);
- break;
- case 'up':
- case 'down':
- setGroupZIndex(options);
- break;
- }
- }
- function setGropOpacity(options) {
- options = options.options;
- if (options.opacity == 1) {
- map23DControl.group({
- action: 'show',
- guid: modValue.brushGroup
- });
- map23DControl.group({
- action: 'show',
- guid: modValue.markerGroup
- });
- map23DControl.group({
- action: 'show',
- guid: ONEMAP.M.routPlaceSearch.modValue.markerGroup
- });
- modValue.routSerchGroup = 'show';
- } else {
- map23DControl.group({
- action: 'hide',
- guid: modValue.brushGroup
- });
- map23DControl.group({
- action: 'hide',
- guid: modValue.markerGroup
- });
- map23DControl.group({
- action: 'hide',
- guid: ONEMAP.M.routPlaceSearch.modValue.markerGroup
- });
- modValue.routSerchGroup = 'hide';
- }
- }
- function remove(options) {
- if (options.modName != 'toolRouteSearch') {
- $("#header .tools-routgh").removeClass('cur');
- $("#routSearchContent").hide();
- $(".slot-title").hide();
- if (modValue.elevationControl) {
- map2DViewer.map.removeControl(modValue.elevationControl);
- modValue.elevationControl = null;
- }
- $('#routeElevationWrap').hide();
- modValue.TDClickType = null;
- $(".waypoint .startIcon").removeClass('active');
- $(".waypoint .stopIcon").removeClass('active');
- unSubscribe();
- } else {
- if ($("#header .tools-routgh").hasClass('cur')) {
- $("#header .tools-routgh").removeClass('cur');
- $("#routSearchContent").hide();
- if (modValue.elevationControl) {
- map2DViewer.map.removeControl(modValue.elevationControl);
- modValue.elevationControl = null;
- }
- $('#routeElevationWrap').hide();
- modValue.TDClickType = null;
- $(".waypoint .startIcon").removeClass('active');
- $(".waypoint .stopIcon").removeClass('active');
- unSubscribe();
- } else {
- $("#header .tools-routgh").addClass('cur');
- $("#routSearchContent").show();
- }
- }
- };
- /**
- * 三维跳转
- */
- function fly3DInView(lat, lng, zoom) {
- map3DViewer.flyTo({
- center: {
- lat: lat,
- lng: lng
- },
- zoom: zoom,
- heading: 0, //摄像机平面角度 正北为0
- tilt: 0, //摄像机倾斜角
- });
- };
- /**
- * 清空图层
- */
- function clearMarker() {
- if (map23DData.display.map3D) {
- $.each(map3DViewer.markers, function (value, key) {
- // map3DViewer.label({
- // action: 'remove',
- // guid: value,
- // featureType: 'marker'
- // })
- })
- }
- map23DControl.group({
- action: 'cleanAll',
- guid: modValue.markerGroup
- })
- };
- /**
- * 清除路径
- */
- function cleanDirections() {
- if (modValue.appendToMyLayer) {
- var options = {
- action: "remove",
- DOMid: modValue.appendToMyLayer
- }
- modValue.appendToMyLayer = ONEMAP.M.myLayers.myLayerControl(options);
- ONEMAP.C.publisher.unSubscribe(controlMyLayer, modValue.appendToMyLayer);
- modValue.appendToMyLayer = null;
- }
- if (modValue.routSerchGroup == 'hide') {
- setGropOpacity({
- options: {
- opacity: 1
- }
- })
- modValue.routSerchGroup = 'show';
- }
- //清空线
- map23DControl.group({
- action: 'cleanAll',
- guid: modValue.brushGroup
- });
- //中间点
- map23DControl.group({
- action: 'cleanAll',
- guid: modValue.markerGroup
- });
- map23DControl.group({
- action: 'cleanAll',
- guid: ONEMAP.M.routPlaceSearch.modValue.markerGroup
- });
- //重置方案
- $('.routeTypeList li:eq(1)').css({
- "display": "none"
- })
- $('#routeSearchType').text('第一方案')
- //查询结果清除
- $("#roadViewList").empty();
- $("#slot-busWaysList").empty();
- //重置路径搜索界面
- $('#directionsStart').val('输入起点');
- $('#directionsStop').val('输入终点');
- $("#acrossPointsList").empty();
- modValue.startPoint = {
- latlng: null,
- name: ''
- };
- modValue.stopPoint = {
- latlng: null,
- name: ''
- };
- modValue.amongMarkers = {};
- modValue.acrossPoints = {};
- modValue.avoidPoints = {};
- modValue.directionsDataResult = null; //查询结果数据
- modValue.navigationResult = {}; //导航结果(新)
- modValue.resultNum = 0; // 导航结果第几条(新)
- window.routingControl = null;
- $('#abtnPrintLine, #d_fav, #directionsSearch .abtnElevation,#downloadLine').hide();
- $(".header .thtitle").show();
- $('#pointSearchResult').hide();
- $('#pointSearchResultWrap').empty();
- $("#roadViewListWrap").mCustomScrollbar("update");
- $("#pointSearchResult").mCustomScrollbar("update");
- $("#directionsSearch .across .waypoint button").removeClass('active');
- $(".waypoint .acrossIcon").removeClass('active');
- $(".waypoint .stopIcon").removeClass('active');
- $(".waypoint .startIcon").removeClass('active');
- modValue.TDClickType = null;
- modValue.curTDAcrossId = null;
- ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
- ONEMAP.C.publisher.unSubscribe(TDClickDelPoint, 'map3D.featureClick');
- };
- /**
- * 清除地名查询列表
- * @return {[type]} [description]
- */
- function cleanPointSearch() {
- clearMarker();
- $('#pointSearchResult').hide()
- $('#pointSearchResultWrap').empty();
- };
- /**
- * 获取最终查询结果
- * @type {Function}
- */
- function getSearchResult() {
- if (modValue.startPoint.latlng && modValue.stopPoint.latlng && modValue.startPoint.name == $("#directionsStart").val() && modValue.stopPoint.name == $("#directionsStop").val()) {
- cleanPointSearch();
- if (map23DData.display.map2D) {
- map2DViewer.groups[modValue.brushGroup].clearLayers();
- map2DViewer.markers[modValue.roadMarker.start].addTo(map2DViewer.groups[modValue.brushGroup]);
- map2DViewer.markers[modValue.roadMarker.stop].addTo(map2DViewer.groups[modValue.brushGroup]);
- for (var item in modValue.amongMarkers) {
- modValue.amongMarkers[item].addTo(map2DViewer.groups[modValue.brushGroup]);
- }
- } else if (map23DData.display.map3D) {
- /*map3DViewer.groups[modValue.brushGroup].clearLayers();
- map3DViewer.markers[modValue.roadMarker.start].addTo(map3DViewer.groups[modValue.brushGroup]);
- map3DViewer.markers[modValue.roadMarker.stop].addTo(map3DViewer.groups[modValue.brushGroup]);
- for(var item in modValue.amongMarkers){
- amongMarkers[item].addTo(map3DViewer.groups[modValue.brushGroup]);
- }*/
- }
- setNotResultHtml('正在计算路径信息...'); //行车查询
- var routeSearch = new routeSearchF();
- var via = [];
- var avoid = [];
- via.push([modValue.startPoint.latlng.lng, modValue.startPoint.latlng.lat]);
- for (var viaItem in modValue.acrossPoints) {
- if (modValue.acrossPoints.hasOwnProperty(viaItem)) {
- via.push([modValue.acrossPoints[viaItem].latlng.lng, modValue.acrossPoints[viaItem].latlng.lat]);
- }
- }
- via.push([modValue.stopPoint.latlng.lng, modValue.stopPoint.latlng.lat]);
- for (var avoidItem in modValue.avoidPoints) {
- if (modValue.avoidPoints.hasOwnProperty(avoidItem)) {
- avoid.push([modValue.avoidPoints[avoidItem].latlng.lng, modValue.avoidPoints[avoidItem].latlng.lat]);
- }
- }
- var searchOptions = {
- viaAry: via,
- searchType: modValue.options.searchType,
- bounds: modValue.avoidAreas
- };
- routeSearch.getNaviPath(searchOptions, function (data) {
- //界面重置
- if (data.length == 1) {
- //设置界面 一条结果路径
- $('.routeTypeList li:eq(1)').css({
- "display": "none"
- })
- } else if (data.length == 2) {
- //设置界面 一条结果路径
- $('.routeTypeList li:eq(1)').css({
- "display": "block"
- })
- } else {
- setNotResultHtml('此线路无路径数据,无法规划路径!');
- return false;
- }
- $('#routeSearchType').html($('.routeTypeList li:eq(0)').text())
- modValue.resultNum = 0
- modValue.navigationResult = [];
- for (var i = 0; i < data.length; i++) {
- var minlon = 0,
- maxlon = 0,
- minlat = 0,
- maxlat = 0;
- var allPolyline = '';
- modValue.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 + ",";
- }
- modValue.navigationResult[i].coors = allPolyline;
- modValue.navigationResult[i].coordinates = data[i].coordinates;
- modValue.navigationResult[i].totalDistance = data[i].summary.totalDistance //米
- modValue.navigationResult[i].totalTime = data[i].summary.totalTime //秒
- modValue.navigationResult[i].segmengList = data[i].instructions //文字导航
- modValue.navigationResult[i].bounds = {
- minlon: minlon - (maxlon - minlon) / 5,
- maxlon: maxlon + (maxlon - minlon) / 5,
- minlat: minlat - (maxlat - minlat) / 5,
- maxlat: maxlat + (maxlat - minlat) / 5,
- }; //缩放范围
- modValue.navigationResult[i].center = {
- lon: (maxlon + minlon) / 2,
- lat: (maxlat + minlat) / 2
- }
- }
- setNavigation();
- });
- // if (map23DData.display.map2D) {
- // map2DViewer.map.fitBounds(map2DViewer.groups[modValue.brushGroup].getBounds());
- // }
- } else if (modValue.startPoint.latlng === null) {
- setNotResultHtml('未查询到起点信息,请检查对应查询条件。');
- } else if (modValue.stopPoint.latlng === null) {
- setNotResultHtml('未查询到终点信息,请检查对应查询条件。');
- }
- };
- /**
- * 绘制导航结果 (最新)
- * @type {Function}
- * @param options {Object}
- * @private
- */
- function setNavigation() {
- //移除 本模块点位popup
- $('.routePopup').remove();
- if (JSON.stringify(modValue.navigationResult) == "{}") {
- return;
- }
- if (map23DData.display.map2D) {
- map2DViewer.map.fitBounds([
- [modValue.navigationResult[modValue.resultNum].bounds.minlat, modValue.navigationResult[modValue.resultNum].bounds.minlon],
- [modValue.navigationResult[modValue.resultNum].bounds.maxlat, modValue.navigationResult[modValue.resultNum].bounds.maxlon]
- ]);
- } else {
- map3DViewer.map.camera.flyTo({
- destination: Cesium.Rectangle.fromDegrees(modValue.navigationResult[modValue.resultNum].bounds.minlon,
- modValue.navigationResult[modValue.resultNum].bounds.minlat,
- modValue.navigationResult[modValue.resultNum].bounds.maxlon,
- modValue.navigationResult[modValue.resultNum].bounds.maxlat)
- })
- }
- modValue.directionsDataResult = {}
- modValue.directionsDataResult.coors = modValue.navigationResult[modValue.resultNum].coors;
- drawCarPolyline({
- opacity: 0.8,
- lineNum: 0,
- color: '#0099ff',
- weight: 6
- });
- parseResultData(modValue.navigationResult[modValue.resultNum].segmengList);
- }
- /**
- * 在地图上画出驾车路线
- * @type {Function}
- * @param options {Object}
- * @private
- */
- function drawCarPolyline(options) {
- if (!modValue.appendToMyLayer) {
- var layerLength = ONEMAP.M.myLayers.checkLength();
- if (layerLength < map23DConfig.layerMaxLength) {
- var mylayeroptions = {
- action: "add",
- DOM: {
- name: '路径规划',
- type: "group",
- guid: modValue.markerGroup
- }
- }
- modValue.appendToMyLayer = ONEMAP.M.myLayers.myLayerControl(mylayeroptions);
- ONEMAP.C.publisher.subscribe(controlMyLayer, modValue.appendToMyLayer);
- } else {
- ONEMAP.C.publisher.publish({
- type: 'warning',
- message: '图层数量已达上限,无法上图'
- }, 'noteBar::add');
- return false;
- }
- }
- $.each(map23DData.polylines, function (i, t) {
- map23DControl.polyline({
- action: 'remove',
- guid: i
- })
- })
- var points = modValue.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;
- //var gcjloc = transformFromWGSToGCJ(parseFloat(temp[0]),parseFloat(temp[1]));
- //temp = [gcjloc.lat.toString(),gcjloc.lng.toString()];
- temp = [temp[1], temp[0]];
- pointLatLng.push(temp);
- }
- };
- var guid = map23DControl.polyline({
- action: 'add',
- groupId: modValue.brushGroup,
- geojson: {
- "properties": {
- color: '#666',
- weight: options.weight + 3,
- opacity: 1,
- altitudeMode: 0,
- },
- "geometry": {
- "coordinates": pointLatLng
- }
- }
- })
- map3DViewer.polyline({
- action: 'hide',
- guid: guid
- })
- // // if (map23DData.display.map3D == true) {
- // // }
- map23DControl.polyline({
- action: 'add',
- groupId: modValue.brushGroup,
- geojson: {
- "properties": {
- color: options.color,
- weight: options.weight,
- opacity: options.opacity,
- altitudeMode: 0,
- },
- "geometry": {
- "coordinates": pointLatLng
- }
- }
- })
- //modValue.polyLineAll.push(polylineID)
- };
- /**
- * 解析数据 填充节点
- * @type {Function}
- * @private
- */
- function parseResultData(data) {
- $(".slot-title").show();
- $("#roadViewList").empty(); //驾车类型
- for (var i = 0, l = data.length; i < l; i++) {
- var item = data[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';
- }
- var lng = modValue.navigationResult[modValue.resultNum].coordinates[item.index].lng
- var lat = modValue.navigationResult[modValue.resultNum].coordinates[item.index].lat
- var nlng = map23DControl.formatDegree(lng);
- var nlat = map23DControl.formatDegree(lat);
- var li = $('' +
- '<li class="withoutChildren" title="' + nlng + ' , ' + nlat + '" data-position-lat="' + lat + '" data-position-lon="' + lng + '">' +
- '<span class="maneuverLink">' +
- '<span class="maneuverWrapper">' +
- '<span class="maneuverHolder">' +
- '<span class="maneuverType">' +
- '<span class="maneuverNumber ' + actionType + '">' + (i + 1) + '.</span>' +
- '</span>' +
- '<span class="maneuverProgress">' + item.distance + ' 米</span>' +
- '<span class="maneuverDescription">' +
- '<span class="maneuverInstruction">' +
- //'<span class="next-street">'+item.roadName+'</span>. ' +
- '<span class="distance-description">' + item.text + '</span>.' +
- '</span>' +
- '</span>' +
- '</span>' +
- '</span>' +
- '</span>' +
- '</li><hr/>');
- $("#roadViewList").append(li);
- var popup_options = {
- name: '<span style="font-size:12px;line-height:36px; color:#fff">' + nlng + ' , ' + nlat + '</span>',
- content: item.text
- };
- var popupHtml = creatPopupHtml(popup_options);
- var markerId = map23DControl.marker({
- action: 'add',
- groupId: modValue.markerGroup,
- geojson: {
- "properties": {
- iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/ico_p_3-' + actionType + '.png',
- iconSize: [16, 16],
- iconAnchor: [8, 8],
- popupAnchor: [0, -8],
- //popupContent: popupHtml
- },
- "geometry": {
- "type": "Point",
- "coordinates": [lng, lat]
- }
- }
- });
- //modValue.markerAll.push(markerId);
- map23DControl.marker({
- action: 'hide',
- guid: markerId,
- })
- li.bind("click", {
- m: markerId,
- info: item.text
- }, function (e) {
- //if(map23DData.display.map2D){
- map23DControl.marker({
- action: 'show',
- guid: e.data.m,
- })
- $("#roadViewList .cur").removeClass('cur');
- $(this).addClass('cur');
- var lat = map23DData.markers[e.data.m].geojson.geometry.coordinates[1];
- var lng = map23DData.markers[e.data.m].geojson.geometry.coordinates[0];
- mapToPoint([lat, lng, 15])
- });
- }
- $("#roadViewList").prepend('<li style="text-align:center; font-size:14px;">总行驶里程: ' + (modValue.navigationResult[modValue.resultNum].totalDistance / 1000).toFixed(3) + '公里</li><hr/>');
- $('#abtnPrintLine').show();
- $("#downloadLine").show();
- //收藏事件
- $('#d_fav').show();
- $('#directionsSearch .abtnElevation').show();
- };
- /**
- * 无结果列表
- * @type {Function}
- * @param notText {String} 无结果提示信息
- * @returns {*}
- * @private
- */
- function setNotResultHtml(notText) {
- $('#roadViewList').empty().append('<p class="not-result">' + notText + '</p>');
- };
- /**
- * 获取起点,终点信息 通过输入框的地名和 起始点的地名匹配判断是否相同 来确定是否进行地名查询
- * pointSearchResult
- * @return {[type]} [description]
- */
- function getStartAndStop() {
- $('#pointSearchResultWrap').empty();
- modValue.resultHtml = '';
- modValue.pointSearchType = 0;
- if (modValue.startPoint.name != $("#directionsStart").val() && $('#directionsStart').val() != '' && $('#directionsStart').val() != '输入起点') {
- //起点展开
- modValue.pointSearchType = 1;
- buildSearch('start');
- };
- $.each($("#acrossPointsList li"), function (i, t) {
- if ($(t).find('input').val() != "" && $(t).find('input').val() != "输入途经点") {
- var cid = $(t).attr('cid');
- modValue.pointSearchContentCid = null;
- if (!modValue.acrossPoints[cid]) {
- modValue.acrossPoints[cid] = {
- latlng: null,
- name: null
- };
- if (modValue.pointSearchType == 0) {
- modValue.pointSearchType = 3;
- }
- buildSearch('across', cid);
- if (!modValue.pointSearchContentCid) {
- modValue.pointSearchContentCid = cid;
- }
- } else {
- if (modValue.acrossPoints[cid].name != $(t).find('input').val()) {
- modValue.acrossPoints[cid] = {
- latlng: null,
- name: $(t).find('input').val()
- };
- if (modValue.pointSearchType == 0) {
- modValue.pointSearchType = 3;
- }
- buildSearch('across', cid);
- if (!modValue.pointSearchContentCid) {
- modValue.pointSearchContentCid = cid;
- }
- }
- }
- }
- })
- if (modValue.stopPoint.name != $("#directionsStop").val() && $('#directionsStop').val() != '' && $('#directionsStop').val() != '输入终点') {
- //如果不需查询起点的时候设置终点展开
- if (modValue.pointSearchType == 0) {
- modValue.pointSearchType = 2;
- }
- buildSearch('stop');
- }
- setPlaceResultHtml();
- };
- /**
- * 构建查询结果 起始点顺序开始
- * @param {[type]} type [description]
- * @return {[type]} [description]
- */
- function buildSearch(type, cid) {
- if (cid) {
- var indexOf = $("#acrossPointsList").find('li[cid=' + cid + ']').index() + 1;
- }
- switch (type) {
- case 'start':
- modValue.resultHtml += '<div id="directionsStartSearch">' +
- '<div class="header"><h3>查询起点</h3></div>' +
- '<div class="d-waypoints" id="dStartResult"></div>' +
- '</div>';
- break;
- case 'across':
- modValue.resultHtml += '<div cid="' + cid + '" class="across-list" id="directionsAcrossSearch' + cid + '">' +
- '<div class="header"><h3>查询第' + indexOf + '途经点</h3></div>' +
- '<div class="d-waypoints" id="dAcross' + modValue.acrossIndeX[cid] + 'Result"></div>' +
- '</div>';
- break;
- case 'stop':
- modValue.resultHtml += '<div id="directionsStopSearch">' +
- '<div class="header"><h3>查询终点</h3></div>' +
- '<div class="d-waypoints" id="dStopResult"></div>' +
- '</div>';
- break;
- }
- };
- /**
- * 填充侧栏html列表
- * @type {Function}
- * @returns {*}
- * @private
- */
- function setPlaceResultHtml() {
- $('#pointSearchResultWrap').empty().append(modValue.resultHtml);
- $('#pointSearchResult').show();
- //判断查询状态,设置展开
- if (modValue.pointSearchType == 1) {
- $('#directionsStartSearch').addClass('open');
- } else if (modValue.pointSearchType == 2) {
- $('#directionsStopSearch').addClass('open');
- } else if (modValue.pointSearchType == 3) {
- $("#pointSearchResultWrap .across-list").eq(0).addClass('open');
- } else {
- return false;
- }
- //绑定事件
- $.each($("#pointSearchResultWrap .across-list"), function (i, t) {
- $(t).find('.header').bind('click', function () {
- $('#pointSearchResult .open').removeClass('open');
- $(this).parent().addClass('open');
- $(this).next().empty();
- modValue.pointSearchType = 3;
- var idName = $(this).next().attr('id');
- var cid = $(this).parent().attr('cid');
- modValue.pointSearchContentId = idName;
- modValue.pointSearchContentCid = cid;
- ONEMAP.M.routPlaceSearch.pointSearch({
- 'keyWord': $("#acrossPointsList").find('li[cid=' + cid + ']').find('input').val()
- });
- });
- })
- $('#directionsStartSearch .header').bind('click', function () {
- //if (modValue.pointSearchType == 2) {
- $('#pointSearchResult .open').removeClass('open');
- $('#directionsStartSearch').addClass('open');
- $('#didNametopResult').empty();
- //}
- modValue.pointSearchType = 1;
- ONEMAP.M.routPlaceSearch.pointSearch({
- 'keyWord': $("#directionsStart").val()
- });
- });
- $('#directionsStopSearch .header').bind('click', function () {
- //if (modValue.pointSearchType == 1) {
- $('#pointSearchResult .open').removeClass('open');
- $('#directionsStopSearch').addClass('open');
- $('#dStartResult').empty();
- //}
- modValue.pointSearchType = 2;
- ONEMAP.M.routPlaceSearch.pointSearch({
- 'keyWord': $("#directionsStop").val()
- });
- });
- if (modValue.pointSearchType == 1) {
- ONEMAP.M.routPlaceSearch.pointSearch({
- 'keyWord': $("#directionsStart").val()
- });
- }
- if (modValue.pointSearchType == 2) {
- ONEMAP.M.routPlaceSearch.pointSearch({
- 'keyWord': $("#directionsStop").val()
- });
- }
- if (modValue.pointSearchType == 3) {
- if (!modValue.pointSearchContentCid) {
- var curid = $("#pointSearchResultWrap .across-list").eq(0).attr('cid');
- var name = $("#acrossPointsList").find('li[cid=' + curid + ']').find('input').val();
- modValue.pointSearchContentCid = curid;
- modValue.pointSearchContentId = $("#pointSearchResultWrap .across-list").eq(0).attr('id');
- } else {
- var name = $("#acrossPointsList").find('li[cid=' + modValue.pointSearchContentCid + ']').find('input').val();
- var indexOf = $("#acrossPointsList").find('li[cid=' + modValue.pointSearchContentCid + ']').index();
- modValue.pointSearchContentId = $("#pointSearchResultWrap .across-list").eq(indexOf).attr('id');
- }
- ONEMAP.M.routPlaceSearch.pointSearch({
- 'keyWord': name
- });
- }
- };
- /**
- * 更新地图上描绘点
- */
- function updateMarkers(options) {
- if (options.latLng.length != 2) {
- var latlng = [];
- latlng[0] = options.latLng.lng;
- latlng[1] = options.latLng.lat;
- } else {
- var latlng = [];
- latlng[0] = options.latLng[0];
- latlng[1] = options.latLng[1];
- }
- map23DControl.marker({
- action: "update",
- guid: options.guid,
- geojson: {
- "properties": {
- title: options.name,
- popupContent: options.popupContent
- },
- "geometry": {
- "coordinates": latlng
- }
- }
- })
- }
- /**
- * 在地图上描绘点
- * @type {Function}
- * @param options {Object} {type , latLng}
- * @private
- */
- function setMarkers(options) {
- if (options.latLng.length != 2) {
- var latlng = [];
- latlng[0] = options.latLng.lng;
- latlng[1] = options.latLng.lat;
- } else {
- var latlng = [];
- latlng[0] = options.latLng[0];
- latlng[1] = options.latLng[1];
- }
- switch (options.type) {
- case 'start':
- if (modValue.roadMarker.start) {
- map23DControl.marker({
- action: 'remove',
- guid: modValue.roadMarker.start
- })
- }
- modValue.roadMarker.start = map23DControl.marker({
- action: 'add',
- groupId: modValue.brushGroup,
- geojson: {
- "type": "Feature",
- "properties": {
- iconUrl: map23DConfig.map23DAssetsUrl + '/images/tools/start_point.png',
- iconSize: [22, 29],
- iconAnchor: [11, 29],
- popupAnchor: [0, -29],
- altitudeMode: 1,
- draggable: true
- },
- "geometry": {
- "type": "Point",
- "coordinates": [latlng[0], latlng[1]]
- }
- }
- })
- if (map23DData.display.map2D) {
- map2DViewer.markers[modValue.roadMarker.start].on('dragend', function () {
- setStartPoint(this._latlng);
- });
- }
- break;
- case 'across':
- var guid = options.cid.split('_')[1];
- var acrossMarker = map23DControl.marker({
- action: 'add',
- guid: guid,
- groupId: modValue.brushGroup,
- geojson: {
- "type": "Feature",
- "properties": {
- iconUrl: map23DConfig.map23DAssetsUrl + '/images/tools/across_point.png',
- iconSize: [22, 29],
- iconAnchor: [11, 29],
- popupAnchor: [0, -29],
- altitudeMode: 1,
- draggable: true
- },
- "geometry": {
- "type": "Point",
- "coordinates": [latlng[0], latlng[1]]
- }
- }
- })
- return acrossMarker;
- break;
- case 'avoid':
- var avoidMarker = map23DControl.marker({
- action: 'add',
- groupId: modValue.brushGroup,
- geojson: {
- "type": "Feature",
- "properties": {
- iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/ico_p_5.png',
- iconSize: [25, 25],
- iconAnchor: [12, 24],
- popupAnchor: [0, -25],
- altitudeMode: 1,
- draggable: true,
- },
- "geometry": {
- "type": "Point",
- "coordinates": [latlng[0], latlng[1]]
- }
- }
- })
- return avoidMarker;
- break;
- case 'stop':
- if (modValue.roadMarker.stop) {
- map23DControl.marker({
- action: 'remove',
- guid: modValue.roadMarker.stop
- })
- }
- modValue.roadMarker.stop = map23DControl.marker({
- action: 'add',
- groupId: modValue.brushGroup,
- geojson: {
- "type": "Feature",
- "properties": {
- iconUrl: map23DConfig.map23DAssetsUrl + '/images/tools/stop_point.png',
- iconSize: [22, 29],
- iconAnchor: [11, 29],
- popupAnchor: [0, -29],
- altitudeMode: 1,
- },
- "geometry": {
- "type": "Point",
- "coordinates": [latlng[0], latlng[1]]
- }
- }
- })
- if (map23DData.display.map2D) {
- map2DViewer.markers[modValue.roadMarker.stop].on('dragend', function () {
- setStopPoint(this._latlng);
- });
- }
- break;
- }
- };
- /**
- * 设置起点坐标
- * @type {Function}
- * @param latLng {Object}
- */
- function setStartPoint(latLng, name) {
- if (!status.initialized) {
- init();
- }
- $("#routSearchContent").show();
- $("#header .tools-routgh").addClass('cur');
- if (latLng instanceof Array) {
- modValue.startPoint.latlng = new L.LatLng(latLng[1], latLng[0]);
- latLng = new L.LatLng(latLng[1], latLng[0]);
- } else {
- modValue.startPoint.latlng = latLng;
- }
- var nLatlng = L.Util.formatHMS(latLng);
- setMarkers({
- type: 'start',
- latLng: latLng
- });
- if (name) {
- $("#directionsStart").val(name);
- modValue.startPoint.name = name;
- if (map23DData.display.map2D) {
- var popup_options = {
- name: name,
- content: '<span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
- };
- var popupHtml = creatPopupHtml(popup_options);
- map2DViewer.markers[modValue.roadMarker.start].bindPopup(popupHtml, {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- }
- var curMarkerData = map2DViewer.markers[modValue.roadMarker.start].getLatLng();
- updateMarkers({
- name: name,
- latLng: [curMarkerData.lng, curMarkerData.lat],
- guid: modValue.roadMarker.start,
- popupContent: popupHtml
- });
- getSearchResult();
- } else {
- ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(latLng, function (data) {
- if (!data.address) {
- data.address = '未知地点';
- }
- $("#directionsStart").val(data.address);
- modValue.startPoint.name = data.address;
- var curMarkerData = map2DViewer.markers[modValue.roadMarker.start].getLatLng();
- updateMarkers({
- name: name,
- latLng: [curMarkerData.lng, curMarkerData.lat],
- guid: modValue.roadMarker.start
- });
- if (map23DData.display.map2D) {
- var popup_options = {
- name: data.address,
- content: '<span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
- };
- var popupHtml = creatPopupHtml(popup_options);
- map2DViewer.markers[modValue.roadMarker.start].bindPopup(popupHtml, {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- }
- //setMarkers();
- getSearchResult();
- });
- }
- };
- /**
- * 创建冒泡窗
- */
- function creatPopupHtml(options) {
- var popupHtml = '<div class="popup_html">' +
- ' <div class="popup-lt"></div>' +
- ' <div class="popup-lb"></div>' +
- ' <div class="popup-rt"></div>' +
- ' <div class="popup-rb"></div>' +
- ' <div class="popup-ct" style="text-indent:15px;line-height:48px">' + options.name +
- ' </div>' +
- ' <div class="popup-cb" style="padding-bottom:20px;color:#666666 !important">' + options.content + '</div>' +
- '</div>'
- return popupHtml;
- }
- /**
- * 添加途经点坐标
- * @type {Function}
- * @param latLng {Object}
- */
- function setAcrossPoint(latLng, name, cid) {
- if (!status.initialized) {
- init();
- }
- $("#routSearchContent").show();
- $("#header .tools-routgh").addClass('cur');
- if (ONEMAP.T.getObjNameAry(modValue.acrossPoints).length > 4) {
- alert('最多可添加 5 个途经点');
- return false;
- }
- if (latLng instanceof Array) {
- latLng = new L.LatLng(latLng[1], latLng[0]);
- }
- var acrossPoint = {
- name: '未知地点',
- latlng: latLng
- }
- //if(modValue.curTDAcrossId){
- // cid = modValue.curTDAcrossId;
- //}
- if (!cid) {
- $(".waypoint .choose-across").click();
- var length = $("#acrossPointsList li").length;
- cid = $("#acrossPointsList li").eq(length - 1).attr('cid');
- }
- if (cid) {
- var pointId = cid;
- }
- if (modValue.amongMarkers[pointId]) {
- updateMarkers({
- type: 'across',
- latLng: latLng,
- cid: cid,
- guid: pointId
- });
- var acrossMarkerId = pointId;
- } else {
- var acrossMarkerId = setMarkers({
- type: 'across',
- latLng: latLng,
- cid: cid
- });
- }
- modValue.amongMarkers[pointId] = map2DViewer.markers[acrossMarkerId];
- modValue.acrossPoints[pointId] = acrossPoint;
- modValue.amongMarkers[pointId].on('dragend', function () {
- modValue.acrossPoints[pointId].latlng = this._latlng;
- //去更新popup
- ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(modValue.acrossPoints[pointId].latlng, function (data) {
- if (!data.address) {
- data.address = '未知地点';
- }
- modValue.acrossPoints[pointId].name = data.address;
- var nLatlng = L.Util.formatHMS(modValue.acrossPoints[pointId].latlng);
- var curMarkerData = modValue.amongMarkers[pointId].getLatLng();
- updateMarkers({
- name: data.address,
- latLng: [curMarkerData.lng, curMarkerData.lat],
- guid: pointId
- }); //
- var popup_options = {
- name: data.address,
- content: '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAcrossPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
- };
- var popupHtml = creatPopupHtml(popup_options);
- modValue.amongMarkers[pointId].bindPopup(popupHtml, {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- });
- getSearchResult();
- });
- if (name) {
- modValue.acrossPoints[pointId].name = name;
- $("#acrossPointsList").find('li[cid=' + cid + ']').find('input').val(name);
- var curMarkerData = modValue.amongMarkers[pointId].getLatLng();
- updateMarkers({
- name: name,
- latLng: [curMarkerData.lng, curMarkerData.lat],
- guid: pointId
- });
- var nLatlng = L.Util.formatHMS(latLng);
- var popup_options = {
- name: name,
- content: '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAcrossPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
- };
- var popupHtml = creatPopupHtml(popup_options);
- modValue.amongMarkers[pointId].bindPopup(popupHtml, {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- getSearchResult();
- } else {
- ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(latLng, function (data) {
- if (!data.address) {
- data.address = '未知地点';
- }
- $("#acrossPointsList").find('li[cid=' + cid + ']').find('input').val(data.address);
- modValue.acrossPoints[pointId].name = data.address;
- var nLatlng = L.Util.formatHMS(latLng);
- var curMarkerData = modValue.amongMarkers[pointId].getLatLng();
- updateMarkers({
- name: data.address,
- latLng: [curMarkerData.lng, curMarkerData.lat],
- guid: pointId
- });
- var popup_options = {
- name: data.address,
- content: '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAcrossPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
- };
- var popupHtml = creatPopupHtml(popup_options);
- modValue.amongMarkers[pointId].bindPopup(popupHtml, {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- getSearchResult();
- });
- }
- };
- /**
- * 移除途经点
- * @param {[type]} pointId [description]
- * @return {[type]} [description]
- */
- function delAcrossPoint(pointId) {
- map23DControl.marker({
- action: 'remove',
- guid: pointId
- });
- $("#acrossPointsList").find('li[cid=' + pointId + ']').remove();
- delete modValue.amongMarkers[pointId];
- delete modValue.acrossPoints[pointId];
- //var acrossPointsArry = Object.getOwnPropertyNames(modValue.acrossPoints);
- //var latname = acrossPointsArry[acrossPointsArry.length - 1];
- //$.each(modValue.acrossPoints, function(i, t) {
- // if (i > pointId) {
- // modValue.acrossPoints[i - 1] = modValue.acrossPoints[i]
- // }
- //});
- //delete modValue.acrossPoints[latname];
- getSearchResult();
- };
- //移除规避区域
- function delAvoidArea(id) {
- map2DViewer.polygon({
- action: 'remove',
- guid: id
- });
- }
- /**
- * 添加规避点坐标
- * @type {Function}
- * @param latLng {Object}
- */
- function setAvoidPoint(latLng, name) {
- if (!status.initialized) {
- init();
- }
- $("#routSearchContent").show();
- $("#header .tools-routgh").addClass('cur');
- if (ONEMAP.T.getObjNameAry(modValue.avoidPoints).length == 5) {
- alert('最多可添加 5 个规避点');
- return false;
- }
- if (latLng instanceof Array) {
- latLng = new L.LatLng(latLng[1], latLng[0]);
- }
- var avoidPoint = {
- name: '未知地点',
- latlng: latLng
- };
- var avoidMarkerId = setMarkers({
- type: 'avoid',
- latLng: latLng
- });
- var pointId = avoidMarkerId;
- if (map23DData.display.map2D) {
- modValue.amongMarkers[pointId] = map2DViewer.markers[pointId];
- modValue.avoidPoints[pointId] = avoidPoint;
- modValue.amongMarkers[pointId].on('dragend', function () {
- modValue.avoidPoints[pointId].latlng = this._latlng;
- //去更新popup
- ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(modValue.avoidPoints[pointId].latlng, function (data) {
- if (!data.address) {
- data.address = '未知地点';
- }
- modValue.avoidPoints[pointId].name = data.address;
- var nLatlng = L.Util.formatHMS(modValue.avoidPoints[pointId].latlng);
- modValue.amongMarkers[pointId].bindPopup(data.address + '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAvoidPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>', {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- });
- getSearchResult();
- });
- if (name) {
- modValue.avoidPoints[pointId].name = name;
- var nLatlng = L.Util.formatHMS(latLng);
- modValue.amongMarkers[pointId].bindPopup(name + '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAvoidPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>', {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- getSearchResult();
- } else {
- ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(latLng, function (data) {
- if (!data.address) {
- data.address = '未知地点';
- }
- modValue.avoidPoints[pointId].name = data.address;
- var nLatlng = L.Util.formatHMS(latLng);
- modValue.amongMarkers[pointId].bindPopup(data.address + '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAvoidPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">(' + nLatlng.lng + ' , ' + nLatlng.lat + ')</span>', {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- getSearchResult();
- });
- }
- }
- };
- /**
- * 移除规避点
- * @param {[type]} pointId [description]
- * @return {[type]} [description]
- */
- function delAvoidPoint(pointId) {
- map23DControl.marker({
- action: 'remove',
- guid: pointId
- });
- delete modValue.amongMarkers[pointId];
- delete modValue.avoidPoints[pointId];
- getSearchResult();
- };
- /**
- * 设置终点坐标
- * @type {Function}
- * @param latLng {Object}
- */
- function setStopPoint(latLng, name) {
- if (!status.initialized) {
- init();
- }
- $("#routSearchContent").show();
- $("#header .tools-routgh").addClass('cur');
- if (latLng instanceof Array) {
- modValue.stopPoint.latlng = new L.LatLng(latLng[1], latLng[0]);
- latLng = new L.LatLng(latLng[1], latLng[0]);
- } else {
- modValue.stopPoint.latlng = latLng;
- }
- var nLatlng = L.Util.formatHMS(latLng);
- setMarkers({
- type: 'stop',
- latLng: latLng
- });
- if (name) {
- $("#directionsStop").val(name);
- modValue.stopPoint.name = name;
- var curMarkerData = map2DViewer.markers[modValue.roadMarker.stop].getLatLng();
- updateMarkers({
- name: name,
- latLng: [curMarkerData.lng, curMarkerData.lat],
- guid: modValue.roadMarker.stop
- });
- if (map23DData.display.map2D) {
- var popup_options = {
- name: name,
- content: '<span style="font-size:12px;line-height:36px; color:#fff">(' + nLatlng.lng + ' , ' + nLatlng.lat + ')</span>'
- };
- var popupHtml = creatPopupHtml(popup_options);
- map2DViewer.markers[modValue.roadMarker.stop].bindPopup(popupHtml, {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- }
- getSearchResult();
- } else {
- ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(latLng, function (data) {
- if (!data.address) {
- data.address = '未知地点';
- }
- $("#directionsStop").val(data.address);
- modValue.stopPoint.name = data.address;
- var curMarkerData = map2DViewer.markers[modValue.roadMarker.stop].getLatLng();
- updateMarkers({
- name: data.address,
- latLng: [curMarkerData.lng, curMarkerData.lat],
- guid: modValue.roadMarker.stop
- });
- if (map23DData.display.map2D) {
- var popup_options = {
- name: data.address,
- content: '<span style="font-size:12px;line-height:36px; color:#fff">(' + nLatlng.lng + ' , ' + nLatlng.lat + ')</span>'
- };
- var popupHtml = creatPopupHtml(popup_options);
- map2DViewer.markers[modValue.roadMarker.stop].bindPopup(popupHtml, {
- closeButton: false,
- autoPan: false,
- maxWidth: 160,
- minWidth: 160
- }).openPopup();
- }
- getSearchResult();
- });
- }
- };
- function keyserch(e) {
- if (e == 13) {
- var acrossChange = true;
- $.each($("#acrossPointsList li"), function (i, t) {
- if ($(t).find('input').val() != "" && $(t).find('input').val() != "输入途经点") {
- var cid = $(t).attr('cid');
- if (!modValue.acrossPoints[cid]) {
- acrossChange = false;
- } else {
- if (modValue.acrossPoints[cid].name != $(t).find('input').val()) {
- acrossChange = false;
- }
- }
- }
- });
- if (acrossChange && modValue.startPoint.latlng && modValue.stopPoint.latlng && modValue.startPoint.name == $('#directionsStart').val() && modValue.stopPoint.name == $('#directionsStop').val()) {
- getSearchResult();
- } else if ($.trim($('#directionsStart').val()) != '' && $('#directionsStart').val() != '输入起点' && $.trim($('#directionsStop').val()) != '' && $('#directionsStop').val() != '输入终点') {
- if ((/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\s\"]/g).test($("#directionsStart").val())) {
- setNotResultHtml('起点只能包含英文、数字、中文');
- return false;
- }
- if ($.trim($("#directionsStart").val()).length < 2) {
- setNotResultHtml('起点不允许输入单字符');
- return false;
- }
- if ((/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\s\"]/g).test($("#directionsStop").val())) {
- setNotResultHtml('终点只能包含英文、数字、中文');
- return false;
- }
- if ($.trim($("#directionsStop").val()).length < 2) {
- setNotResultHtml('终点不允许输入单字符');
- return false;
- }
- getStartAndStop();
- } else if ($.trim($('#directionsStart').val()) == '' || $('#directionsStart').val() == '输入起点') {
- setNotResultHtml('起点不能为空,请检查对应查询条件。');
- return false;
- } else if ($.trim($('#directionsStop').val()) == '' || $('#directionsStop').val() == '输入终点') {
- setNotResultHtml('终点不能为空,请检查对应查询条件。');
- return false;
- }
- }
- };
- /**
- * 下载地图上路线数据
- * 格式为geojson
- */
- function downloadLineGeojson(){
- var geojson = {
- "type": "FeatureCollection",
- "features": [{
- "type": "Feature",
- "properties": {
- name:modValue.startPoint.name
- },
- "geometry": {
- "type": "Point",
- "coordinates": [
- modValue.startPoint.latlng.lng,
- modValue.startPoint.latlng.lat,
- ]
- }
- },{
- "type": "Feature",
- "properties": {
- name:modValue.stopPoint.name
- },
- "geometry": {
- "type": "Point",
- "coordinates": [
- modValue.stopPoint.latlng.lng,
- modValue.stopPoint.latlng.lat,
- ]
- }
- }]
- };
- $.each(modValue.acrossPoints,function(i,t){
- geojson.features.push({
- "type": "Feature",
- "properties": {
- name:t.name
- },
- "geometry": {
- "type": "Point",
- "coordinates": [
- t.latlng.lng,
- t.latlng.lat,
- ]
- }
- })
- })
- var points = modValue.directionsDataResult.coors;
- //转换为可用坐标
- var pArray = points.split(',');
- var pointLatLng = [];
- var dDouble = true;
- var temp = [];
- for (var i = 0, l = pArray.length; i < l; i++) {
- var num = pArray[i];
- if(typeof(pArray[i]) == "string" && pArray[i] != ""){
- num = JSON.parse(num);
- }
- if (dDouble) {
- temp = [];
- temp.push(num);
- dDouble = false;
- } else {
- temp.push(num);
- dDouble = true;
- pointLatLng.push(temp);
- }
- }
- geojson.features.push({
- "type": "Feature",
- "properties": {
- },
- "geometry": {
- "type": "LineString",
- "coordinates": pointLatLng
- }
- })
- var eleLink = document.createElement('a');
- var filename = 'exportRout.geojson';
- eleLink.download = filename;
- var content = JSON.stringify(geojson);
- var blob = new Blob([content]);
- var href = URL.createObjectURL(blob);
- eleLink.href = href;
- $(eleLink)[0].click();
- }
- function bindEvent() {
- //添加途经点
- $(".waypoint .choose-across").unbind('click').bind('click', function () {
- if ($("#acrossPointsList .across-li").length > 4) {
- alert('最多可添加 5 个途经点');
- return false;
- }
- var divID = map23DControl.buildGuid('marker23D');
- var acrossItemHtml = '<li class="across-li" cid="' + divID + '">' +
- '<div class="waypoint">' +
- '<div class="searchBox">' +
- '<input type="text" class="input directions-across" title="输入途经点">' +
- '<a class="delete-cur-across"></a>' +
- '</div>' +
- '<div class="acrossIcon"></div>' +
- '</div>' +
- '</li>';
- $(acrossItemHtml).appendTo($("#acrossPointsList"));
- $.each($("#acrossPointsList li"), function (i, t) {
- if ($(t).find('input').val() == "") {
- $(t).find('input').val("输入途经点");
- }
- })
- $("#directionsSearch .waypointWrapper .across-points-content").mCustomScrollbar('update');
- bindEvent();
- if (map23DData.display.map3D) {
- bindTDEvent();
- }
- });
- //添加规避区域
- $(".waypoint .choose-avoid").unbind("click").bind("click", function () {
- if ($("#avoidAreaList .avoid-li").length > 4) {
- alert('最多可添加 5 个规避区域');
- return false;
- }
- map2DViewer.drawrectangleFire = function (data) {
- var guid = map2DViewer.polygon({
- action: 'add',
- polygontype: 'circlepolygon', //polygon circlepolygon
- geojson: {
- "type": "Feature",
- "properties": {
- title: '测试矩形',
- color: '#0033ff',
- weight: 3,
- fillColor: '#ff9999',
- opacity: 1,
- fillOpacity: 0.5,
- popupContent: '',
- },
- "geometry": {
- "type": "Polygon",
- "coordinates": [data._latlng]
- }
- }
- })
- var dbd = new Array();
- dbd[0] = [data.bounds[0][1], data.bounds[0][0]];
- dbd[1] = [data.bounds[1][1], data.bounds[1][0]];
- modValue.options.searchType = 4;
- modValue.avoidAreas.push(dbd);
- var avoidItemHtml = '<li class="avoid-li" cid="' + guid + '">' +
- '<div class="waypoint">' +
- '<div class="searchBox">' +
- '<input type="text" class="input directions-avoid" title="绘制规避区域" value=' + dbd + '>' +
- '<a class="delete-cur-avoid">删除</a>' +
- '</div>' +
- '<div class="avoidIcon"></div>' +
- '</div>' +
- '</li>';
- $(avoidItemHtml).appendTo($("#avoidAreaList"));
- $.each($("#avoidAreaList li"), function (i, t) {
- if ($(t).find('input').val() == "") {
- $(t).find('input').val("绘制规避区域");
- }
- })
- $("#directionsSearch .waypointWrapper .avoid-points-content").mCustomScrollbar('update');
- bindEvent();
- if (map23DData.display.map3D) {
- bindTDEvent();
- }
- };
- var avoidA = map2DViewer.setDrawRectangle({
- action: 'add_start',
- offset: [-1000, 50],
- properties: {
- title: '测试矩形',
- color: '#ff0000',
- weight: 3,
- fillColor: '#ff9999',
- opacity: 1,
- fillOpacity: 0.5,
- popupContent: '',
- },
- });
- // var divID = map23DControl.buildGuid('marker23D');
- });
- // 删除当前规避区域
- $("#avoidAreaList .delete-cur-avoid").unbind('click').bind('click', function () {
- var curid = $(this).parent().parent().parent().attr('cid');
- //数据删除
- delAvoidArea(curid);
- var index = $(this).parents().filter(".avoid-li").index();
- $(this).parents().filter(".avoid-li").remove();
- // var hh = modValue.avoidAreas;
- modValue.avoidAreas.splice(index, 1);
- // var gg = modValue.avoidAreas;
- //重新获取路线
- getSearchResult();
- })
- // 删除当前途经点
- $("#acrossPointsList .delete-cur-across").unbind('click').bind('click', function () {
- var curid = $(this).parent().parent().parent().attr('cid');
- //数据删除
- delAcrossPoint(curid)
- //重新获取路线
- getSearchResult();
- })
- //路径规划模式选择
- $(".routeTypeList li").unbind('click').bind('click', function () {
- $(".routeTypeList li").removeClass("active");
- $(this).addClass("active");
- $("#routeSearchType").text($(this).text());
- modValue.resultNum = $(this).attr("type");
- $(".routeTypeList").hide();
- //清空点标记图层组
- map23DControl.group({
- action: 'cleanAll',
- guid: modValue.markerGroup
- })
- setNavigation();
- })
- $(".routeTypeList li").hover(function () {
- $(".routeTypeList li").removeClass("active");
- $(this).addClass("active");
- })
- $("#routeSearchType").click(function () {
- $(".routeTypeList").show();
- })
- $("#routeSearchType").bind('mouseleave', function () {
- $(".routeTypeList").hide();
- })
- $(".routeTypeList").hover(function () {
- $(".routeTypeList").show();
- }, function () {
- $(".routeTypeList").hide();
- })
- //清除路径
- $('#d_clear a').unbind('focus').bind('click', function () {
- cleanDirections();
- $(".slot-title").hide();
- });
- //收藏
- $('#d_fav a').unbind('click').bind('click', function () {
- //判断是否登录,没有登录进行提示
- if (!ONEMAP.D.isLoad) {
- ONEMAP.C.publisher.publish({
- type: 'warning',
- message: '请登录后使用!'
- }, 'noteBar::add');
- return false;
- }
- var acrossPointsAry = [];
- for (var across in modValue.acrossPoints) {
- //if(modValue.acrossPoints.hasOwnProperty(across)){
- acrossPointsAry.push([modValue.acrossPoints[across].latlng.lng, modValue.acrossPoints[across].latlng.lat]);
- //}
- }
- var avoidPointsAry = [];
- for (var avoid in modValue.avoidPoints) {
- //if(modValue.avoidPoints.hasOwnProperty(avoid)){
- avoidPointsAry.push([modValue.avoidPoints[avoid].latlng.lng, modValue.avoidPoints[avoid].latlng.lat]);
- //}
- }
- var objData = {
- name: $('#directionsStart').val() + ' 至 ' + $('#directionsStop').val(),
- startpoint_lat: modValue.startPoint.latlng.lat,
- startpoint_lon: modValue.startPoint.latlng.lng,
- stoppoint_lat: modValue.stopPoint.latlng.lat,
- stoppoint_lon: modValue.stopPoint.latlng.lng,
- acrossPoints: JSON.stringify(acrossPointsAry),
- avoidPoints: JSON.stringify(avoidPointsAry)
- //acrossPoints : acrossPointsAry,
- //avoidPoints :avoidPointsAry
- };
- require(['modDir/user/userRoute'], function (userRoute) {
- userRoute.addRoute(objData);
- })
- });
- $('#directionsStart').bind('focus', function () {
- $(this).val('');
- });
- $('#directionsStop').bind('focus', function () {
- $(this).val('');
- });
- $("#acrossPointsList .directions-across").bind('focus', function () {
- $(this).val('');
- });
- $("#acrossPointsList .directions-across").bind('focusout', function () {
- if ($(this).val() == '') {
- $(this).val('输入途经点');
- }
- });
- $("#avoidAreaList .directions-avoid").bind('focus', function () {
- $(this).val('');
- });
- $("#avoidAreaList .directions-avoid").bind('focusout', function () {
- if ($(this).val() == '') {
- $(this).val('绘制规避区域');
- }
- });
- $('#directionsStart').bind('focusout', function () {
- if ($(this).val() == '') {
- if (map23DData.display.map2D) {
- $(this).val('输入起点');
- } else {
- $(this).val('点击左边图标激活地图选点');
- }
- };
- });
- $('#directionsStop').bind('focusout', function () {
- if ($(this).val() == '') {
- if (map23DData.display.map2D) {
- $(this).val('输入起点');
- } else {
- $(this).val('点击左边图标激活地图选点');
- }
- };
- });
- //查询路线 如果有起始点,直接查询,没有,先去查询起始点的位置
- $("#directionsSearchButton").unbind('click').bind("click", function () {
- keyserch(13);
- });
- $("#directionsStart").unbind('keydown').bind('keydown', function (e) {
- keyserch(e.keyCode);
- })
- $("#directionsStop").unbind('keydown').bind("keydown", function (e) {
- keyserch(e.keyCode);
- });
- // $("#directionsStart").unbind('change').bind('change', function (e) {
- // cleanDirections();
- // })
- // $("#directionsStop").unbind('change').bind("change", function (e) {
- // cleanDirections();
- // });
- //路线导出
- $("#downloadLine").unbind('click').bind('click',function(){
- downloadLineGeojson()
- })
- //打印事件
- $('#abtnPrintLine').unbind('click').bind('click', function () {
- var acrossPointsAry = [];
- for (var across in modValue.acrossPoints) {
- if (modValue.acrossPoints.hasOwnProperty(across)) {
- acrossPointsAry.push([modValue.acrossPoints[across].latlng.lat, modValue.acrossPoints[across].latlng.lng]);
- }
- }
- var avoidPointsAry = [];
- for (var avoid in modValue.avoidPoints) {
- if (modValue.avoidPoints.hasOwnProperty(avoid)) {
- avoidPointsAry.push([modValue.avoidPoints[avoid].latlng.lat, modValue.avoidPoints[avoid].latlng.lng]);
- }
- }
- var can = '?m=directions' +
- '&dir=' + modValue.startPoint.latlng.lat + '|' + modValue.startPoint.latlng.lng + '|' + modValue.stopPoint.latlng.lat + '|' + modValue.stopPoint.latlng.lng + '|' + map2DViewer.map.getMaxZoom() +
- '&across=' + JSON.stringify(acrossPointsAry) +
- '&searchType=' + JSON.stringify(modValue.options.searchType) +
- '&avoid=' + JSON.stringify(avoidPointsAry) +
- '&map=' + ONEMAP.M.mapHolder.modValue.mainLayers + '|' + map2DViewer.map.getZoom() + '|' + map2DViewer.map.getCenter().lat + '|' + map2DViewer.map.getCenter().lng +
- '&place=' + modValue.startPoint.name + '|' + modValue.stopPoint.name +
- '&plan=' + $('.routeTypeList .active').attr('type')
- window.open('/print.html' + can);
- });
- $('#routeElevationWrap .close').unbind('click').bind('click', function () {
- $('#routeElevationShow').empty();
- $('#routeElevationWrap').hide();
- $('#directionsSearch .abtnElevation').removeClass("active");
- });
- ////剖面量算事件 ,'d3/d3.v3.min'
- $('#directionsSearch .abtnElevation').unbind('click').bind('click', function () {
- $(this).addClass("active");
- var coordinates = '' + modValue.startPoint.latlng.lng + ',' + modValue.startPoint.latlng.lat + ',';
- var points = modValue.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);
- }
- }
- for (var ii = 0, ll = pointLatLng.length; ii < ll; ii++) {
- if (ii % 2 == 0) {
- coordinates += pointLatLng[ii]['lng'] + ',' + pointLatLng[ii]['lat'] + ',';
- }
- }
- coordinates += modValue.stopPoint.latlng.lng + ',' + modValue.stopPoint.latlng.lat;
- var url = onemapUrlConfig.elevationDataUrl + '/v1.0/geoprocessing/profile_elevation';
- var ajaxData = {
- points: '[' + coordinates + ']',
- count: 8,
- zoom: map23DData.view.zoom,
- delta_zoom: 0
- };
- $.ajax({
- type: "post",
- dataType: 'json',
- url: url,
- data: ajaxData,
- beforeSend: ONEMAP.V.loading.load(),
- success: function (data) {
- if (data.code == 0) {
- data = data.data;
- if (data.length > 0) {
- var coordinatesAll = [];
- var coordinatesTemp = [];
- var gap = 1;
- for (var i = 0, l = data.length; i < l; i++) {
- coordinatesTemp = [data[i + 2], data[i + 3], data[i + 1]];
- coordinatesAll.push(coordinatesTemp);
- i = i + 3;
- }
- var geojson = {
- "name": "NewFeatureType",
- "type": "FeatureCollection",
- "features": [{
- "type": "Feature",
- "geometry": {
- "type": "LineString",
- "coordinates": coordinatesAll
- },
- "properties": null
- }]
- };
- if (modValue.elevationControl) {
- map2DViewer.map.removeControl(modValue.elevationControl);
- modValue.elevationControl = null;
- }
- modValue.elevationControl = L.control.elevation();
- modValue.elevationControl.addTo(map2DViewer.map);
- var gjl = L.geoJson(geojson, {
- onEachFeature: modValue.elevationControl.addData.bind(modValue.elevationControl)
- });
- $('#routeElevationShow').empty();
- $(".leaflet-control-elevation").appendTo($('#routeElevationShow'));
- $(".leaflet-control-elevation").css({
- 'position': 'absolute',
- 'left': 0,
- 'bottom': 0
- });
- $('#routeElevationWrap').show();
- // if(ONEMAP.M.mapHolder._elevationControl){
- // ONEMAP.M.mapHolder._elevationControl.removeFrom(_this._map);
- // ONEMAP.M.mapHolder._elevationControl = null;
- // var gjl = L.geoJson(geojson,{
- // onEachFeature: ONEMAP.M.mapHolder._elevationControl.addData.bind(ONEMAP.M.mapHolder._elevationControl)
- // });
- // }else {
- // require(['ocean/Control.Elevation','d3/d3.v3.min'], function () {
- // ONEMAP.M.mapHolder._elevationControl = L.control.elevation();
- // ONEMAP.M.mapHolder._elevationControl.addTo(_this._map);
- // var gjl = L.geoJson(geojson,{
- // onEachFeature: ONEMAP.M.mapHolder._elevationControl.addData.bind(ONEMAP.M.mapHolder._elevationControl)
- // });
- // });
- // }
- } else {
- ONEMAP.C.publisher.publish({
- type: 'error',
- message: '无量算数据显示'
- }, 'noteBar::add');
- }
- } else {
- ONEMAP.C.publisher.publish({
- type: 'error',
- message: data.message
- }, 'noteBar::add');
- }
- },
- completer: ONEMAP.V.loading.loaded()
- });
- });
- };
- /**
- * 设置地图到指定的区域
- * 支持url解析
- * @type {Function}
- * @param options {Object} {center:中心点,zoom:缩放比例}
- */
- function mapToPoint(options) {
- var mapViewer = {
- center: {
- lat: options[0],
- lng: options[1],
- },
- alt: map3DViewer.getZoomFrom2DZoom(options[2], -90)
- };
- map23DControl.flyTo(mapViewer);
- };
- return ONEMAP.M.toolRouteSearch = {
- init: init,
- clearMarker: clearMarker,
- modValue: modValue,
- setStartPoint: setStartPoint,
- setAcrossPoint: setAcrossPoint,
- delAcrossPoint: delAcrossPoint,
- setAvoidPoint: setAvoidPoint,
- delAvoidPoint: delAvoidPoint,
- setStopPoint: setStopPoint
- }
- })
|