toolPlaceSearch.js 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191
  1. define([
  2. 'html!templates/tools/toolPlaceSearch',
  3. 'modDir/service/addressSearch',
  4. 'modDir/service/poiSearch',
  5. 'modDir/service/regionSearch',
  6. 'modDir/service/routeSearch',
  7. 'text!data/address_baike/db.json',
  8. 'css!styles/tools/toolPlaceSearch'
  9. ], function(tpcLayout, addressSearchF, poiSearchF, regionSearchF, routeSearchF, addressBaikeDb) {
  10. /**
  11. * 索引函数
  12. */
  13. if (!Array.prototype.indexOf) {
  14. Array.prototype.indexOf = function(elt, from) {
  15. var len = this.length;
  16. var from = Number(arguments[1]) || 0;
  17. from = (from < 0) ? Math.ceil(from) : Math.floor(from);
  18. if (from < 0) {
  19. from += len;
  20. }
  21. for (; from < len; from++) {
  22. if (from in this && this[from] === elt) {
  23. return from;
  24. }
  25. return -1;
  26. }
  27. }
  28. }
  29. /**
  30. * 模块数据 用于数据存储和外部调用
  31. * @type {Object}
  32. * 数据存放
  33. */
  34. var modValue = {
  35. markers: {},
  36. options: {
  37. page: 1,
  38. bounds: null,
  39. pageSize: 10,
  40. keyWord: '',
  41. type: 'bounds', // bounds/dis
  42. center: null, //中心点
  43. dis: 0, //圆范围
  44. themeId: null, //类型
  45. pac: 0, //区域pac
  46. init_query_key: '' //原始查询关键字
  47. },
  48. initialized: false, //是否初始化
  49. placeDataResult: null, //查询数据集合
  50. fitBounds: true, //最优显示
  51. circleGroup: null, //圆容器
  52. searchCircle: null,
  53. searchPoup: null,
  54. markerGroup: null, //标记容器
  55. areaGroup: [], //区域容器
  56. searchArea:null,//当前选择的区域信息
  57. hotPoint: [{
  58. "name": "热门",
  59. "id": "0",
  60. "sons": [
  61. { "name": "交通枢纽", "id": "11" },
  62. { "name": "加油站", "id": "14" },
  63. { "name": "停车场", "id": "16" },
  64. { "name": "桥梁", "id": "12" },
  65. { "name": "城镇居民点", "id": "51" },
  66. { "name": "机关团体", "id": "42" },
  67. { "name": "企事业单位", "id": "43" },
  68. { "name": "风景区", "id": "63" }
  69. ]
  70. }, {
  71. "name": "交通",
  72. "id": "1",
  73. "sons": [{
  74. "name": "交通枢纽",
  75. "id": "11",
  76. "sons": [
  77. { "name": "山口、关隘", "id": "1341", "sons": "" },
  78. { "name": "锚地", "id": "2311", "sons": "" },
  79. { "name": "海港", "id": "2312", "sons": "" },
  80. { "name": "河港", "id": "2313", "sons": "" },
  81. { "name": "船闸、升船机战", "id": "2314", "sons": "" },
  82. { "name": "渡口", "id": "2315", "sons": "" },
  83. { "name": "长途汽车站", "id": "2322", "sons": "" },
  84. { "name": "火车站", "id": "1232", "sons": "" },
  85. { "name": "航空港", "id": "2341", "sons": "" }
  86. ]
  87. }, {
  88. "name": "桥梁",
  89. "id": "12",
  90. "sons": [
  91. { "name": "桥梁", "id": "2361", "sons": "" }
  92. ]
  93. }, {
  94. "name": "隧道",
  95. "id": "13",
  96. "sons": [
  97. { "name": "隧道", "id": "2362", "sons": "" }
  98. ]
  99. }, {
  100. "name": "加油站",
  101. "id": "14",
  102. "sons": [
  103. { "name": "加油站", "id": "2366", "sons": "" }
  104. ]
  105. }, {
  106. "name": "导航站",
  107. "id": "15",
  108. "sons": [
  109. { "name": "灯塔、导航站", "id": "2367", "sons": "" }
  110. ]
  111. }, {
  112. "name": "停车场",
  113. "id": "16",
  114. "sons": [
  115. { "name": "停车场", "id": "2354", "sons": "" }
  116. ]
  117. }]
  118. }, {
  119. "name": "设施",
  120. "id": "2",
  121. "sons": [{
  122. "name": "电力",
  123. "id": "21",
  124. "sons": [
  125. { "name": "电力设施", "id": "246", "sons": "" }
  126. ]
  127. }, {
  128. "name": "通信",
  129. "id": "22",
  130. "sons": [
  131. { "name": "通信设施", "id": "247", "sons": "" }
  132. ]
  133. }, {
  134. "name": "水利",
  135. "id": "23",
  136. "sons": [
  137. { "name": "井", "id": "241", "sons": "" },
  138. { "name": "蓄水区", "id": "242", "sons": "" },
  139. { "name": "排灌设施", "id": "243", "sons": "" },
  140. { "name": "堤堰", "id": "244", "sons": "" },
  141. { "name": "运河", "id": "245", "sons": "" }
  142. ]
  143. }, {
  144. "name": "其他",
  145. "id": "29",
  146. "sons": [
  147. { "name": "场", "id": "263", "sons": "" }
  148. ]
  149. }]
  150. }, {
  151. "name": "水系",
  152. "id": "3",
  153. "sons": [{
  154. "name": "海岛",
  155. "id": "31",
  156. "sons": [
  157. { "name": "海洋岛屿", "id": "115", "sons": "" }
  158. ]
  159. }, {
  160. "name": "河流",
  161. "id": "32",
  162. "sons": [
  163. { "name": "河流", "id": "121", "sons": "" }
  164. ]
  165. }, {
  166. "name": "池塘水库",
  167. "id": "33",
  168. "sons": [
  169. { "name": "湖泊", "id": "122", "sons": "" },
  170. { "name": "池塘", "id": "2421", "sons": "" },
  171. { "name": "水库", "id": "2423", "sons": "" }
  172. ]
  173. }]
  174. }, {
  175. "name": "单位",
  176. "id": "4",
  177. "sons": [{
  178. "name": "军事单位",
  179. "id": "41",
  180. "sons": [
  181. { "name": "军事区", "id": "2175", "sons": "" },
  182. { "name": "军事单位", "id": "275", "sons": "" }
  183. ]
  184. }, {
  185. "name": "机关团体",
  186. "id": "42",
  187. "sons": [
  188. { "name": "党政机关", "id": "271", "sons": "" },
  189. { "name": "民间组织", "id": "272", "sons": "" }
  190. ]
  191. }, {
  192. "name": "企事业单位",
  193. "id": "43",
  194. "sons": [
  195. { "name": "事业单位", "id": "273", "sons": "" },
  196. { "name": "企业", "id": "274", "sons": "" }
  197. ]
  198. }, {
  199. "name": "开发区",
  200. "id": "44",
  201. "sons": [
  202. { "name": "工业区、开发区", "id": "2173", "sons": "" }
  203. ]
  204. }, {
  205. "name": "边贸口岸",
  206. "id": "45",
  207. "sons": [
  208. { "name": "边贸区、口岸", "id": "2174", "sons": "" }
  209. ]
  210. }]
  211. }, {
  212. "name": "居民点",
  213. "id": "5",
  214. "sons": [{
  215. "name": "城镇",
  216. "id": "51",
  217. "sons": [
  218. { "name": "城镇居民点", "id": "221", "sons": "" }
  219. ]
  220. }, {
  221. "name": "农村",
  222. "id": "52",
  223. "sons": [
  224. { "name": "农村居民点", "id": "222", "sons": "" }
  225. ]
  226. }, {
  227. "name": "其他",
  228. "id": "59",
  229. "sons": [
  230. { "name": "工矿点", "id": "223", "sons": "" },
  231. { "name": "农、林、牧场等", "id": "224", "sons": "" },
  232. { "name": "其他", "id": "229", "sons": "" }
  233. ]
  234. }]
  235. }, {
  236. "name": "旅游",
  237. "id": "6",
  238. "sons": [{
  239. "name": "纪念地",
  240. "id": "61",
  241. "sons": [
  242. { "name": "纪念地", "id": "251", "sons": "" }
  243. ]
  244. }, {
  245. "name": "公园",
  246. "id": "62",
  247. "sons": [
  248. { "name": "公园", "id": "252", "sons": "" }
  249. ]
  250. }, {
  251. "name": "风景区",
  252. "id": "63",
  253. "sons": [
  254. { "name": "风景名胜区(点)", "id": "253", "sons": "" }
  255. ]
  256. }, {
  257. "name": "山地",
  258. "id": "64",
  259. "sons": [
  260. { "name": "山地", "id": "134", "sons": "" }
  261. ]
  262. }]
  263. }] //常用热点关键字
  264. };
  265. /**
  266. * 初始化
  267. * @type {Function}
  268. * @param options {Object}
  269. */
  270. function init() {
  271. if (!modValue.initialized) {
  272. setLayout();
  273. bindEvent();
  274. subscribe();
  275. modValue.initialized = true;
  276. modValue.markerGroup = map23DControl.group({
  277. action: 'add'
  278. });
  279. addressBaikeDb = JSON.parse(addressBaikeDb);
  280. }
  281. if($(".tools-painting").hasClass('cur')){
  282. // var r = confirm("是否离开标注并保存当前标注?");
  283. // if(r){
  284. // $(".tsAct li.save").click();
  285. // $(".modal .modal-header .close,#userDrawAddModal .form .sure").bind("click",function(){
  286. afac()
  287. // })
  288. // }
  289. } else{
  290. afac()
  291. }
  292. };
  293. function afac(){
  294. ONEMAP.C.publisher.publish({
  295. modName: 'placeSearch',
  296. }, 'tools:active');
  297. ONEMAP.D.panelMore = false;
  298. }
  299. /**
  300. * 数据合并
  301. */
  302. function initData(options) {
  303. if (typeof(options) != "undefined") {
  304. modValue.options.bounds = options.bounds || map2DViewer.map.getBounds();
  305. modValue.options.keyWord = options.keyWord || '';
  306. modValue.options.type = options.type || 'bounds';
  307. modValue.options.center = options.center || map23DData.view.center;
  308. modValue.options.dis = options.dis || null;
  309. modValue.options.pac = options.pac || 0;
  310. modValue.options.themeId = options.themeId || null;
  311. return modValue.options;
  312. }
  313. };
  314. /**
  315. * 监听事件
  316. */
  317. function subscribe() {
  318. //ONEMAP.C.publisher.subscribe(rePlaceSearch,'add3d');
  319. ONEMAP.C.publisher.subscribe(clearMarker, 'cleanMap');
  320. //ONEMAP.C.publisher.subscribe(remove, 'tools:active');
  321. };
  322. function unSubscribe() {
  323. ONEMAP.C.publisher.unSubscribe(clearMarker, 'cleanMap');
  324. //ONEMAP.C.publisher.unSubscribe(remove, 'tools:active');
  325. };
  326. function clearMarker() {
  327. map23DControl.group({
  328. action: 'cleanAll',
  329. guid: modValue.markerGroup
  330. })
  331. removeShowArea();
  332. map2DViewer.map.off('dragend zoomend', searchInViewFire);
  333. $(".category-list-wrap").empty();
  334. $(".place-list").empty();
  335. $(".page-wrap").empty();
  336. $("#searchInViewFrom").hide();
  337. $("#searchresult").hide();
  338. }
  339. function remove(options) {
  340. if (options.modName === 'placeSearch') {
  341. // if (modValue.options.type === 'pac') {
  342. // if ($(".tools-search").hasClass('cur')) {
  343. // $(".tools-search").removeClass('cur');
  344. // $("#searchInViewFrom").hide();
  345. // $("#searchresult").hide();
  346. // //clearMarker();
  347. // } else {
  348. // $(".tools-search").addClass('cur');
  349. // $("#searchInViewKey").val('关键字');
  350. // $("#searchInViewFrom").show();
  351. // $("#searchInViewFrom").css({
  352. // top:1,
  353. // })
  354. // $("#searchresult").css({
  355. // top:39
  356. // })
  357. // //$("#searchresult").show();
  358. // }
  359. // $(".tools-serchView").removeClass('cur');
  360. // } else if (modValue.options.type === 'bounds') {
  361. // if ($(".tools-serchView").hasClass('cur')) {
  362. // $(".tools-serchView").removeClass('cur');
  363. // $("#searchInViewFrom").hide();
  364. // $("#searchresult").hide();
  365. // $("#searchInViewFrom").css({
  366. // top:1,
  367. // })
  368. // $("#searchresult").css({
  369. // top:39
  370. // })
  371. // //clearMarker();
  372. // } else {
  373. // $(".tools-serchView").addClass('cur');
  374. // $("#searchInViewFrom").show();
  375. // $("#searchInViewKey").val('关键字');
  376. // $("#searchInViewFrom").css({
  377. // top:95,
  378. // })
  379. // $("#searchresult").css({
  380. // top:134
  381. // })
  382. // //$("#searchresult").show();
  383. // }
  384. // $(".tools-search").removeClass('cur');
  385. // }
  386. } else {
  387. // $(".tools-search").removeClass('cur');
  388. // $(".tools-serchView").removeClass('cur')
  389. // $("#searchInViewFrom").hide();
  390. // $("#searchresult").hide();
  391. cleanMarkerGroup();
  392. removeShowArea();
  393. //clearMarker();
  394. }
  395. };
  396. function setLayout() {
  397. $("#searchresult .cover-content").empty().html(tpcLayout);
  398. $("#placePanel .place-list-wrap").mCustomScrollbar({
  399. scrollInertia: 1000
  400. });
  401. // 海量地图库搜索结果滚动条
  402. // $("#placePanel .thematic-content").mCustomScrollbar({
  403. // scrollInertia: 1000
  404. // });
  405. };
  406. function changSearchType(type) {
  407. clearMarker();
  408. switch (type) {
  409. case 'pac':
  410. modValue.options.type = 'pac';
  411. map2DViewer.map.off('dragend zoomend', searchInViewFire);
  412. break;
  413. case 'bounds':
  414. modValue.options.type = 'bounds';
  415. //map2DViewer.map.on('dragend zoomend', searchInViewFire);
  416. }
  417. };
  418. function searchInViewFire() {
  419. setTimeout(function() {
  420. changeToBoundsSearch({
  421. keyWord: modValue.options.keyWord
  422. })
  423. // var keyWord = $('#searchInViewKey').val();
  424. // if (keyWord != '' && keyWord != '关键字') {
  425. // ONEMAP.D.user.searchKeyWord = keyWord;
  426. // changeToBoundsSearch({
  427. // keyWord: keyWord
  428. // });
  429. // }
  430. }, 600)
  431. };
  432. function globalSearchFire() {
  433. var qkeyWord = $("#searchInViewKey").val();
  434. $(".placeOther").show();
  435. modValue.options.keyWord = qkeyWord;
  436. modValue.options.type = 'pac';
  437. if (qkeyWord != '' && qkeyWord != '请输入地名关键字') {
  438. // 引入海量地图库搜索
  439. require(['modDir/atlas/atlasSearch'], function(atlasSearch) {
  440. atlasSearch.init();
  441. });
  442. // // 天气搜索结果
  443. // meteo.c.http.httpFunction(meteo.c.http.station, qkeyWord, null, function(json) {
  444. // showList(json);
  445. // })
  446. if (modValue.options.type === 'pac') {
  447. ONEMAP.D.user.searchKeyWord = qkeyWord;
  448. globalSearch({
  449. keyWord: qkeyWord
  450. });
  451. map2DViewer.map.off('dragend zoomend', searchInViewFire);
  452. } else {
  453. ONEMAP.D.user.searchKeyWord = qkeyWord;
  454. changeToBoundsSearch({ keyWord: qkeyWord });
  455. map2DViewer.map.on('dragend zoomend', searchInViewFire);
  456. }
  457. var sUrl = onemapUrlConfig.gcmsServiceUrl + '/search/global?query=' + qkeyWord + '&page=1&size=100&order=desc&sort=gcms_id';
  458. sUrl = encodeURI(sUrl);
  459. $(".gcms-search").hide();
  460. //gcms搜索
  461. $.ajax({
  462. url: sUrl,
  463. type: 'GET',
  464. dataType: 'json',
  465. success: function(data) {
  466. // console.log(data)
  467. $(".gcms-search-result-list").html("");
  468. if (data.total > 0) {
  469. $(".gcms-search").show();
  470. if ($("#gcms-search-result-list")) {
  471. $("#gcms-search-result-list").remove();
  472. }
  473. var ul = $('<ul id="gcms-search-result-list" class="panel"><h3>资源搜索结果列表</h3></ul>');
  474. $(data.data).each(function(i, el) {
  475. if (el.record) {
  476. var li = $('<li onclick="ONEMAP.M.gcmsEvents.showDetailDiy(\'' + el.record.gcms_id + '\',\'' + el.table + '\')">' + el.record.gcms_title + '</li>');
  477. li.appendTo(ul);
  478. if ($(".gcms-search-result-list li").length < 3) {
  479. li.clone().appendTo($(".gcms-search-result-list"));
  480. }
  481. }
  482. })
  483. ul.appendTo($("#sideBarBody"))
  484. } else {
  485. $(".gcms-search").hide();
  486. }
  487. }
  488. })
  489. }
  490. };
  491. // function showList(json) {
  492. // // console.log(json)
  493. // $('.meteo-search-result-list').html('');
  494. // for (var key in json) {
  495. // var name = json[key].cname ? json[key].cname : json[key].ename;
  496. // var html = "<li id='meteo-station-" + json[key].station + "'>" + name + "</li>";
  497. // $(".meteo-search-result-list").append(html);
  498. // $('#meteo-station-' + json[key].station).click(function(e) {
  499. // //if(map23DConfig.netType == 2){
  500. // meteo.c.popup.showPopup("" + e.currentTarget.id.split("-")[2], e.currentTarget.innerHTML, 0);
  501. // //}else if(map23DConfig.netType == 1){
  502. // //meteo.c.popup.showPopup("" + e.currentTarget.id.split("-")[2], e.currentTarget.innerHTML, 0,'2017-12-25 20:00:00', '2017-12-25 08:00:00');
  503. // //}
  504. // });
  505. // }
  506. // $('.meteo-search-result-list').show();
  507. // // meteo.c.popup.showPopup("station" , 'name', 0,'2017-12-25 20:00:00', '2017-12-25 08:00:00');
  508. // }
  509. function globalSearch(options) {
  510. modValue.fitBounds = true;
  511. //判断输入
  512. if (options.keyWord == '') {
  513. alert('查询关键字不能为空');
  514. return false;
  515. }
  516. if (options.keyWord.length < 2) {
  517. alert('查询关键字不允许输入单字');
  518. $('#header .h-center .close').click();
  519. return false;
  520. }
  521. if ((/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\s\"]/g).test(options.keyWord)) {
  522. alert('查询关键字只能包含英文、数字、中文');
  523. return false;
  524. }
  525. modValue.options.init_query_key = options.keyWord;
  526. getAreaInfo({ keywords: options.keyWord }, function(data) {
  527. if (data.residue_addr_name.length > 0 && (data.address[0]['area_name'].length > 0 || data.address[0]['name'].length > 0)) {
  528. //即包含匹配的区域列表又包含二次查询关键字
  529. createNameListForSearchResultHtml(data);
  530. initData({ type: 'pac', pac:'', keyWord: data.residue_addr_name });
  531. getPageResult({ page: 1,wrap:$('#searchresult .place-list') });
  532. } else if (data.residue_addr_name.length == 0 && (data.address[0]['area_name'].length > 0 || data.address[0]['name'].length > 0)) {
  533. //只包含匹配的区域列表
  534. createNameListResultHtml(data);
  535. getPageResult({ page: 1,wrap:$('#searchresult .place-list') });
  536. } else {
  537. //只包含二次查询关键字(原始关键字查询)
  538. initData({ type: 'pac', pac:'', keyWord: modValue.options.init_query_key });
  539. getPageResult({ page: 1 });
  540. }
  541. //return false;
  542. // if (data.residue_addr_name.length > 0) {
  543. // if (initData({ type: 'pac', keyWord: data.residue_addr_name })) {
  544. // //如果只返回一个参考地址
  545. // if (data.address.length == 1) {
  546. // //如果有pac 按pac查
  547. // //if(data.address[0].area_pac>0){
  548. // modValue.options.type = 'pac';
  549. // modValue.options.pac = (data.address[0].area_pac.toString()).length > 2 ? (data.address[0].area_pac.toString().substr(2, data.address[0].area_pac.toString().length - 1)) : data.address[0].area_pac;
  550. // if (modValue.options.pac.length > 7) {
  551. // modValue.options.pac = modValue.options.pac.substr(0, 7);
  552. // }
  553. // if (data.address[0].area_lat != 0 && data.address[0].area_lon != 0) {
  554. // addShowArea({
  555. // lat: data.address[0].area_lat,
  556. // lng: data.address[0].area_lon,
  557. // demand: pac2Demand(pac)
  558. // })
  559. // if (map23DData.display.map2D) {
  560. // map2DViewer.map.setView([data.address[0].area_lat, data.address[0].area_lon], getZoom({ 'pac': modValue.options.pac }));
  561. // setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  562. // } else if (map23DData.display.map3D) {
  563. // fly3DInView(data.address[0].area_lat, data.address[0].area_lon, getZoom({ 'pac': modValue.options.pac }));
  564. // }
  565. // }
  566. // getPageResult({ page: 1 });
  567. // //如果返回多个参考地址,列出参考地址
  568. // } else {
  569. // createNameListForSearchResultHtml(data);
  570. // }
  571. // }
  572. // } else {
  573. // if (data.address[0].pac > 0) {
  574. // if (initData({ keyWord: data.name })) {
  575. // if (map23DData.display.map2D) {
  576. // map2DViewer.map.setView([data.address[0].lat, data.address[0].lon], getZoom({ 'pac': data.address[0].pac.toString().substr(2, data.address[0].pac.toString().length - 1) }));
  577. // setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  578. // } else if (map23DData.display.map3D) {
  579. // fly3DInView(data.address[0].lat, data.address[0].lon, getZoom({ 'pac': data.address[0].pac.toString().substr(2, data.address[0].pac.toString().length - 1) }))
  580. // }
  581. // //ONEMAP.M.toolsBar.setSystemNote({type:'success',message:'已切换至 '+data.address[0].name+' 区域'});
  582. // modValue.placeDataResult = {
  583. // list: [{
  584. // cn: data.address[0].name,
  585. // lon: data.address[0].lon,
  586. // tc: 0,
  587. // tid: 0,
  588. // pac: 0,
  589. // lat: data.address[0].lat,
  590. // id: 0
  591. // }],
  592. // num_pages: 1,
  593. // page: 1,
  594. // per_page: 10,
  595. // total: 10,
  596. // type: 1
  597. // };
  598. // createResultHtml({ fitBounds: false });
  599. // setPlaceResultHtml();
  600. // setTimeout(function() {
  601. // modValue.markers[0].openPopup();
  602. // }, 300);
  603. // }
  604. // } else {
  605. // modValue.fitBounds = true;
  606. // if (initData({})) {
  607. // createNameListResultHtml(data);
  608. // }
  609. // return false;
  610. // }
  611. // }
  612. });
  613. };
  614. //区域尺度(scale)取值: 1: 全球、2: 大洲/大洋、3: 国家、4: 省、5: 市、6: 县
  615. function pac2Demand(pac) {
  616. switch (pac.toString().length) {
  617. case 11:
  618. return 6;
  619. break;
  620. case 9:
  621. return 5;
  622. break;
  623. case 7:
  624. return 4;
  625. break;
  626. case 5:
  627. return 3;
  628. break;
  629. case 3:
  630. return 2;
  631. break;
  632. case 0:
  633. return 1;
  634. break;
  635. }
  636. }
  637. function removeShowArea() {
  638. //移除之前的
  639. if (modValue.areaGroup.length > 0) {
  640. $.each(modValue.areaGroup, function(index, el) {
  641. map23DControl.polygon({
  642. action: 'remove',
  643. guid: el
  644. })
  645. });
  646. }
  647. modValue.areaGroup = [];
  648. }
  649. function addShowArea(options) {
  650. //移除之前的
  651. if (modValue.areaGroup.length > 0) {
  652. $.each(modValue.areaGroup, function(index, el) {
  653. map23DControl.polygon({
  654. action: 'remove',
  655. guid: el
  656. })
  657. });
  658. }
  659. //添加新的
  660. modValue.areaGroup = [];
  661. getRegionBoundary({ lat: options.lat, lng: options.lng, demand: options.demand }, function(data) {
  662. if (data) {
  663. if (data['type'] == 'Polygon') {
  664. //var altitude = [];
  665. //for(var i=0;i<data['coordinates'][0].length;i++){
  666. // altitude.push(10)
  667. //}
  668. modValue.areaGroup.push(map23DControl.polygon({
  669. action: 'add',
  670. geojson: {
  671. "type": "Feature",
  672. "properties": {
  673. title: data['name'],
  674. color: '#ff0000',
  675. weight: 1,
  676. fillColor: '#ff6600',
  677. opacity: 0.5,
  678. fillOpacity: 0.3,
  679. popupContent: '',
  680. altitudeMode:0,
  681. },
  682. "geometry": {
  683. "type": "Polygon",
  684. "coordinates": data['coordinates']
  685. }
  686. }
  687. }))
  688. }
  689. if (data['type'] == 'MultiPolygon') {
  690. $.each(data['coordinates'], function(index, el) {
  691. //var altitude = [];
  692. //for(var i=0;i<el[0].length;i++){
  693. // altitude.push(10);
  694. //}
  695. modValue.areaGroup.push(map23DControl.polygon({
  696. action: 'add',
  697. geojson: {
  698. "type": "Feature",
  699. "properties": {
  700. title: data['name'],
  701. color: '#ff0000',
  702. weight: 1,
  703. fillColor: '#ff6600',
  704. opacity: 0.5,
  705. fillOpacity: 0.3,
  706. popupContent: '',
  707. altitudeMode:0,
  708. },
  709. "geometry": {
  710. "type": "Polygon",
  711. "coordinates": el
  712. }
  713. }
  714. }))
  715. });
  716. }
  717. }
  718. })
  719. }
  720. function getPageResult(options) {
  721. cleanMarkerGroup();
  722. modValue.options.page = options.page;
  723. var poiSearch = new poiSearchF({
  724. page: modValue.options.page,
  725. pageSize: modValue.options.pageSize
  726. });
  727. ONEMAP.V.loading.load();
  728. if (modValue.options.type === 'bounds') {
  729. var min_lng = modValue.options.bounds.getSouthWest().lng;
  730. var max_lng = modValue.options.bounds.getNorthEast().lng;
  731. if (min_lng < -180) {
  732. min_lng = -180;
  733. }
  734. if (max_lng > 180) {
  735. max_lng = 180;
  736. }
  737. var bounds = {
  738. southWest: [modValue.options.bounds.getSouthWest().lat, min_lng],
  739. northEast: [modValue.options.bounds.getNorthEast().lat, max_lng]
  740. };
  741. poiSearch.getPoiByOptions({ bounds: bounds, keywords: modValue.options.keyWord },
  742. function(data) {
  743. ONEMAP.V.loading.loaded();
  744. if (data.hasOwnProperty('type')) {
  745. if (data.type == 1) {
  746. if (data.hasOwnProperty('data') && data['data'].length > 0) {
  747. data.page = data.page * 1;
  748. modValue.placeDataResult = data;
  749. createResultHtml(options);
  750. //setPlaceResultHtml();
  751. } else {
  752. if(modValue.options.type == "pac"){
  753. setNotResultHtml('没有搜索到 ' + modValue.options.keyWord + ' 的信息,请修改搜索条件。');
  754. }
  755. if(modValue.options.type == 'bounds'){
  756. setNotResultHtml('当前视野内没有搜索到 ' + modValue.options.keyWord + ' 的信息,请移动或缩放地图进行搜索。');
  757. }
  758. }
  759. } else if (data.type == 2) {
  760. data.page = data.page * 1;
  761. modValue.placeDataResult = data;
  762. createResultHtml(options);
  763. //setPlaceResultHtml();
  764. }
  765. } else {
  766. if(modValue.options.type == "pac"){
  767. setNotResultHtml('没有搜索到 ' + modValue.options.keyWord + ' 的信息,请修改搜索条件。');
  768. }
  769. if(modValue.options.type == 'bounds'){
  770. setNotResultHtml('当前视野内没有搜索到 ' + modValue.options.keyWord + ' 的信息,请移动或缩放地图进行搜索。');
  771. }
  772. }
  773. });
  774. } else if (modValue.options.type === 'theme') {
  775. var themeOptions = {
  776. rangeCenter: [modValue.options.center.lat, modValue.options.center.lng],
  777. range: modValue.options.dis
  778. };
  779. if (modValue.options.themeId || modValue.options.keyWord) {
  780. if (modValue.options.themeId) {
  781. themeOptions.themeId = modValue.options.themeId;
  782. }
  783. if (modValue.options.keyWord) {
  784. themeOptions.keywords = modValue.options.keyWord;
  785. }
  786. }
  787. poiSearch.getPoiByOptions(themeOptions, function(data) {
  788. ONEMAP.V.loading.loaded();
  789. if (data.hasOwnProperty('data') && data['data'].length > 0) {
  790. data.page = data.page * 1;
  791. modValue.placeDataResult = data;
  792. createResultHtml(options);
  793. //setPlaceResultHtml();
  794. } else {
  795. setNotResultHtml('没有搜索到相关的信息,请修改搜索条件。');
  796. }
  797. });
  798. } else if (modValue.options.type === 'pac') {
  799. var _searchKeyWord = options.hasOwnProperty('wrap')?modValue.options.init_query_key:modValue.options.keyWord;
  800. poiSearch.getPoiByOptions({ pac: modValue.options.pac, keywords: _searchKeyWord,center:map2DViewer.map.getCenter()}, function(data) {
  801. ONEMAP.V.loading.loaded();
  802. if (data.hasOwnProperty('type')) {
  803. if (data.type == 1) {
  804. if (data.hasOwnProperty('data') && data['data'].length > 0) {
  805. data.page = data.page * 1;
  806. modValue.placeDataResult = data;
  807. createResultHtml(options);
  808. //setPlaceResultHtml();
  809. } else {
  810. if(options.hasOwnProperty('wrap')){
  811. return false;
  812. }
  813. if(modValue.options.type == "pac"){
  814. setNotResultHtml('没有搜索到 ' + modValue.options.init_query_key + ' 的信息,请修改搜索条件。');
  815. }
  816. if(modValue.options.type == 'bounds'){
  817. setNotResultHtml('当前视野内没有搜索到 ' + modValue.options.init_query_key + ' 的信息,请移动或缩放地图进行搜索。');
  818. }
  819. }
  820. } else if (data.type == 2) {
  821. if(options.hasOwnProperty('wrap')){
  822. return false;
  823. }
  824. data.page = data.page * 1;
  825. modValue.placeDataResult = data;
  826. createResultHtml(options);
  827. //setPlaceResultHtml();
  828. }
  829. } else {
  830. if(options.hasOwnProperty('wrap')){
  831. return false;
  832. }
  833. if(modValue.options.type == "pac"){
  834. setNotResultHtml('没有搜索到 ' + modValue.options.init_query_key + ' 的信息,请修改搜索条件。');
  835. }
  836. if(modValue.options.type == 'bounds'){
  837. setNotResultHtml('当前视野内没有搜索到 ' + modValue.options.init_query_key + ' 的信息,请移动或缩放地图进行搜索。');
  838. }
  839. }
  840. });
  841. }
  842. };
  843. /**
  844. * 三维跳转
  845. */
  846. function fly3DInView(lat, lng, zoom) {
  847. map3DViewer.flyTo({
  848. center: {
  849. lat: lat,
  850. lng: lng
  851. },
  852. zoom: zoom,
  853. heading: 0, //摄像机平面角度 正北为0
  854. tilt: 0, //摄像机倾斜角
  855. });
  856. };
  857. /**
  858. * 构建分页数据
  859. * @type {Function}
  860. * @returns {*}
  861. * @private
  862. */
  863. function createResultHtml(options) {
  864. if(!options.hasOwnProperty('wrap')){
  865. $(".category-list-wrap").empty();
  866. }
  867. $(".place-list").empty();
  868. $(".page-wrap").empty();
  869. if (modValue.placeDataResult.type == 2) {
  870. $('<h3>查询到以下区域中包含 '+modValue.options.keyWord+'</h3>').appendTo($(".category-list-wrap"));
  871. //先判断数据到哪一个级别
  872. //列出一级
  873. var place_fi_length = 0;
  874. for (var place_fi in modValue.placeDataResult['data']) {
  875. if (ONEMAP.T.getObjNameAry(modValue.placeDataResult['data']).length > 1) {
  876. place_fi_length++;
  877. var _placeDl = $('<dl class="areaSelect fi" pid="' + modValue.placeDataResult['data'][place_fi]['pac'] + '"></dl>');
  878. var _placeDt = $('<dt><a href="javascript:void(0)">' + place_fi + '(' + modValue.placeDataResult['data'][place_fi]['count'] + ')</a></dt>');
  879. modValue.placeDataResult['data'][place_fi].area_name = place_fi;
  880. _placeDl.bind('click', { d: modValue.placeDataResult['data'][place_fi] }, function(e) {
  881. if (modValue.options.type == 'pac') {
  882. if (map23DData.display.map2D) {
  883. map2DViewer.map.setView([e.data.d.lat, e.data.d.lon], getZoom({ 'pac': e.data.d.pac }));
  884. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  885. } else if (map23DData.display.map3D) {
  886. fly3DInView(e.data.d.lat, e.data.d.lon, getZoom({ 'pac': e.data.d.pac }));
  887. }
  888. addShowArea({
  889. lat: e.data.d.lat,
  890. lng: e.data.d.lon,
  891. demand: pac2Demand('00'+e.data.d.pac)
  892. })
  893. modValue.options.pac = e.data.d.pac;
  894. setTimeout(function() {
  895. modValue.options.type = 'pac';
  896. getPageResult({ page: 1 });
  897. }, 300);
  898. } else {
  899. if (map23DData.display.map2D) {
  900. map2DViewer.map.setView([e.data.d.lat, e.data.d.lon], map23DData.view.zoom + 2);
  901. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  902. } else if (map23DData.display.map2D) {
  903. fly3DInView(e.data.d.lat, e.data.d.lon, map23DData.view.zoom + 2);
  904. }
  905. }
  906. $(".category-list-wrap").empty();
  907. });
  908. _placeDt.appendTo(_placeDl);
  909. _placeDl.appendTo($(".category-list-wrap"));
  910. }else {
  911. //列出二级
  912. var place_se_length = 0;
  913. for (var place_se in modValue.placeDataResult['data'][place_fi]['sub']) {
  914. if (ONEMAP.T.getObjNameAry(modValue.placeDataResult['data'][place_fi]['sub']).length > 1) {
  915. place_se_length++;
  916. var _placeDl_se = $('<dl class="areaSelect se" pid="' + modValue.placeDataResult['data'][place_fi]['sub'][place_se]['pac'] + '"></dl>');
  917. var _placeDt_se = $('<dt><a href="javascript:void(0)">'+place_fi + place_se + '(' + modValue.placeDataResult['data'][place_fi]['sub'][place_se]['count'] + ')</a></dt>');
  918. modValue.placeDataResult['data'][place_fi]['sub'][place_se].area_name = place_se;
  919. _placeDl_se.bind('click', { d: modValue.placeDataResult['data'][place_fi]['sub'][place_se] }, function(e) {
  920. if (modValue.options.type == 'pac') {
  921. if (map23DData.display.map2D) {
  922. map2DViewer.map.setView([e.data.d.lat, e.data.d.lon], getZoom({ 'pac': e.data.d.pac }));
  923. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  924. } else if (map23DData.display.map2D) {
  925. fly3DInView(e.data.d.lat, e.data.d.lon, getZoom({ 'pac': e.data.d.pac }));
  926. }
  927. addShowArea({
  928. lat: e.data.d.lat,
  929. lng: e.data.d.lon,
  930. demand: pac2Demand('00'+e.data.d.pac)
  931. })
  932. modValue.options.pac = e.data.d.pac;
  933. setTimeout(function() {
  934. modValue.options.type = 'pac';
  935. getPageResult({ page: 1 });
  936. }, 300);
  937. } else {
  938. if (map23DData.display.map2D) {
  939. map2DViewer.map.setView([e.data.d.lat, e.data.d.lon], map23DData.view.zoom + 2);
  940. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  941. } else if (map23DData.display.map3D) {
  942. fly3DInView(e.data.d.lat, e.data.d.lon, map23DData.view.zoom + 2);
  943. }
  944. }
  945. $(".category-list-wrap").empty();
  946. });
  947. _placeDt_se.appendTo(_placeDl_se);
  948. _placeDl_se.appendTo($(".category-list-wrap"));
  949. }else {
  950. //如果二级只有一个,列出三级
  951. if (ONEMAP.T.getObjNameAry(modValue.placeDataResult['data'][place_fi]['sub']).length == 1) {
  952. if(ONEMAP.T.getObjNameAry(modValue.placeDataResult['data'][place_fi]['sub'][place_se]['sub']).length > 0){
  953. for (var place_th in modValue.placeDataResult['data'][place_fi]['sub'][place_se]['sub']) {
  954. var _placeDl_th = $('<dl class="areaSelect th" pid="' + modValue.placeDataResult['data'][place_fi]['sub'][place_se]['sub'][place_th]['pac'] + '"></dl>');
  955. var _placeDt_th = $('<dt><a href="javascript:void(0)">'+place_fi+place_se + place_th + '(' + modValue.placeDataResult['data'][place_fi]['sub'][place_se]['sub'][place_th]['count'] + ')</a></dt>');
  956. modValue.placeDataResult['data'][place_fi]['sub'][place_se]['sub'][place_th].area_name = place_th;
  957. _placeDl_th.bind('click', { d: modValue.placeDataResult['data'][place_fi]['sub'][place_se]['sub'][place_th] }, function(e) {
  958. if (modValue.options.type == 'pac') {
  959. if (map23DData.display.map2D) {
  960. map2DViewer.map.setView([e.data.d.lat, e.data.d.lon], getZoom({ 'pac': e.data.d.pac }));
  961. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  962. } else if (map23DData.display.map3D) {
  963. fly3DInView(e.data.d.lat, e.data.d.lon, getZoom({ 'pac': e.data.d.pac }));
  964. }
  965. addShowArea({
  966. lat: e.data.d.lat,
  967. lng: e.data.d.lon,
  968. demand: pac2Demand('00'+e.data.d.pac)
  969. })
  970. modValue.options.pac = e.data.d.pac;
  971. setTimeout(function() {
  972. modValue.options.type = 'pac';
  973. getPageResult({ page: 1 });
  974. }, 300);
  975. } else {
  976. if (map23DData.display.map2D) {
  977. map2DViewer.map.setView([e.data.d.lat, e.data.d.lon], map23DData.view.zoom + 2);
  978. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  979. } else if (map23DData.display.map3D) {
  980. fly3DInView(e.data.d.lat, e.data.d.lon, map23DData.view.zoom + 2);
  981. }
  982. }
  983. $(".category-list-wrap").empty();
  984. //ONEMAP.M.toolsBar.setSystemNote({type:'success',message:'已切换至 '+e.data.d.area_name+' 区域'});
  985. });
  986. _placeDt_th.appendTo(_placeDl_th);
  987. _placeDl_th.appendTo($(".category-list-wrap"));
  988. }
  989. }else {
  990. if (ONEMAP.T.getObjNameAry(modValue.placeDataResult['data'][place_fi]['sub']).length == 1 &&
  991. ONEMAP.T.getObjNameAry(modValue.placeDataResult['data'][place_fi]['sub'][place_se]['sub']).length == 0){
  992. var goData = modValue.placeDataResult['data'][place_fi]['sub'][place_se];
  993. if (modValue.options.type == 'pac') {
  994. if (map23DData.display.map2D) {
  995. map2DViewer.map.setView([goData.lat, goData.lon], getZoom({ 'pac': goData.pac }));
  996. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  997. } else if (map23DData.display.map2D) {
  998. fly3DInView(goData.lat, goData.lon, getZoom({ 'pac': goData.pac }));
  999. }
  1000. addShowArea({
  1001. lat: goData.lat,
  1002. lng: goData.lon,
  1003. demand: pac2Demand('00'+goData.pac)
  1004. })
  1005. if(modValue.options.pac.toString().length == goData.pac.toString().length){
  1006. modValue.options.pac = goData.pac*100;
  1007. }else {
  1008. modValue.options.pac = goData.pac;
  1009. }
  1010. setTimeout(function() {
  1011. modValue.options.type = 'pac';
  1012. getPageResult({ page: 1 });
  1013. }, 300);
  1014. } else {
  1015. if (map23DData.display.map2D) {
  1016. map2DViewer.map.setView([goData.lat, goData.lon], map23DData.view.zoom + 2);
  1017. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  1018. } else if (map23DData.display.map3D) {
  1019. fly3DInView(goData.lat, goData.lon, map23DData.view.zoom + 2);
  1020. }
  1021. }
  1022. $(".category-list-wrap").empty();
  1023. }else {
  1024. place_se_length++;
  1025. var _placeDl_se = $('<dl class="areaSelect se" pid="' + modValue.placeDataResult['data'][place_fi]['sub'][place_se]['pac'] + '"></dl>');
  1026. var _placeDt_se = $('<dt><a href="javascript:void(0)">'+place_fi + place_se + '(' + modValue.placeDataResult['data'][place_fi]['sub'][place_se]['count'] + ')</a></dt>');
  1027. modValue.placeDataResult['data'][place_fi]['sub'][place_se].area_name = place_se;
  1028. _placeDl_se.bind('click', { d: modValue.placeDataResult['data'][place_fi]['sub'][place_se] }, function(e) {
  1029. if (modValue.options.type == 'pac') {
  1030. if (map23DData.display.map2D) {
  1031. map2DViewer.map.setView([e.data.d.lat, e.data.d.lon], getZoom({ 'pac': e.data.d.pac }));
  1032. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  1033. } else if (map23DData.display.map2D) {
  1034. fly3DInView(e.data.d.lat, e.data.d.lon, getZoom({ 'pac': e.data.d.pac }));
  1035. }
  1036. addShowArea({
  1037. lat: e.data.d.lat,
  1038. lng: e.data.d.lon,
  1039. demand: pac2Demand('00'+e.data.d.pac)
  1040. })
  1041. if(modValue.options.pac.toString().length == e.data.d.pac.toString().length){
  1042. modValue.options.pac = e.data.d.pac*100;
  1043. }else {
  1044. modValue.options.pac = e.data.d.pac;
  1045. }
  1046. setTimeout(function() {
  1047. modValue.options.type = 'pac';
  1048. getPageResult({ page: 1 });
  1049. }, 300);
  1050. } else {
  1051. if (map23DData.display.map2D) {
  1052. map2DViewer.map.setView([e.data.d.lat, e.data.d.lon], map23DData.view.zoom + 2);
  1053. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  1054. } else if (map23DData.display.map3D) {
  1055. fly3DInView(e.data.d.lat, e.data.d.lon, map23DData.view.zoom + 2);
  1056. }
  1057. }
  1058. $(".category-list-wrap").empty();
  1059. });
  1060. _placeDt_se.appendTo(_placeDl_se);
  1061. _placeDl_se.appendTo($(".category-list-wrap"));
  1062. }
  1063. }
  1064. }
  1065. }
  1066. }
  1067. }
  1068. }
  1069. } else {
  1070. var _searchKeyWord = options.hasOwnProperty('wrap')?modValue.options.init_query_key:modValue.options.keyWord;
  1071. if(modValue.options.type == 'bounds'){
  1072. $('<h3>视野内查询到以下相关 '+_searchKeyWord+' 地名信息</h3>').appendTo($("#placePanel .place-list"));
  1073. //根据视野内范围过滤视野外的数据
  1074. for (var bi = 0, bl = modValue.placeDataResult.data.length; bi < bl; bi++) {
  1075. var placeb = modValue.placeDataResult.data[bi];
  1076. if(!modValue.options.bounds.contains(L.latLng(placeb.lat, placeb.lon))){
  1077. delete modValue.placeDataResult.data[bi];
  1078. }
  1079. }
  1080. }else if(modValue.options.type == 'pac'){
  1081. $('<h3>查询到以下相关 '+_searchKeyWord+' 地名信息</h3>').appendTo($("#placePanel .place-list"));
  1082. }
  1083. for (var i = 0, l = modValue.placeDataResult.data.length; i < l; i++) {
  1084. var place = modValue.placeDataResult.data[i];
  1085. place.pnum = i;
  1086. var nLatlng = L.Util.formatHMS([place.lat, place.lon]);
  1087. var _placeDl = $('<dl id="plm' + place.id + '"></dl>');
  1088. var _placeDt = $('<dt><i class="p' + (i + 1) + '"><img src="../images/layout/marker-icon' + (i + 1) + '.png" /></i><a href="javascript:void(0)">' + place.cn + '</a></dt>');
  1089. var _placeDd = $('<dd><p class="area"></p>' +
  1090. '<p class="latlng">' + nLatlng.lng + ' , ' + nLatlng.lat + '</p></dd>');
  1091. fixAreaRegByPac(place.pac, _placeDd);
  1092. _placeDl.bind('click', { d: place }, function(e) {
  1093. if (map23DData.display.map2D) {
  1094. modValue.markers[e.data.d.pnum].setZIndexOffset((new Date()).getTime());
  1095. modValue.markers[e.data.d.pnum].openPopup();
  1096. }
  1097. //var zoomTo = ((map23DData.view.zoom>14)?map23DData.view.zoom:14);
  1098. removeShowArea();
  1099. if (map23DData.display.map2D) {
  1100. map2DViewer.map.setView([e.data.d.lat, e.data.d.lon], e.data.d.l);
  1101. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  1102. } else if (map23DData.display.map3D) {
  1103. fly3DInView(e.data.d.lat, e.data.d.lon, e.data.d.l);
  1104. }
  1105. $("#placePanel .place-list .cur").removeClass("cur");
  1106. $(this).addClass("cur");
  1107. });
  1108. _placeDt.appendTo(_placeDl);
  1109. // if (place.pac) {
  1110. // if (addressBaikeDb[place.pac]) {
  1111. // var _bakeDd = $('<a class="baike" bid="' + place.pac + '">地名百科</a>');
  1112. // _bakeDd.bind('click', function() {
  1113. // var title = $(this).prev().html();
  1114. // var bid = $(this).attr("bid");
  1115. // require(['modDir/tools/toolAddressBaike'], function(toolAddressBaike) {
  1116. // toolAddressBaike.init({
  1117. // title: title,
  1118. // bid: bid
  1119. // });
  1120. // });
  1121. // })
  1122. // _bakeDd.appendTo(_placeDt);
  1123. // }
  1124. // }
  1125. _placeDd.appendTo(_placeDl);
  1126. _placeDl.appendTo($(".place-list"));
  1127. markerToMap(place);
  1128. }
  1129. if (modValue.fitBounds && modValue.placeDataResult.data.length > 1) {
  1130. if (map23DData.display.map2D) {
  1131. map2DViewer.map.fitBounds(map2DViewer.groups[modValue.markerGroup].getBounds(), { 'paddingTopLeft': [100, 100], 'paddingBottomRight': [100, 100],'maxZoom':15 });
  1132. } else if (map23DData.display.map3D) {
  1133. }
  1134. }
  1135. var countPages = modValue.placeDataResult.num_pages;
  1136. if (countPages == 0) {
  1137. countPages = 1;
  1138. }
  1139. modValue.pageJump = $('<div id="placeSearchPageJump" class="count"><span>第</span><input class="page_num input input-small" value="' + modValue.placeDataResult.page + '" type="text" /><span>/' + countPages + '页</span></div>');
  1140. // modValue.pageJump.appendTo($(".page-wrap"));
  1141. //$("#searchresult .page-wrap").show();
  1142. modValue.pj = '<div id="placeSearchPageJump" class="count"><input class="page_num input input-small" value="' + modValue.placeDataResult.page + '" type="text" /><span>/' + countPages + '</span></div>'
  1143. var pageHtmlBtnGroup = $('<div class="btn-group" style="width:315px"></div>').appendTo($(".page-wrap"));
  1144. if (modValue.placeDataResult.per_page < modValue.placeDataResult.total) {
  1145. if (modValue.placeDataResult.page == 1) {
  1146. var abtnNext = $(modValue.pj + '<button type="button" title="下一页 >" class="btn btn2 btn-small next" pid=' + (modValue.placeDataResult.page + 1) + '>下一页 ></button>');
  1147. pageHtmlBtnGroup.append(abtnNext);
  1148. } else if (countPages == modValue.placeDataResult.page && modValue.placeDataResult.total > modValue.placeDataResult.per_page) {
  1149. var abtnPrev = $('<button type="button" title="< 上一页" class="btn btn2 btn-small prev" pid=' + (modValue.placeDataResult.page - 1) + '>< 上一页</button>' + modValue.pj);
  1150. pageHtmlBtnGroup.append(abtnPrev);
  1151. } else {
  1152. var abtnPrev = $('<button type="button" title="< 上一页" class="btn btn2 btn-small prev" pid=' + (modValue.placeDataResult.page - 1) + '>< 上一页</button>' + modValue.pj);
  1153. var abtnNext = $('<button type="button" title="下一页 >" class="btn btn2 btn-small next" pid=' + (modValue.placeDataResult.page + 1) + '>下一页 ></button>');
  1154. pageHtmlBtnGroup.append(abtnPrev).append(abtnNext);
  1155. }
  1156. $("#searchresult .page-wrap").show();
  1157. } else {
  1158. $("#searchresult .page-wrap").hide();
  1159. }
  1160. $("#placePanel .page-wrap .btn").bind('click', function() {
  1161. if(options.hasOwnProperty('wrap')){
  1162. getPageResult({ page: $(this).attr("pid"),wrap:options.wrap });
  1163. }else {
  1164. getPageResult({ page: $(this).attr("pid") });
  1165. }
  1166. });
  1167. $("#placeSearchPageJump .page_num").bind('keydown', function(e) {
  1168. if (e.keyCode === 13) {
  1169. var pageJump = parseInt($("#placeSearchPageJump .page_num").val());
  1170. if (!pageJump || pageJump > countPages) {
  1171. return;
  1172. } else {
  1173. if(options.hasOwnProperty('wrap')){
  1174. getPageResult({ page: parseInt(pageJump),wrap:options.wrap });
  1175. }else {
  1176. getPageResult({ page: parseInt(pageJump) });
  1177. }
  1178. }
  1179. }
  1180. });
  1181. //结果数据大于20条 提示视野内搜索
  1182. if (modValue.placeDataResult.total > 20) {
  1183. if (!(modValue.options.type == 'bounds')) {
  1184. $(".boundsSearchLink").empty();
  1185. $("#placePanel .boundsSearchLink").show();
  1186. $('<div>查询到的结果过多,您可以在当前视野内查询 <a> '+_searchKeyWord+' </a></div>').appendTo($(".boundsSearchLink"));
  1187. $("#placePanel .boundsSearchLink a").bind('click', function() {
  1188. $("#placePanel .boundsSearchLink").hide();
  1189. fastBoundsSearch({
  1190. keyWord:_searchKeyWord
  1191. });
  1192. });
  1193. }
  1194. } else {
  1195. $("#placePanel .boundsSearchLink").hide();
  1196. }
  1197. }
  1198. $("#placePanel .place-list-wrap").mCustomScrollbar('update');
  1199. };
  1200. /**
  1201. * 无结果列表
  1202. * @type {Function}
  1203. * @param notText {String} 无结果说明文字
  1204. * @returns {*}
  1205. * @private
  1206. */
  1207. function setNotResultHtml(notText) {
  1208. $(".category-list-wrap").empty();
  1209. $(".place-list").empty();
  1210. $(".page-wrap").empty();
  1211. $('<p class="not-result">' + notText + '</p>').appendTo($(".place-list"));
  1212. };
  1213. /**
  1214. * 快速当前区域查询
  1215. */
  1216. function fastBoundsSearch(options) {
  1217. if(options.hasOwnProperty('keyWord')){
  1218. var keyWord = options.keyWord;
  1219. }else {
  1220. var keyWord = $('#searchInViewKey').val();
  1221. }
  1222. ONEMAP.D.user.searchKeyWord = keyWord;
  1223. changeToBoundsSearch({ keyWord: keyWord });
  1224. map2DViewer.map.on('dragend zoomend', searchInViewFire);
  1225. };
  1226. /**
  1227. * 快速搜索
  1228. * [fastSearch description]
  1229. * @return {[type]} [description]
  1230. */
  1231. function fastSearch() {
  1232. var poiSearch = new poiSearchF({
  1233. page: modValue.options.page,
  1234. pageSize: modValue.options.pageSize
  1235. });
  1236. poiSearch.getPoiByOptions({ keywords: modValue.options.init_query_key },
  1237. function(data) {
  1238. ONEMAP.V.loading.loaded();
  1239. if (data.hasOwnProperty('type')) {
  1240. if (data.type == 1) {
  1241. if (data.hasOwnProperty('data') && data['data'].length > 0) {
  1242. data.page = data.page * 1;
  1243. modValue.placeDataResult = data;
  1244. createResultHtml({ page: 1 });
  1245. //setPlaceResultHtml();
  1246. } else {
  1247. if(modValue.options.type == "pac"){
  1248. setNotResultHtml('没有搜索到 ' + modValue.options.init_query_key + ' 的信息,请修改搜索条件。');
  1249. }
  1250. if(modValue.options.type == 'bounds'){
  1251. setNotResultHtml('当前视野内没有搜索到 ' + modValue.options.init_query_key + ' 的信息,请移动或缩放地图进行搜索。');
  1252. }
  1253. }
  1254. } else if (data.type == 2) {
  1255. data.page = data.page * 1;
  1256. modValue.placeDataResult = data;
  1257. createResultHtml({ page: 1 });
  1258. //setPlaceResultHtml();
  1259. }
  1260. } else {
  1261. if(modValue.options.type == "pac"){
  1262. setNotResultHtml('没有搜索到 ' + modValue.options.init_query_key + ' 的信息,请修改搜索条件。');
  1263. }
  1264. if(modValue.options.type == 'bounds'){
  1265. setNotResultHtml('当前视野内没有搜索到 ' + modValue.options.init_query_key + ' 的信息,请移动或缩放地图进行搜索。');
  1266. }
  1267. }
  1268. });
  1269. };
  1270. /**
  1271. * 创建getAreaName结果二次查询列表数据
  1272. * @param {[type]} options [description]
  1273. * @return {[type]} [description]
  1274. */
  1275. function createNameListForSearchResultHtml(options) {
  1276. $(".category-list-wrap").empty();
  1277. $("#searchresult .page-wrap").hide();
  1278. $(".place-list").empty();
  1279. $(".page-wrap").empty();
  1280. $(".fastSearchLink").empty();
  1281. //$("#placePanel .fastSearchLink").show();
  1282. // $('<div>您可以直接查询 <a>' + modValue.options.init_query_key + '</a></div>').appendTo($(".fastSearchLink"));
  1283. // $("#placePanel .fastSearchLink a").bind('click', function() {
  1284. // $("#placePanel .fastSearchLink").hide();
  1285. // fastSearch();
  1286. // });
  1287. $('<h3>您可以选择以下区域进行查询:</h3>').appendTo($(".category-list-wrap"));
  1288. for (var i = 0, l = options.address.length; i < l; i++) {
  1289. var place = options.address[i];
  1290. place.pnum = i;
  1291. var nLatlng = L.Util.formatHMS([place.area_lat, place.area_lon]);
  1292. var _placeDl = $('<dl class="areaSelect fi" id="plm' + place.pnum + '"></dl>');
  1293. var _placeDt = $('<dt><a>' + place.area_name + '</a> <span class="area"></span></dt>');
  1294. fixAreaRegByPac(place.area_pac, _placeDt)
  1295. _placeDl.bind('click', { d: place }, function(e) {
  1296. $("#placePanel .fastSearchLink").hide();
  1297. $("#placePanel .place-list .cur").removeClass("cur");
  1298. $(this).addClass("cur");
  1299. addShowArea({
  1300. lat: e.data.d.area_lat,
  1301. lng: e.data.d.area_lon,
  1302. demand: pac2Demand(e.data.d.area_pac)
  1303. })
  1304. modValue.options.type = 'pac';
  1305. modValue.options.pac = (e.data.d.area_pac.toString()).length > 2 ? (e.data.d.area_pac.toString().substr(2, e.data.d.area_pac.toString().length - 1)) : e.data.d.area_pac;
  1306. if (modValue.options.pac.length > 7) {
  1307. modValue.options.pac = modValue.options.pac.substr(0, 7);
  1308. }
  1309. if (map23DData.display.map2D) {
  1310. map2DViewer.map.setView([e.data.d.area_lat, e.data.d.area_lon], getZoom({ 'pac': modValue.options.pac }));
  1311. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  1312. } else if (map23DData.display.map3D) {
  1313. fly3DInView(e.data.d.area_lat, e.data.d.area_lon, getZoom({ 'pac': modValue.options.pac }));
  1314. }
  1315. getPageResult({ page: 1 });
  1316. });
  1317. _placeDt.appendTo(_placeDl);
  1318. _placeDl.appendTo($(".category-list-wrap"));
  1319. }
  1320. };
  1321. /**
  1322. * 填充侧栏html列表
  1323. * @type {Function}
  1324. * @returns {*}
  1325. * @private
  1326. */
  1327. function setPlaceResultHtml(options) {
  1328. $("#placePanel .page-wrap .btn").bind('click', function() {
  1329. if(options.hasOwnProperty('wrap')){
  1330. getPageResult({ page: $(this).attr("pid"),wrap:options.wrap });
  1331. }else {
  1332. getPageResult({ page: $(this).attr("pid") });
  1333. }
  1334. });
  1335. };
  1336. function addPreZero(num) {
  1337. var t = (num + '').length,
  1338. s = '';
  1339. for (var i = 0; i < 11 - t; i++) {
  1340. s += '0';
  1341. }
  1342. return num + s;
  1343. }
  1344. /**
  1345. * 构建分页数据 区域列表最终结果显示
  1346. * @type {Function}
  1347. * @returns {*}
  1348. * @private
  1349. */
  1350. function createNameListResultHtml(options) {
  1351. $(".category-list-wrap").empty();
  1352. // $(".place-list").empty();
  1353. // $(".page-wrap").empty();
  1354. $('<h3>查询到以下相关区域信息</h3>').appendTo($(".category-list-wrap"));
  1355. for (var i = 0, l = options.address.length; i < l; i++) {
  1356. var place = options.address[i];
  1357. place.pnum = i+100;
  1358. var nLatlng = L.Util.formatHMS([place.area_lat, place.area_lon]);
  1359. var _placeDl = $('<dl id="plm' + place.pnum + '"></dl>');
  1360. var _placeDt = $('<dt><i class="p' + (i + 1) + '"><img src="../images/layout/marker-icon' + (i + 1) + '.png" /></i><a>' + place.area_name + '</a></dt>');
  1361. var _placeDd = $('<dd><p class="area"></p>' +
  1362. '<p class="latlng">' + nLatlng.lng + ' , ' + nLatlng.lat + '</p></dd>');
  1363. fixAreaRegByPac(place.area_pac, _placeDd);
  1364. _placeDl.bind('click', { d: place }, function(e) {
  1365. addShowArea({
  1366. lat: e.data.d.area_lat,
  1367. lng: e.data.d.area_lon,
  1368. demand: pac2Demand(e.data.d.area_pac)
  1369. })
  1370. $.each(map23DData.markers, function(i, t) {
  1371. if (t.pnum === e.data.d.pnum) {
  1372. map23DControl.marker({
  1373. action: 'remove',
  1374. guid: i
  1375. })
  1376. delete modValue.markers[e.data.d.pnum];
  1377. }
  1378. })
  1379. markerToMap({
  1380. lat: e.data.d.area_lat,
  1381. lon: e.data.d.area_lon,
  1382. id: e.data.d.pnum,
  1383. cn: e.data.d.area_name,
  1384. pnum: e.data.d.pnum
  1385. });
  1386. if (map23DData.display.map2D) {
  1387. modValue.markers[e.data.d.pnum].setZIndexOffset((new Date()).getTime());
  1388. modValue.markers[e.data.d.pnum].openPopup();
  1389. }
  1390. var pac = (e.data.d.area_pac.toString()).length > 2 ? (e.data.d.area_pac.toString().substr(2, e.data.d.area_pac.toString().length - 1)) : e.data.d.area_pac;
  1391. // if (pac.length > 7) {
  1392. // pac = pac.substr(0, 7);
  1393. // }
  1394. var zoomTo = getZoom({ 'pac': pac });
  1395. if (map23DData.display.map2D) {
  1396. map2DViewer.map.setView([e.data.d.area_lat, e.data.d.area_lon], zoomTo);
  1397. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  1398. } else if (map23DData.display.map3D) {
  1399. fly3DInView(e.data.d.area_lat, e.data.d.area_lon, zoomTo);
  1400. }
  1401. $("#placePanel .category-list-wrap .cur").removeClass("cur");
  1402. $(this).addClass("cur");
  1403. });
  1404. _placeDt.appendTo(_placeDl);
  1405. _placeDd.appendTo(_placeDl);
  1406. var _area_pac = addPreZero(place.area_pac);
  1407. if (_area_pac) {
  1408. if (addressBaikeDb[_area_pac]) {
  1409. var _bakeDd = $('<a class="baike" bid="' + _area_pac + '">地名百科</a>');
  1410. _bakeDd.bind('click', function() {
  1411. var title = $(this).prev().html();
  1412. var bid = $(this).attr("bid");
  1413. require(['modDir/tools/toolAddressBaike'], function(toolAddressBaike) {
  1414. toolAddressBaike.init({
  1415. title: title,
  1416. bid: bid
  1417. });
  1418. });
  1419. })
  1420. //_bakeDd.appendTo(_placeDt);
  1421. }
  1422. }
  1423. _placeDl.appendTo($(".category-list-wrap"));
  1424. markerToMap({
  1425. lat: place.area_lat,
  1426. lon: place.area_lon,
  1427. id: place.pnum,
  1428. cn: place.area_name,
  1429. pnum: place.pnum
  1430. });
  1431. }
  1432. if (modValue.fitBounds && options.address.length > 1) {
  1433. if (map23DData.display.map2D) {
  1434. map2DViewer.map.fitBounds(map2DViewer.groups[modValue.markerGroup].getBounds(), { 'paddingTopLeft': [100, 100], 'paddingBottomRight': [100, 100],'maxZoom':15 });
  1435. }
  1436. } else {
  1437. var pac = (options.address[0].area_pac.toString()).length > 2 ? (options.address[0].area_pac.toString().substr(2, options.address[0].area_pac.toString().length - 1)) : options.address[0].area_pac;
  1438. if (pac.length > 7) {
  1439. pac = pac.substr(0, 7);
  1440. }
  1441. var zoomTo = getZoom({ 'pac': pac });
  1442. if (map23DData.display.map2D) {
  1443. //map2DViewer.map.setView([options.address[0].area_lat, options.address[0].area_lon], zoomTo);
  1444. setTimeout(function() { ONEMAP.C.publisher.publish('placeSearch', 'mapChange'); }, 200);
  1445. } else if (map23DData.display.map3D) {
  1446. fly3DInView(options.address[0].area_lat, options.address[0].area_lon, zoomTo);
  1447. }
  1448. }
  1449. };
  1450. /**
  1451. * 添加标记到地图
  1452. * @type {Function}
  1453. * @param obj {Object} marker对象
  1454. * @private
  1455. */
  1456. function markerToMap(obj) {
  1457. var markerObj = {
  1458. latlng: [obj.lat, obj.lon],
  1459. name: obj.cn,
  1460. pguid: obj.id,
  1461. pnum: obj.pnum
  1462. };
  1463. createMarker(markerObj);
  1464. };
  1465. /**
  1466. * 创建冒泡窗
  1467. */
  1468. function creatPopupHtml(options) {
  1469. var popupHtml = '<div class="popup_html mini">' +
  1470. ' <div class="popup-lt"></div>' +
  1471. ' <div class="popup-lb"></div>' +
  1472. ' <div class="popup-rt"></div>' +
  1473. ' <div class="popup-rb"></div>' +
  1474. ' <div class="popup-ct" style="text-indent:15px;line-height:48px">' + options.name +
  1475. ' </div>' +
  1476. ' <div class="popup-cb" style="padding-bottom:20px;color:#666666 !important">' + options.content + '</div>' +
  1477. '</div>'
  1478. return popupHtml;
  1479. }
  1480. /**
  1481. * 创建地图标记
  1482. * @type {Function}
  1483. * @param obj {Object} marker
  1484. * @returns {*}
  1485. * @private
  1486. */
  1487. function createMarker(obj) {
  1488. if (!modValue.initialized) {
  1489. init();
  1490. modValue.initialized = true;
  1491. // ONEMAP.C.publisher.publish({
  1492. // modName: 'userPoint',
  1493. // }, 'tools:active');
  1494. }
  1495. var markerPoup = '<div class="placeInfo">' +
  1496. '<div class="op text-right">设为:' +
  1497. '<a id="placeSearchPointFrom" href="javascript:ONEMAP.M.placeSearch.setDirections(\'' + obj.pnum + '\',\'start\')">起点</a> | ' +
  1498. '<a id="placeSearchPointFrom" href="javascript:ONEMAP.M.placeSearch.setDirections(\'' + obj.pnum + '\',\'across\')">途经点</a> | ' +
  1499. //'<a id="placeSearchPointFrom" href="javascript:ONEMAP.M.placeSearch.setDirections(\''+obj.pnum+'\',\'avoid\')">规避点</a> | ' +
  1500. '<a id="placeSearchPointGoTo" href="javascript:ONEMAP.M.placeSearch.setDirections(\'' + obj.pnum + '\',\'stop\')">终点</a></div>' +
  1501. '</div>';
  1502. var options_popup = {
  1503. name: obj.name,
  1504. content: markerPoup
  1505. }
  1506. markerPoup = creatPopupHtml(options_popup);
  1507. var markerId = map23DControl.marker({
  1508. action: 'add',
  1509. groupId: modValue.markerGroup,
  1510. pnum: obj.pnum,
  1511. objData: obj,
  1512. geojson: {
  1513. "properties": {
  1514. //iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/marker-icon.png', //+(obj.pnum+1)+'
  1515. iconUrl:map23DConfig.map23DAssetsUrl+'/images/layout/marker-icon'+(obj.pnum+1)+'.png',
  1516. iconSize: [25, 41],
  1517. iconAnchor: [13, 41],
  1518. popupAnchor: [0, -39]
  1519. },
  1520. "geometry": {
  1521. "type": "Point",
  1522. "coordinates": [obj.latlng[1], obj.latlng[0]]
  1523. }
  1524. }
  1525. });
  1526. modValue.markers[obj.pnum] = map2DViewer.markers[markerId];
  1527. map2DViewer.markers[markerId].bindPopup(markerPoup, {
  1528. closeButton: false,
  1529. maxWidth: 200,
  1530. minWidth: 200,
  1531. title: obj.name
  1532. });
  1533. map2DViewer.markers[markerId].on("mouseover", function() {
  1534. this.setZIndexOffset((new Date()).getTime());
  1535. this.openPopup();
  1536. $('#placePanel .place-list .cur').removeClass('cur');
  1537. $('#plm' + this.pguid).addClass('cur');
  1538. });
  1539. // map3DViewer.label({
  1540. // action: 'update',
  1541. // guid: markerId,
  1542. // featureType: 'marker',
  1543. // label: {
  1544. // text: obj.name, //标牌内容
  1545. // textColor: '#ffffff', //标牌文字颜色
  1546. // lineColor: '#ff0000', //标牌引线及边框颜色
  1547. // background: '#FF0000', //标牌背景颜色
  1548. // lineTop: 10, //标牌偏移值
  1549. // lineLeft: 100 //标牌偏移值
  1550. // }
  1551. // })
  1552. };
  1553. function setFav(num) {
  1554. //判断是否登录,没有登录进行提示
  1555. if (!ONEMAP.D.isLoad) {
  1556. ONEMAP.C.publisher.publish({
  1557. type: 'warning',
  1558. message: '请登录后使用!'
  1559. }, 'noteBar::add');
  1560. return false;
  1561. }
  1562. var marker = modValue.markers[num];
  1563. var markerData = map23DData.markers[marker.guid]
  1564. var objData = {
  1565. latlng: [marker.getLatLng().lng, marker.getLatLng().lat],
  1566. name: markerData.objData.name,
  1567. obj: markerData.objData
  1568. }
  1569. require(['modDir/user/userPoint'], function(userPoint) {
  1570. userPoint.addPoint(objData);
  1571. })
  1572. };
  1573. function setDirections(pguid, type) {
  1574. switch (type) {
  1575. case 'start':
  1576. var marker = modValue.markers[pguid];
  1577. setDirectionsPoint(marker.getLatLng().lat, marker.getLatLng().lng, 'start', marker.dirName);
  1578. break;
  1579. case 'across':
  1580. var marker = modValue.markers[pguid];
  1581. setDirectionsPoint(marker.getLatLng().lat, marker.getLatLng().lng, 'across', marker.dirName);
  1582. break;
  1583. case 'avoid':
  1584. var marker = modValue.markers[pguid];
  1585. setDirectionsPoint(marker.getLatLng().lat, marker.getLatLng().lng, 'avoid', marker.dirName);
  1586. break;
  1587. case 'stop':
  1588. var marker = modValue.markers[pguid];
  1589. setDirectionsPoint(marker.getLatLng().lat, marker.getLatLng().lng, 'stop', marker.dirName);
  1590. break;
  1591. }
  1592. };
  1593. /**
  1594. * 设置起始点
  1595. * @type {Function}
  1596. * @param _lat {String} 纬度
  1597. * @param _lng {String} 经度
  1598. * @param _type {String} 类型
  1599. * @private
  1600. */
  1601. function setDirectionsPoint(_lat, _lng, _type, _name) {
  1602. switch (_type) {
  1603. case "start":
  1604. require(['modDir/tools/toolRouteSearch'], function(toolRouteSearch) {
  1605. toolRouteSearch.setStartPoint(new L.LatLng(_lat, _lng), _name);
  1606. });
  1607. break;
  1608. case "across":
  1609. require(['modDir/tools/toolRouteSearch'], function(toolRouteSearch) {
  1610. toolRouteSearch.setAcrossPoint(new L.LatLng(_lat, _lng), _name);
  1611. });
  1612. break;
  1613. case "avoid":
  1614. require(['modDir/tools/toolRouteSearch'], function(toolRouteSearch) {
  1615. toolRouteSearch.setAvoidPoint(new L.LatLng(_lat, _lng), _name);
  1616. });
  1617. break;
  1618. case "stop":
  1619. require(['modDir/tools/toolRouteSearch'], function(toolRouteSearch) {
  1620. toolRouteSearch.setStopPoint(new L.LatLng(_lat, _lng), _name);
  1621. });
  1622. break;
  1623. }
  1624. };
  1625. /**
  1626. * 清除搜索结果
  1627. * @return {[type]} [description]
  1628. */
  1629. function clearSearch() {
  1630. cleanMarkerGroup();
  1631. try {
  1632. $(".category-list-wrap").empty();
  1633. $(".place-list").empty();
  1634. $(".page-wrap").empty();
  1635. } catch (e) {}
  1636. };
  1637. /**
  1638. * 根据pac的长度返回对应zoom 不包含大洋、大洲
  1639. * @param {[type]} options [description]
  1640. * @return {[type]} [description]
  1641. */
  1642. function getZoom(options) {
  1643. var zhixiashi = [15611, 15612, 15631, 15650, 15681, 15682];
  1644. //直辖市判断
  1645. if (zhixiashi.indexOf(parseInt(options.pac)) != -1) {
  1646. return 8;
  1647. }
  1648. switch (options.pac.toString().length) {
  1649. case 3: //国家
  1650. return 4;
  1651. case 5: //省
  1652. return 6;
  1653. case 7: //市
  1654. return 8;
  1655. case 9: //县
  1656. return 10;
  1657. }
  1658. return 12;
  1659. };
  1660. /**
  1661. * 菜单 获取地名
  1662. * @type {Function}
  1663. * @param latlng {Object} 坐标
  1664. * @param abc {Object} 容器
  1665. * @param zoom {Int} 缩放等级
  1666. * @private
  1667. */
  1668. function getPlaceName(latlng, abc, zoom) {
  1669. var addressSearch = new addressSearchF();
  1670. addressSearch.getAddressInfo({ zoom: (zoom ? zoom : 8), latLng: [latlng.lat, latlng.lng] }, function(data) {
  1671. ONEMAP.V.loading.loaded();
  1672. abc.find('.address').empty().append(data.data.region);
  1673. $("#placePanel .place-list-wrap").mCustomScrollbar('update');
  1674. });
  1675. };
  1676. /**
  1677. * 菜单 获取pac所属区域
  1678. * @type {Function}
  1679. * @private
  1680. */
  1681. function fixAreaRegByPac(pac, wrap) {
  1682. getPacRegionInfo({ pac: pac }, function(data) {
  1683. ONEMAP.V.loading.loaded();
  1684. wrap.find('.area').empty().append(data.name_continent + data.name_country + data.name_province + data.name_prefecture + data.name_county);
  1685. })
  1686. };
  1687. function clearContextMenuMarker() {
  1688. $.each(map2DViewer.markers, function(i, t) {
  1689. map2DViewer.marker({
  1690. action: 'remove',
  1691. guid: i
  1692. })
  1693. });
  1694. };
  1695. /**
  1696. * 地图周边搜索
  1697. */
  1698. function rightClickPopup(center) {
  1699. if (modValue.searchCircle) {
  1700. cleanCricle();
  1701. }
  1702. if (!modValue.initialized) {
  1703. setLayout();
  1704. }
  1705. cleanMarkerGroup();
  1706. // ONEMAP.C.publisher.publish({modName: 'clickPlaceSearch',
  1707. // }, 'tools:active');
  1708. ONEMAP.C.publisher.subscribe(clearContextMenuMarker, 'cleanMap');
  1709. modValue.fitBounds = false;
  1710. modValue.options.center = center;
  1711. if (typeof(modValue.searchPoup) != 'null' || typeof(modValue.searchCircle) != 'null') {
  1712. cleanRightClickPopup();
  1713. }
  1714. //dis是范围等级,对应的公里数:(dis*2+1)*5
  1715. var form = '<div id="rightClickSearchForm">' +
  1716. '<div class="s-form"><input type="text" class="input" id="rightClickSearchForm-keyWord"><button class="btn btn2" type="button">搜索</button></div>' +
  1717. '<div class="s-select"><span>范围选择:</span><select class="select" id="rightClickSearchForm-select">' +
  1718. '<option selected value="0">5公里内</option>' +
  1719. '<option value="1">15公里内</option>' +
  1720. '<option value="2">25公里内</option>' +
  1721. '<option value="3">35公里内</option>' +
  1722. '<option value="4">45公里内</option>' +
  1723. '<option value="5">55公里内</option>' +
  1724. '<option value="6">65公里内</option>' +
  1725. '<option value="7">75公里内</option>' +
  1726. '<option value="8">85公里内</option>' +
  1727. '</select></div>' +
  1728. '<div class="s-hot-point">' +
  1729. '<div class="s-hot-point-select">' +
  1730. '</div>' +
  1731. '<ul id="placeSearchRoundThemeList">' +
  1732. '<li><a href="javascript:ONEMAP.M.placeSearch.findSurround(11)" hid="11">交通枢纽</a></li>' +
  1733. '<li><a href="javascript:ONEMAP.M.placeSearch.findSurround(14)" hid="14">加油站</a></li>' +
  1734. '<li><a href="javascript:ONEMAP.M.placeSearch.findSurround(16)" hid="16">停车场</a></li>' +
  1735. '<li><a href="javascript:ONEMAP.M.placeSearch.findSurround(12)" hid="12">桥梁</a></li>' +
  1736. '<li><a href="javascript:ONEMAP.M.placeSearch.findSurround(51)" hid="51">城镇</a></li>' +
  1737. '<li><a href="javascript:ONEMAP.M.placeSearch.findSurround(42)" hid="42">机关团体</a></li>' +
  1738. '<li><a href="javascript:ONEMAP.M.placeSearch.findSurround(43)" hid="43">企事业单位</a></li>' +
  1739. '<li><a href="javascript:ONEMAP.M.placeSearch.findSurround(63)" hid="63">风景区</a></li>' +
  1740. '</ul>' +
  1741. '</div>' +
  1742. '</div>';
  1743. var options_popup = {
  1744. name: '周边搜索',
  1745. content: form
  1746. }
  1747. form = creatPopupHtml(options_popup);
  1748. modValue.searchPoup = new L.Popup({ maxWidth: 300 });
  1749. modValue.searchPoup.setLatLng(center)
  1750. .setContent(form)
  1751. .openOn(map2DViewer.map);
  1752. drawCircle(center, 5000);
  1753. setMoreSurround();
  1754. modValue.options.themeId = null;
  1755. modValue.options.keyWord = '';
  1756. bingClickEvents();
  1757. map2DViewer.map.on('click', cleanRightClickPopup);
  1758. };
  1759. function bingClickEvents() {
  1760. $("#rightClickSearchForm-select").bind('change', function() {
  1761. var val = (parseInt($(this).val()) * 2 + 1) * 5000;
  1762. map2DViewer.circle({
  1763. action: 'update',
  1764. geojson: {
  1765. "properties": {
  1766. radius: val
  1767. }
  1768. },
  1769. guid: modValue.searchCircle
  1770. })
  1771. //searchCircle.setRadius(val);
  1772. map2DViewer.map.fitBounds(map2DViewer.circles[modValue.searchCircle].getBounds());
  1773. });
  1774. $("#rightClickSearchForm .s-form .btn").bind('click', function() {
  1775. var keyWord = $("#rightClickSearchForm .s-form .input").val();
  1776. var dis = $("#rightClickSearchForm .select").val();
  1777. if (keyWord.length == 0) {
  1778. return false;
  1779. }
  1780. cleanRightClickPopup();
  1781. if (initData({ 'keyWord': keyWord, 'dis': dis, 'type': "theme", center: modValue.options.center })) {
  1782. $(".category-list-wrap").empty();
  1783. $(".place-list").empty();
  1784. $(".page-wrap").empty();
  1785. /*$("#searchresult").css("top","0px")*/
  1786. $("#searchresult").show();
  1787. $("#userContent .userInfo").removeClass("active");
  1788. getPageResult({ 'page': 1 });
  1789. }
  1790. });
  1791. $('#rightClickSearchForm .s-form .input').on('keydown', function(e) {
  1792. if (e.keyCode === 13) {
  1793. var keyWord = $("#rightClickSearchForm .s-form .input").val();
  1794. var dis = $("#rightClickSearchForm .select").val();
  1795. if (keyWord.length == 0) {
  1796. return false;
  1797. }
  1798. cleanRightClickPopup();
  1799. if (initData({ 'keyWord': keyWord, 'dis': dis, 'type': "theme", center: modValue.options.center })) {
  1800. $(".category-list-wrap").empty();
  1801. $(".place-list").empty();
  1802. $(".page-wrap").empty();
  1803. /*$("#searchresult").css("top","0px")*/
  1804. $("#searchresult").show();
  1805. $("#userContent .userInfo").removeClass("active");
  1806. getPageResult({ 'page': 1 });
  1807. }
  1808. }
  1809. });
  1810. };
  1811. /**
  1812. * 设置分类
  1813. */
  1814. function setMoreSurround() {
  1815. $('#rightClickSearchForm .s-hot-point-select')
  1816. .empty()
  1817. .append($('<div class="list"><span>地名分类:</span><select class="select first">' +
  1818. '<option value="0">常用</option>' +
  1819. '<option value="1">交通</option>' +
  1820. '<option value="2">设施</option>' +
  1821. '<option value="3">水系</option>' +
  1822. '<option value="4">单位</option>' +
  1823. '<option value="5">居民点</option>' +
  1824. '<option value="6">旅游</option>' +
  1825. '</select>' +
  1826. '</div>'));
  1827. $('#rightClickSearchForm .s-hot-point-select .first').bind('change', function() {
  1828. $('#placeSearchRoundThemeList').empty();
  1829. for (var i = 0, l = modValue.hotPoint.length; i < l; i++) {
  1830. if (modValue.hotPoint[i].id === $(this).val()) {
  1831. for (var ii = 0, ll = modValue.hotPoint[i].sons.length; ii < ll; ii++) {
  1832. var item = $('<li><a href="javascript:ONEMAP.M.placeSearch.findSurround(' + modValue.hotPoint[i].sons[ii].id + ')" hid="' + modValue.hotPoint[i].sons[ii].id + '">' + modValue.hotPoint[i].sons[ii].name + '</a></li>');
  1833. item.appendTo($('#placeSearchRoundThemeList'));
  1834. }
  1835. }
  1836. }
  1837. });
  1838. };
  1839. /**
  1840. * 根据半径画圆
  1841. */
  1842. function drawCircle(center, dis) {
  1843. modValue.searchCircle = map2DViewer.circle({
  1844. action: 'add',
  1845. geojson: {
  1846. "properties": {
  1847. color: '#ff6600',
  1848. weight: 1,
  1849. fillColor: '#ff6600',
  1850. opacity: 1,
  1851. fillOpacity: 0.5,
  1852. radius: dis //半径米
  1853. },
  1854. "geometry": {
  1855. "type": "Circle",
  1856. "coordinates": [center.lng, center.lat]
  1857. }
  1858. }
  1859. });
  1860. map2DViewer.map.fitBounds(map2DViewer.circles[modValue.searchCircle].getBounds());
  1861. map2DViewer.circles[modValue.searchCircle].on('click', function() {
  1862. cleanCricle();
  1863. })
  1864. };
  1865. function findSurround(hid) {
  1866. var keyWord = $("#rightClickSearchForm .s-form .input").val();
  1867. if (keyWord.length == 0) {
  1868. keyWord = 'temp';
  1869. }
  1870. $(".placeOther").hide();
  1871. if (initData({ 'keyWord': keyWord, 'themeId': hid, 'dis': $("#rightClickSearchForm .select").val(), 'type': "theme", 'center': modValue.options.center })) {
  1872. if (keyWord == 'temp') {
  1873. modValue.options.keyWord = '';
  1874. }
  1875. /*$("#searchresult").css("top","0px")*/
  1876. $("#searchresult").show();
  1877. $("#userContent .userInfo").removeClass("active");
  1878. getPageResult({ 'page': 1 });
  1879. cleanRightClickPopup();
  1880. }
  1881. };
  1882. /**
  1883. * 清除右键弹出popup和圆
  1884. * @type {Function}
  1885. * @private
  1886. */
  1887. function cleanRightClickPopup() {
  1888. if (map2DViewer.map.hasLayer(modValue.searchPoup)) {
  1889. map2DViewer.map.removeLayer(modValue.searchPoup)
  1890. }
  1891. map2DViewer.map.on('click', cleanCricle);
  1892. map2DViewer.map.off('click', cleanRightClickPopup);
  1893. };
  1894. function cleanCricle() {
  1895. map2DViewer.circle({
  1896. action: 'remove',
  1897. guid: modValue.searchCircle
  1898. })
  1899. $("#searchresult").hide();
  1900. /*$("#searchresult").css("top","39px");*/
  1901. map2DViewer.map.off('click', cleanCricle);
  1902. };
  1903. /**
  1904. * 清除标记
  1905. * [cleanMarkerGroup description]
  1906. * @return {[type]} [description]
  1907. */
  1908. function cleanMarkerGroup() {
  1909. if (map23DData.display.map3D) {
  1910. $.each(map3DViewer.markers, function(value, key) {
  1911. // map3DViewer.label({
  1912. // action: 'remove',
  1913. // guid: value,
  1914. // featureType: 'marker'
  1915. // })
  1916. })
  1917. }
  1918. map23DControl.group({
  1919. action: 'cleanAll',
  1920. guid: modValue.markerGroup
  1921. })
  1922. };
  1923. function getAreaInfo(options, callback_func) {
  1924. var poiSearch = new poiSearchF();
  1925. poiSearch.getAreaInfo({ keywords: options.keywords }, function(data) {
  1926. callback_func(data.data);
  1927. });
  1928. };
  1929. function getPacRegionInfo(options, callback_func) {
  1930. var regionSearch = new regionSearchF();
  1931. regionSearch.getPacRegionInfo({ pac: options.pac }, function(data) {
  1932. callback_func(data.data);
  1933. });
  1934. };
  1935. function getRegionBoundary(options, callback_func) {
  1936. var regionSearch = new regionSearchF();
  1937. regionSearch.getRegionBoundary({ latLng: [options.lat, options.lng], demand: options.demand }, function(data) {
  1938. callback_func(data.data);
  1939. });
  1940. };
  1941. function changeToBoundsSearch(options) {
  1942. modValue.fitBounds = false;
  1943. //changSearchType({'type':'bounds'});
  1944. modValue.options.init_query_key = options.keyWord;
  1945. if (initData({ type: 'bounds', keyWord: options.keyWord })) {
  1946. getPageResult({ page: 1 });
  1947. }
  1948. };
  1949. function bindEvent() {
  1950. // $('#searchInViewKey').bind('focusout', function() {
  1951. // if ($(this).val() == '') {
  1952. // $(this).val('关键字');
  1953. // };
  1954. // });
  1955. $('#btnSearchInView').bind('click', function() {
  1956. $("#placePanel .fastSearchLink").hide();
  1957. $("#placePanel .boundsSearchLink").hide();
  1958. ONEMAP.D.searchFirstResult = false;
  1959. // if($(".tools-search").hasClass('cur')){
  1960. modValue.options.type = 'pac'
  1961. // }else if($('.tools-serchView').hasClass('cur')){
  1962. // modValue.options.type = 'bounds'
  1963. // }
  1964. $("#searchresult").show();
  1965. $("#userContent .userInfo").removeClass("active");
  1966. map23DControl.group({
  1967. action: 'cleanAll',
  1968. guid: modValue.markerGroup
  1969. })
  1970. globalSearchFire();
  1971. if ($("#searchInViewKey").val() == "") {
  1972. $("#searchresult").hide();
  1973. }
  1974. });
  1975. $('#searchInViewKey').bind('keydown', function(e) {
  1976. $("#placePanel .fastSearchLink").hide();
  1977. $("#placePanel .boundsSearchLink").hide();
  1978. $('#header .h-center .close').show();
  1979. $(".userInfo").removeClass("active");
  1980. ONEMAP.D.searchFirstResult = false;
  1981. if ($("#searchInViewKey").val() != "") {
  1982. $('#header .h-center .close').show();
  1983. }
  1984. if (e.keyCode === 13) {
  1985. if ($("#searchInViewKey").val() != "") {
  1986. // if($(".tools-search").hasClass('cur')){
  1987. modValue.options.type = 'pac'
  1988. // }else if($('.tools-serchView').hasClass('cur')){
  1989. // modValue.options.type = 'bounds'
  1990. // }
  1991. $("#searchresult").show();
  1992. $("#userContent .userInfo").removeClass("active");
  1993. map23DControl.group({
  1994. action: 'cleanAll',
  1995. guid: modValue.markerGroup
  1996. })
  1997. globalSearchFire();
  1998. }
  1999. }
  2000. if ($("#searchInViewKey").val() == "") {
  2001. $("#searchresult").hide();
  2002. $('#header .h-center .close').hide();
  2003. clearMarker();
  2004. $("#placePanel .thematic-search-list").empty();
  2005. ONEMAP.D.user.searchKeyWord = "";
  2006. modValue.options.keyWord = "";
  2007. //$(".meteo-search-result-list").html("");
  2008. $("#placePanel .thematic-content").hide();
  2009. ONEMAP.D.panelMore = false;
  2010. // $(".abtn-mini-side-bar").removeClass("close");
  2011. ONEMAP.C.publisher.publish('handHide', 'layout::sideBar');
  2012. }
  2013. });
  2014. // $('#searchInViewKey').bind('focus', function() {
  2015. // $(this).val('');
  2016. // clearMarker();
  2017. // });
  2018. $('#header .h-center .close').unbind('click').bind('click', function() {
  2019. $("#gcms-search-result-list").remove(); //移除右侧栏搜索结果
  2020. $('#searchInViewKey').val('');
  2021. clearMarker();
  2022. $(this).hide();
  2023. $("#placePanel .thematic-search-list").empty();
  2024. ONEMAP.D.user.searchKeyWord = "";
  2025. modValue.options.keyWord = "";
  2026. //$(".meteo-search-result-list").html("");
  2027. $("#thematicSearchKey").val("");
  2028. $("#placePanel .thematic-content").hide();
  2029. ONEMAP.D.panelMore = false;
  2030. // $(".abtn-mini-side-bar").removeClass("close");
  2031. ONEMAP.C.publisher.publish('handHide', 'layout::sideBar');
  2032. });
  2033. //gcms搜索列表
  2034. $(".gcms-search .moreLi .fr").unbind('click').bind("click", function() {
  2035. //设置zIndex 为最高
  2036. var zIndex = ONEMAP.M.sideBar.getZIndex();
  2037. $('#gcms-search-result-list').css({ zIndex: zIndex });
  2038. $(".gcms-search-result-list").show();
  2039. ONEMAP.D.currentSideBarMod = 'gcms-search-result-list';
  2040. //开启侧栏
  2041. ONEMAP.C.publisher.publish('handShow', 'layout::sideBar');
  2042. })
  2043. };
  2044. return ONEMAP.M.placeSearch = {
  2045. init: init,
  2046. setFav: setFav,
  2047. changSearchType: changSearchType,
  2048. modValue: modValue,
  2049. rightClickPopup: rightClickPopup,
  2050. findSurround: findSurround,
  2051. getAreaInfo: getAreaInfo,
  2052. setDirections: setDirections,
  2053. createMarker: createMarker
  2054. }
  2055. })