traffic_org.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878
  1. let _size = [48, 48, 48, 48, 40, 32, 24, 22, 20, 18, 18];
  2. let _AtrdData = [];
  3. let _AtrdMap = new Map();
  4. let selectIncidentId = null;
  5. //시설물 유형
  6. const _FacilityArray = ['cctv', 'vms', 'intersection', 'incident', 'traffic', 'parking', 'intersectionCamera'];
  7. const g_color = new Map();
  8. g_color.set('LTC0', '#888888;');
  9. g_color.set('LTC1', '#2fba2c;');
  10. g_color.set('LTC2', '#ffc500;');
  11. g_color.set('LTC3', '#ee0000;');
  12. const CCTV_DISPLAY_TIME = 30 * 1000; // 영상 표출 시간
  13. const VMS_DISPLAY_TIME = 4 * 1000; // VMS 이미지 표출 시간
  14. let _MapHandler; //카카오 맵 핸들러
  15. let _Level = 6; //현재 줌레벨
  16. let _methodMap = new Map();
  17. _methodMap.set('cctv', getCctv);
  18. _methodMap.set('vms', getVms);
  19. _methodMap.set('incident', getIncident);
  20. _methodMap.set('intersection', getIntersection);
  21. _methodMap.set('traffic', getAtrd);
  22. _methodMap.set('parking', getParking);
  23. $(()=>{
  24. // Map 요소 ID로 생성
  25. _MapHandler = new MapHandler('map');
  26. _MapHandler.init();
  27. // 시설물 유형 정보로 flag 값 세팅
  28. if (_type) {
  29. _MapHandler[_type + 'Flag'] = true;
  30. _MapHandler[_type + 'ListFlag'] = true;
  31. _methodMap.get(_type)();
  32. }
  33. /**
  34. * 범례 클릭 이벤트 및 색 변환
  35. * */
  36. $('.legend-bottom button').on('click', function (){
  37. const target = $(this);
  38. const legendIcon = target.children().eq(0);
  39. const isShow = !legendIcon.hasClass('active');
  40. const id = target.attr('id');
  41. const type = id.replace('-legend', '');
  42. let subType = null;
  43. if (type === 'intersection') {
  44. subType = type + 'Camera';
  45. }
  46. if (type === 'traffic') {
  47. subType = 'atrd';
  48. getVertex();
  49. }
  50. else {
  51. if (_MapHandler[type] && _MapHandler[type].length <= 0) {
  52. _methodMap.get(type)();
  53. }
  54. }
  55. let toggle = 'hide';
  56. let classToggle = 'removeClass';
  57. if (isShow === true) {
  58. toggle = 'show';
  59. classToggle = 'addClass';
  60. }
  61. legendIcon[classToggle]('active');
  62. target[classToggle]('active');
  63. _MapHandler[toggle](type);
  64. if (subType) {
  65. _MapHandler[toggle](subType);
  66. }
  67. })
  68. /**
  69. * 범례 호버 색 변환
  70. * */
  71. $('.legend-bottom ul li').hover((event)=>{
  72. const iconDiv = $(event.currentTarget).children().eq(0);
  73. const childDiv = iconDiv.children().eq(0);
  74. if (!iconDiv.hasClass('active')) {
  75. childDiv.addClass('hover');
  76. }
  77. else {
  78. if (childDiv.hasClass('hover')) {
  79. childDiv.removeClass('hover');
  80. }
  81. }
  82. },
  83. (event)=>{
  84. const iconDiv = $(event.currentTarget).children().eq(0);
  85. const childDiv = iconDiv.children().eq(0);
  86. if (!iconDiv.hasClass('active')) {
  87. childDiv.removeClass('hover');
  88. }
  89. else {
  90. if (childDiv.hasClass('hover')) {
  91. childDiv.removeClass('hover');
  92. }
  93. }
  94. });
  95. /**
  96. * 탭 호버 색 변환
  97. * */
  98. $('.left-list-area .list-tab > li').hover((event)=>{
  99. const iconDiv = $(event.currentTarget);
  100. const childDiv = iconDiv.children().eq(0);
  101. if (!iconDiv.hasClass('active')) {
  102. childDiv.addClass('hover');
  103. }
  104. else {
  105. if (childDiv.hasClass('hover')) {
  106. childDiv.removeClass('hover');
  107. }
  108. }
  109. },
  110. (event)=>{
  111. const iconDiv = $(event.currentTarget);
  112. const childDiv = iconDiv.children().eq(0);
  113. if (!iconDiv.hasClass('active')) {
  114. childDiv.removeClass('hover');
  115. }
  116. else {
  117. if (childDiv.hasClass('hover')) {
  118. childDiv.removeClass('hover');
  119. }
  120. }
  121. });
  122. let _MarkerArr = [];
  123. $('.tab-title > div').on('click', function(){
  124. const $spot = $('.list-content.spot');
  125. const $list = $('.list-content.list');
  126. let searchType = $('.tab-title > div.active').text();
  127. if (searchType === $(this).text()) return;
  128. $('.tab-title > div').toggleClass("active");
  129. searchType = $(this).text();
  130. let list;
  131. let spot;
  132. if (searchType === '지점 검색') {
  133. list = 'none';
  134. spot = 'block';
  135. $spot.html("");
  136. }
  137. else {
  138. list = 'block';
  139. spot = 'none';
  140. $('.list-content.list > li').css('display', 'block');
  141. }
  142. $('#search-box').val("");
  143. $list.css('display', list);
  144. $spot.css('display', spot);
  145. if (_MarkerArr.length > 0) {
  146. _MarkerArr.forEach((obj)=>{
  147. obj.setMap(null);
  148. });
  149. _MarkerArr = [];
  150. }
  151. })
  152. $('#search-box').on('keyup', function () {
  153. const searchType = $('.tab-title > div.active').text();
  154. const searchText = $(this).val();
  155. if (searchType === '리스트') {
  156. const $list = $('.list-content.list > li');
  157. if (!$list.length) return;
  158. for (let ii = 0; ii < $list.length; ii++) {
  159. const li = $list.eq(ii);
  160. if ($(this).val().length === 0) {
  161. li.css('display', 'block');
  162. }
  163. else {
  164. let text = $('.list-content.list > li').eq(ii).text().toLowerCase();
  165. if (text.includes(searchText.toLowerCase())) {
  166. li.css('display', 'block');
  167. }
  168. else {
  169. li.css('display', 'none');
  170. }
  171. }
  172. }
  173. }
  174. else {
  175. if (_MarkerArr.length > 0) {
  176. _MarkerArr.forEach((obj)=>{
  177. obj.setMap(null);
  178. });
  179. _MarkerArr = [];
  180. }
  181. $('.list-content.spot').html("");
  182. if (!searchText || !searchText.trim()) return;
  183. $.ajax({
  184. url: 'https://dapi.kakao.com/v2/local/search/address.json',
  185. headers: { 'Authorization': 'KakaoAK 4896b94398b96949d349881d004835cf'},
  186. data :{
  187. query : searchText,
  188. },
  189. type: 'GET'
  190. }).done(function(data) {
  191. if (data && data.documents.length > 0) {
  192. let str = "";
  193. const setMap = new Map();
  194. const bounds = new kakao.maps.LatLngBounds();
  195. let minX;
  196. let minY;
  197. let maxX;
  198. let maxY;
  199. let idx = 0;
  200. data.documents.forEach((obj)=>{
  201. if (!setMap.get(obj.address_name) && obj.address_name.includes("경북 포항시")) {
  202. idx++;
  203. let addr = obj.address_name;
  204. if (obj.x && obj.y) {
  205. const position = getKakaoPosition(obj.y, obj.x);
  206. let marker = new kakao.maps.Marker({
  207. position : position,
  208. title : addr ,
  209. content : addr
  210. });
  211. new kakao.maps.event.addListener(marker, 'click', function() {
  212. moveLocation(obj.x, obj.y, idx);
  213. })
  214. if (!minX) {
  215. minX = obj.x;
  216. }
  217. if (!maxX) {
  218. maxX = obj.x;
  219. }
  220. if (!minY) {
  221. minY = obj.y;
  222. }
  223. if (!maxY) {
  224. maxY = obj.y;
  225. }
  226. minX = minX <= obj.x ? minX : obj.x;
  227. maxX = maxX >= obj.x ? maxX : obj.x;
  228. minY = minY <= obj.y ? minY : obj.y;
  229. maxY = maxY >= obj.y ? maxY : obj.y;
  230. marker.setMap(_MapHandler.map);
  231. _MarkerArr.push(marker);
  232. setMap.set(addr, obj);
  233. str+= `<li id="spot-${idx}" onclick="moveLocation(${obj.x}, ${obj.y}, ${idx})">
  234. ${obj.address_name}
  235. </li>`;
  236. }
  237. }
  238. });
  239. if (minX && minY && maxX && maxY) {
  240. bounds.extend(new kakao.maps.LatLng(minY, minX));
  241. bounds.extend(new kakao.maps.LatLng(maxY, maxX));
  242. _MapHandler.map.setBounds(bounds);
  243. $('.list-content.spot').html(str);
  244. getVertex();
  245. }
  246. }
  247. });
  248. }
  249. })
  250. });
  251. /**
  252. * 간선도로 마커 레벨별 이미지 보이기 감추기
  253. */
  254. function atrdMarkerResize() {
  255. let level = _Level;
  256. let atrdArr = _MapHandler['atrd'];
  257. atrdArr.forEach((atrd)=>{
  258. setMarkerImage(atrd, atrd.obj.drct_cd, true);
  259. });
  260. if (level === 3) {
  261. level = 4;
  262. }
  263. if (level >= 8) {
  264. level = 7;
  265. }
  266. else if (level >= 6) {
  267. level = 6;
  268. }
  269. const atrdInfo = _AtrdMap.get(level.toString());
  270. if (atrdInfo) {
  271. _AtrdData = [];
  272. let upHillArr = [];
  273. let downHillArr = [];
  274. const $selectedLi = $(".left-list-area .list-content.list > li.click");
  275. let id;
  276. let idArr;
  277. if ($selectedLi[0]) {
  278. id = $selectedLi.attr('id');
  279. }
  280. if (id) {
  281. idArr = id.split("_");
  282. }
  283. atrdInfo.forEach((atrd)=>{
  284. if (atrd.atrd_id.toString() === idArr[1] || atrd.atrd_id.toString() === idArr[2]) {
  285. _AtrdData.push(atrd);
  286. if (atrd.atrd_id.toString() === idArr[1]) {
  287. upHillArr.push(atrd);
  288. }
  289. else {
  290. downHillArr.push(atrd);
  291. }
  292. }
  293. });
  294. if (upHillArr[0]) {
  295. let upHillX = upHillArr[0].x_crdn_arr.split(',')[0];
  296. let upHillY = upHillArr[0].y_crdn_arr.split(',')[0];
  297. atrdArr[0].marker.setPosition(getKakaoPosition(upHillY, upHillX));
  298. }
  299. if (downHillArr[0]) {
  300. let downHillX = downHillArr[0].x_crdn_arr.split(',')[0];
  301. let downHillY = downHillArr[0].y_crdn_arr.split(',')[0];
  302. atrdArr[1].marker.setPosition(getKakaoPosition(downHillY, downHillX));
  303. }
  304. }
  305. }
  306. /**
  307. * 스마트교차로 카메라 레벨별 이미지 보이기 감추기
  308. */
  309. function intersectionCameraChangeWidthZoomLevel() {
  310. const level = _Level;
  311. const size = [48, 48, 48]
  312. const levelSize = size[level];
  313. const type = 'intersectionCamera';
  314. const markerArr = _MapHandler[type];
  315. const map = _MapHandler.map;
  316. if (markerArr.length > 0) {
  317. markerArr.forEach((obj) => {
  318. const content = $('<div title='+obj.NAME+'>');
  319. content.css(
  320. {
  321. width: levelSize+ 'px',
  322. height: levelSize+ 'px',
  323. backgroundImage:'url(/images/icon/intersection-cctv.png)',
  324. backgroundSize : levelSize+'px '+levelSize+'px',
  325. backgroundRepeat: 'no-repeat',
  326. backgroundPosition : 'center',
  327. transform : 'rotate(' + obj.obj.cmra_angn +'deg)',
  328. cursor : 'pointer'
  329. });
  330. obj.marker.setContent(content[0]);
  331. content.on('click', ()=> {
  332. _MapHandler.click(type, obj.ID);
  333. });
  334. if (level <= 2 && _MapHandler['intersectionFlag']) {
  335. obj.marker.setMap(map);
  336. obj.polyline.setMap(map);
  337. } else {
  338. obj.marker.setMap(null);
  339. obj.polyline.setMap(null);
  340. }
  341. })
  342. }
  343. }
  344. /**
  345. * 스마트교차로 레벨별 이미지 보이기 감추기
  346. */
  347. function intersectionMarkerChangeWithZoomLevel() {
  348. const level = _Level;
  349. if (_MapHandler['intersection'].length > 0) {
  350. _MapHandler['intersection'].forEach((obj)=>{
  351. setMarkerImage(obj, "", false);
  352. if (level > 2 && _MapHandler['intersectionFlag']) {
  353. obj.marker.setVisible(true);
  354. }
  355. else {
  356. obj.marker.setVisible(false);
  357. }
  358. })
  359. }
  360. }
  361. /**
  362. * 맵 레벨별 이미지 변환
  363. * @param array
  364. */
  365. function markerSizeChangeWithZoomLevel(array) {
  366. if (array && array.length > 0) {
  367. array.forEach((obj)=>{
  368. if (obj.isClick) {
  369. setMarkerImage(obj, 2, false)
  370. }
  371. else {
  372. setMarkerImage(obj, 1, false);
  373. }
  374. });
  375. }
  376. }
  377. /**
  378. * 지점 클릭 위치 이동
  379. * @param xCoordinate x좌표
  380. * @param yCoordinate y좌표
  381. * @param listIndex 지점 선택 인덱스
  382. */
  383. function moveLocation(xCoordinate, yCoordinate, listIndex) {
  384. const position = getKakaoPosition(yCoordinate, xCoordinate);
  385. _MapHandler.map.setCenter(position);
  386. _MapHandler.map.setLevel(3);
  387. $('.list-content.spot > li.click').removeClass('click');
  388. $('#spot-' +listIndex).addClass('click');
  389. getVertex();
  390. }
  391. /**
  392. * cctv 데이터 가져오기
  393. */
  394. function getCctv() {
  395. getDataAsync('/api/traffic/cctv-list', 'POST', null, null, (jsonData)=>{
  396. if (jsonData && jsonData.length > 0) {
  397. receiveFacilityData(jsonData, TbCCtvObj,'cctv');
  398. }
  399. }, null);
  400. }
  401. /**
  402. * vms 데이터 가져오기
  403. */
  404. function getVms() {
  405. getDataAsync('/api/traffic/vms-list', 'POST', null, null, (jsonData)=>{
  406. if (jsonData && jsonData.length > 0) {
  407. jsonData.sort((a, b)=>{
  408. return a.vms_nm > b.vms_nm ? 1 : a.vms_nm < b.vms_nm ? -1 : 0;
  409. })
  410. receiveFacilityData(jsonData, TbVmsObj,'vms');
  411. }
  412. }, null);
  413. }
  414. /**
  415. * 돌발정보
  416. */
  417. function getIncident () {
  418. getDataAsync('/api/traffic/incident-list', 'POST', null, null, (jsonData)=>{
  419. if (jsonData && jsonData.length > 0) {
  420. receiveFacilityData(jsonData, TbIncdObj, 'incident');
  421. if (selectIncidentId) {
  422. _MapHandler.click('incident', selectIncidentId);
  423. }
  424. }
  425. }, null);
  426. }
  427. /**
  428. * 스마트교차로
  429. */
  430. function getIntersection() {
  431. getDataAsync('/api/itcs/list', 'POST', null, null, (jsonData)=>{
  432. if (jsonData && jsonData.length > 0) {
  433. jsonData.sort((a, b)=>{
  434. return a.ixr_nm > b.ixr_nm ? 1 : a.ixr_nm < b.ixr_nm ? -1 : 0;
  435. });
  436. let data = [];
  437. jsonData.forEach((obj)=>{
  438. if(obj.detail.length > 0) {
  439. data.push(obj);
  440. }
  441. })
  442. receiveFacilityData(data, IntersectionObj, 'intersection');
  443. }
  444. }, null);
  445. }
  446. /**
  447. * 주차정보
  448. */
  449. function getParking() {
  450. getDataAsync('/api/traffic/parking-list', 'POST', null, null, (jsonData)=>{
  451. if (jsonData && jsonData.length > 0) {
  452. receiveFacilityData(jsonData, TbParkingObj, 'parking');
  453. }
  454. }, null);
  455. }
  456. /**
  457. * 간선도로 정보
  458. */
  459. function getAtrd() {
  460. getDataAsync("/api/traffic/atrd-vertex-all", "POST", null, null, (jsonData)=>{
  461. if (jsonData && jsonData.length > 0) {
  462. _AtrdMap = new Map();
  463. jsonData.forEach((obj)=>{
  464. _AtrdMap.set(obj.level, obj.list);
  465. });
  466. }
  467. }, null);
  468. getDataAsync('/api/traffic/atrd-list', 'POST', null, null, (jsonData)=>{
  469. if (jsonData) {
  470. let listStr = "";
  471. let mobileStr = "";
  472. let atrdData = [];
  473. for (let key in jsonData){
  474. atrdData.push({
  475. name : key,
  476. list : jsonData[key]
  477. });
  478. }
  479. atrdData.sort((a,b)=>{
  480. return a.name > b.name ? 1 : a.name < b.name ? -1 : 0;
  481. });
  482. atrdData.forEach((obj)=>{
  483. let upHillId = null;
  484. let downHillId = null;
  485. const list = obj.list;
  486. if (list && list.length === 2) {
  487. upHillId = list[0].atrd_id;
  488. downHillId = list[1].atrd_id;
  489. if (list[0].drct_cd === "1") {
  490. upHillId = list[1].atrd_id;
  491. downHillId = list[0].atrd_id;
  492. }
  493. }
  494. listStr += `<li id="atrd_${upHillId}_${downHillId}" onclick="atrdClickEvent('${upHillId}', '${downHillId}')">${obj.name}</li>`
  495. mobileStr += `<option value="${upHillId}_${downHillId}">${obj.name}</option>`
  496. });
  497. const $mobileSelect = $('.mobile-select');
  498. $mobileSelect.append($(mobileStr));
  499. $mobileSelect.on('change', function(){
  500. const ids = $(this).val();
  501. if (ids && ids !== '-') {
  502. const idArr = ids.split('_');
  503. atrdClickEvent(idArr[0], idArr[1]);
  504. }
  505. else {
  506. const array = _MapHandler['atrd'];
  507. if (array.length > 0) {
  508. array.forEach((atrd)=>{
  509. atrd.close();
  510. })
  511. _MapHandler['atrd'] = [];
  512. getVertex();
  513. }
  514. }
  515. })
  516. const listSection = $('.left-list-area .list-content.list');
  517. listSection.empty();
  518. listSection.html(listStr);
  519. }
  520. });
  521. getVertex();
  522. }
  523. /**
  524. * 소통정보 가져오기
  525. */
  526. function getVertex() {
  527. const array = _MapHandler['traffic'];
  528. if (array.length > 0) {
  529. array.forEach((obj) => {
  530. obj.setVisibleMarker(false);
  531. if (obj.infoWindow) {
  532. obj.infoWindow.setMap(null);
  533. }
  534. })
  535. _MapHandler['traffic'] = [];
  536. }
  537. let level = _MapHandler.map.getLevel();
  538. const bounds = _MapHandler.map.getBounds();
  539. const swLatLng = bounds.getSouthWest();
  540. const neLatLng = bounds.getNorthEast();
  541. const data = {
  542. levl : level,
  543. swLat : swLatLng.getLat(),
  544. neLat : neLatLng.getLat(),
  545. swLng : swLatLng.getLng(),
  546. neLng : neLatLng.getLng(),
  547. }
  548. if (_MapHandler.atrd && _MapHandler.atrd.length > 0) {
  549. _MapHandler.atrd.forEach((atrd)=>{
  550. atrd.cnt = 0;
  551. atrd.trvl_hh = 0;
  552. atrd.sped = 0;
  553. })
  554. }
  555. getDataAsync('/api/traffic/vertex-list', 'POST', data, null, (jsonData)=>{
  556. if (jsonData && jsonData.length > 0) {
  557. jsonData.forEach((obj)=>{
  558. const trafficObj = new TrafficObj(obj);
  559. if (_AtrdData.length > 0) {
  560. _AtrdData.forEach((atrd)=>{
  561. if (atrd.road_id.toString() === trafficObj.ID.toString()) {
  562. let sped = Number(obj.sped);
  563. let trvl_hh = Number(obj.trvl_hh);
  564. const atrdObj = _MapHandler.getSelectObj(_MapHandler['atrd'], atrd.atrd_id);
  565. if (!isNaN(sped)) {
  566. atrdObj.sped += sped;
  567. }
  568. if (!isNaN(trvl_hh)) {
  569. atrdObj.trvl_hh += trvl_hh;
  570. }
  571. atrdObj.cnt += 1;
  572. trafficObj.polyBackLine.setOptions({
  573. strokeColor : 'black',
  574. });
  575. }
  576. })
  577. }
  578. _MapHandler['traffic'].push(trafficObj);
  579. })
  580. }
  581. });
  582. }
  583. /**
  584. * 간선도로 클릭 이벤트
  585. * @param AupHillId 상행 ID
  586. * @param AdownHillId 하행 ID
  587. */
  588. function atrdClickEvent(AupHillId, AdownHillId) {
  589. let atrdArr = _MapHandler['atrd'];
  590. if (atrdArr.length > 0) {
  591. atrdArr.forEach((atrd)=>{
  592. atrd.close();
  593. });
  594. _MapHandler['atrd'] = [];
  595. }
  596. const selectedObj = _MapHandler.selectedObj;
  597. if (selectedObj) {
  598. _MapHandler.close(selectedObj.type, selectedObj.ID);
  599. }
  600. _AtrdData = [];
  601. const $selectedLi = $('.left-list-area .list-content.list > li.click');
  602. if ($selectedLi) {
  603. $selectedLi.removeClass('click');
  604. }
  605. const $selectLi = $('#atrd_' + AupHillId + "_" + AdownHillId);
  606. $selectLi.addClass('click');
  607. $selectLi.focus();
  608. //상행, 하행 ID 가 있다면 실행
  609. if (AupHillId && AdownHillId) {
  610. const upHillArr = [];
  611. const downHillArr = [];
  612. const bounds = new kakao.maps.LatLngBounds();
  613. //전체 간선도로 목록을 담은 Map 에서 기준값을 5레벨로 잡아 포커스 좌표를 설정
  614. if (_AtrdMap.get("5")) {
  615. const basicAtrd = _AtrdMap.get("5");
  616. for (let idx in basicAtrd) {
  617. const obj = basicAtrd[idx];
  618. if (obj.atrd_id.toString() === AupHillId || obj.atrd_id.toString() === AdownHillId) {
  619. bounds.extend(new kakao.maps.LatLng(obj.y_crdn_min, obj.x_crdn_min));
  620. bounds.extend(new kakao.maps.LatLng(obj.y_crdn_max, obj.x_crdn_max));
  621. }
  622. }
  623. _MapHandler.map.setBounds(bounds);
  624. //전체 레벨이 다있는게 아니므로 로드 레벨은 재설정
  625. let level = _Level;
  626. if (level >= 8) {
  627. level = 7;
  628. }
  629. else if (level >= 6) {
  630. level = 6;
  631. }
  632. /**
  633. * 범위를 포커스 하게 되면 레벨이 변경되므로 변경 된 레벨의 간선도로 목록에서
  634. * 상행, 하행 ID가 포함된 데이터 갖고오며 상행, 하행 데이터 따로 구분
  635. */
  636. const atrdInfo = _AtrdMap.get(level.toString());
  637. if (atrdInfo) {
  638. atrdInfo.forEach((atrd)=>{
  639. if (atrd.atrd_id.toString() === AupHillId.toString() || atrd.atrd_id.toString() === AdownHillId.toString()) {
  640. _AtrdData.push(atrd);
  641. if (atrd.atrd_id === AupHillId) {
  642. upHillArr.push(atrd);
  643. }
  644. else {
  645. downHillArr.push(atrd);
  646. }
  647. }
  648. })
  649. }
  650. //레벨이 변경됐으므로 다시한번 버텍스를 초기화해준다
  651. getVertex();
  652. //각 상행 하행의 첫번째 좌표를 가지고 상행, 하행 아이콘을 생성 하며 객체는 array에 보관해둠
  653. if (upHillArr[0]) {
  654. const upHillObj = new TbAtrdObj(upHillArr[0]);
  655. _MapHandler['atrd'].push(upHillObj);
  656. }
  657. if (downHillArr[0]) {
  658. const downHillObj = new TbAtrdObj(downHillArr[0]);
  659. _MapHandler['atrd'].push(downHillObj);
  660. }
  661. }
  662. }
  663. }
  664. /**
  665. * 간선도로 상,하행 마커 그리기
  666. * @param src 상, 하행 코드
  667. * @param lat X 좌표
  668. * @param lng Y 좌표
  669. * @param name 명칭
  670. * @returns {daum.maps.Marker} 생성 마커
  671. */
  672. function drawAtrdMakrer(src, lng, lat, name) {
  673. let imageSize;
  674. let imageOption;
  675. let imageSrc = '/images/icon/atrd' + src + '.png';
  676. //레벨별 사이즈를 다르게 표출
  677. const level = _Level;
  678. let size = 48;
  679. if (level >= 7) {
  680. size = 24;
  681. }
  682. imageSize = new kakao.maps.Size(size, size);
  683. imageOption = {
  684. offset: new kakao.maps.Point(size/2, size),
  685. };
  686. let markerImage = new kakao.maps.MarkerImage(imageSrc, imageSize, imageOption);
  687. let markerPosition = new kakao.maps.LatLng(lng, lat);
  688. let atrdSideMarker = new kakao.maps.Marker({
  689. position: markerPosition,
  690. image: markerImage,
  691. zIndex: 5,
  692. title: name,
  693. });
  694. return atrdSideMarker;
  695. }
  696. /**
  697. * 소통정보 Object
  698. */
  699. class TrafficObj {
  700. constructor(obj) {
  701. this.ID = obj.roadway_id;
  702. this.NAME = obj.roadway_nm;
  703. this.obj = obj;
  704. this.infoWindow = null;
  705. this.polyLine = null;
  706. this.polyBackLine = null;
  707. this.init();
  708. }
  709. init() {
  710. const _self = this;
  711. const trafficObj = this.obj;
  712. const xArray = trafficObj.x_crdn.split(",");
  713. const yArray = trafficObj.y_crdn.split(",");
  714. const linePath = [];
  715. for (let ii = 0; ii < xArray.length; ii++) {
  716. const x_crdn = Number(xArray[ii]);
  717. const y_crdn = Number(yArray[ii]);
  718. const coordinates = getKakaoPosition(y_crdn, x_crdn);
  719. linePath.push(coordinates);
  720. }
  721. let strokeWeight = 5;
  722. let strokeWeightBack = 7;
  723. const level = _Level;
  724. if (level === 3) {
  725. strokeWeightBack = 6;
  726. } else if (level === 5 || level === 4) {
  727. strokeWeight = 3;
  728. strokeWeightBack = 5;
  729. } else if (level >= 6) {
  730. strokeWeight = 2;
  731. strokeWeightBack = 4;
  732. }
  733. this.polyBackLine = new kakao.maps.Polyline({
  734. path: linePath, // 선을 구성하는 좌표배열 입니다
  735. strokeWeight: strokeWeightBack, // 선의 두께 입니다
  736. strokeColor: '#eeeeee', // 선의 색깔입니다
  737. strokeOpacity: 1, // 선의 불투명도 입니다 1에서 0 사이의 값이며 0에 가까울수록 투명합니다
  738. strokeStyle: 'solid', // 선의 스타일입니다
  739. zIndex: 1
  740. });
  741. this.polyLine = new kakao.maps.Polyline({
  742. path: linePath, // 선을 구성하는 좌표배열 입니다
  743. strokeWeight: strokeWeight, // 선의 두께 입니다
  744. strokeColor: g_color.get(trafficObj.cmtr_grad_cd), // 선의 색깔입니다
  745. strokeOpacity: 1, // 선의 불투명도 입니다 1에서 0 사이의 값이며 0에 가까울수록 투명합니다
  746. strokeStyle: 'solid', // 선의 스타일입니다
  747. zIndex: 2
  748. });
  749. this.setVisibleMarker(_MapHandler['trafficFlag']);
  750. new kakao.maps.event.addListener(this.polyLine, 'mouseover', function (event) {
  751. this.setOptions({strokeColor: '#0000FF'});
  752. const iwContent =
  753. `<div class="trafficPop">
  754. <div class="traffic-speed ${trafficObj.cmtr_grad_cd}">
  755. <span class="traffic-name">${_self.NAME}</span>
  756. <span class="traffic-speed-info border-back ${trafficObj.cmtr_grad_cd}">${trafficObj.grad_nm}</span>
  757. </div>
  758. <div class="traffic-info">
  759. <span>${trafficObj.strt_nm_node} → ${trafficObj.end_nm_node}</span>
  760. <br>
  761. <span>소요시간 : </span>
  762. <span class="${trafficObj.cmtr_grad_cd}">약 ${textFormat(trafficObj.trvl_hh)}분 </span>
  763. <span>&nbsp; 속도 : </span>
  764. <span class="${trafficObj.cmtr_grad_cd}">약 ${textFormat(trafficObj.sped)}km/h</span>
  765. </div>
  766. </div>`;
  767. _self.infoWindow = new kakao.maps.CustomOverlay({
  768. map: _MapHandler.map,
  769. clickable: true,
  770. position: event.latLng,
  771. content: iwContent,
  772. xAnchor: -0.1,
  773. yAnchor: 1.1,
  774. zIndex: 4
  775. });
  776. });
  777. daum.maps.event.addListener(this.polyLine, 'mouseout', function () {
  778. this.setOptions({strokeColor: g_color.get(trafficObj.cmtr_grad_cd)});
  779. if (_self.infoWindow != null) _self.infoWindow.setMap(null);
  780. });
  781. }
  782. setVisibleMarker(isVisible) {
  783. const isShow = isVisible ? _MapHandler.map : null;
  784. this.polyBackLine.setMap(isShow);
  785. this.polyLine.setMap(isShow);
  786. }
  787. }
  788. /**
  789. * 간선도로 Object
  790. */
  791. class TbAtrdObj {
  792. constructor(obj) {
  793. this.ID = obj.atrd_id;
  794. this.NAME = obj.atrd_nm;
  795. this.X_CRDN = null;
  796. this.Y_CRDN = null;
  797. this.obj = obj;
  798. this.marker = null;
  799. this.imgSrc = '/images/icon/atrd';
  800. this.isClick = false;
  801. this.sped = 0;
  802. this.trvl_hh = 0;
  803. this.cnt = 0;
  804. this.infoWindow = null;
  805. this.init();
  806. }
  807. init() {
  808. if (this.obj.x_crdn_arr) {
  809. this.X_CRDN = this.obj.x_crdn_arr.split(",")[0];
  810. }
  811. if (this.obj.y_crdn_arr) {
  812. this.Y_CRDN = this.obj.y_crdn_arr.split(",")[0];
  813. }
  814. const name = this.NAME + " [" + this.obj.drct_nm + "]";
  815. this.marker = drawAtrdMakrer(this.obj.drct_cd, this.Y_CRDN, this.X_CRDN, name);
  816. this.click();
  817. // let _self = this;
  818. // new kakao.maps.event.addListener(this.marker, 'mouseover', function (event) {
  819. // let position = getKakaoPosition(_self.Y_CRDN, _self.X_CRDN);
  820. // const iwContent =
  821. // `<div class="trafficPop">
  822. // <div>
  823. // <span class="traffic-name">${_self.NAME}</span>
  824. // <span>[${_self.obj.drct_nm}]</span>
  825. // </div>
  826. // <div class="traffic-info">
  827. // <span>평균속도 : ${Math.round(_self.sped/_self.cnt)} km/h</span><br>
  828. // <span>통행시간 : ${textFormat(Math.round(_self.trvl_hh/_self.trvl_hh))}분 </span>
  829. // </div>
  830. // </div>`;
  831. // _self.infoWindow = new kakao.maps.CustomOverlay({
  832. // map: _MapHandler.map,
  833. // clickable: true,
  834. // position: position,
  835. // content: iwContent,
  836. // xAnchor: -0.1,
  837. // yAnchor: 1.1,
  838. // zIndex: 4
  839. // });
  840. // });
  841. // new kakao.maps.event.addListener(this.marker, 'mouseout', function (event) {
  842. // _self.infoWindow.setMap(null);
  843. // })
  844. }
  845. click() {
  846. this.setVisibleMarker(true);
  847. }
  848. setVisibleMarker(isVisible) {
  849. let visible = isVisible ? _MapHandler.map : null;
  850. this.marker.setMap(visible);
  851. this.isClick = isVisible;
  852. }
  853. close() {
  854. this.setVisibleMarker(false);
  855. }
  856. }
  857. /**
  858. * CCTV Object
  859. */
  860. class TbCCtvObj {
  861. constructor(obj) {
  862. this.ID = obj.cctv_mngm_nmbr;
  863. this.NAME = obj.istl_lctn_nm;
  864. this.X_CRDN = obj.x_crdn;
  865. this.Y_CRDN = obj.y_crdn;
  866. this.URL = obj.strm_http_addr;
  867. this.type = 'cctv';
  868. this.obj = obj;
  869. this.marker = null;
  870. this.infoWindow = null;
  871. this.iwContent = null;
  872. this.isClick = false;
  873. this.imgSrc = '/images/icon/cctv';
  874. this.timer = null;
  875. }
  876. init() {
  877. this.marker = createMarker(this, 'cctv');
  878. this.iwContent = `<div class="cctv-info-window">
  879. <div class="title">
  880. <div class="cctv-name-${this.ID}">${this.NAME}</div>
  881. <div onclick="infoWindowEvent('cctv', '${this.ID}', 'close')">X</div>
  882. </div>
  883. <div class="content">
  884. <div>
  885. <video id="video-${this.ID}" class="video-js" playsinline style="width: 100%; height: 100%;"></video>
  886. </div>
  887. <div>
  888. <div>※ CCTV영상은 30초간 제공됩니다.</div>
  889. <div class="continue-play">계속재생</div>
  890. </div>
  891. </div>
  892. </div>`;
  893. }
  894. setVisibleMarker(isVisible) {
  895. this.marker.setVisible(isVisible);
  896. }
  897. }
  898. /**
  899. * Parking Object
  900. */
  901. class TbParkingObj {
  902. constructor(obj) {
  903. this.ID = obj.parking_id;
  904. this.NAME = obj.parking_nm;
  905. this.X_CRDN = obj.x_crdn;
  906. this.Y_CRDN = obj.y_crdn;
  907. this.obj = obj;
  908. this.marker = null;
  909. this.infoWindow = null;
  910. this.iwContent = null;
  911. this.isClick = false;
  912. this.imgSrc = '/images/icon/parking';
  913. this.timer = null;
  914. this.type = 'parking';
  915. }
  916. init() {
  917. this.marker = createMarker(this, 'parking');
  918. this.iwContent = `<div class="parking-info-window">
  919. <div class="title">
  920. <div class="parking-name-${this.ID}">${this.NAME}</div>
  921. <div onclick="infoWindowEvent('parking', '${this.ID}', 'close')"></div>
  922. </div>
  923. <div class="content">
  924. <div class="row">
  925. <div>주차면수</div>
  926. <div title="주차면수 : ${this.obj.parking_num} 대">${this.obj.parking_num} 대</div>
  927. </div>
  928. <div class="row">
  929. <div>구분</div>
  930. <div title="구분 : ${this.obj.parking_type_desc}">${this.obj.parking_type_desc}</div>
  931. </div>
  932. <div class="row">
  933. <div>기본요금</div>
  934. <div title="기본요금 : ${this.obj.parking_fee_type_desc}">${this.obj.parking_fee_type_desc}</div>
  935. </div>
  936. <div class="row">
  937. <div>주소</div>
  938. <div title="주소 : ${this.obj.parking_addr}">${this.obj.parking_addr}</div>
  939. </div>
  940. </div>
  941. </div>`;
  942. }
  943. setVisibleMarker(isVisible) {
  944. this.marker.setVisible(isVisible);
  945. }
  946. }
  947. /**
  948. * VMS Object
  949. */
  950. class TbVmsObj {
  951. constructor(obj) {
  952. this.ID = obj.vms_ctlr_nmbr;
  953. this.NAME = obj.vms_nm;
  954. this.X_CRDN = obj.x_crdn;
  955. this.Y_CRDN = obj.y_crdn;
  956. this.obj = obj;
  957. this.marker = null;
  958. this.infoWindow = null;
  959. this.iwContent = null;
  960. this.isClick = false;
  961. this.imgSrc = '/images/icon/vms';
  962. this.timer = null;
  963. this.phaseArray = [];
  964. this.type = 'vms';
  965. }
  966. init() {
  967. this.marker = createMarker(this, 'vms');
  968. this.phaseArray = [];
  969. let width;
  970. let height;
  971. let isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
  972. switch (this.obj.vms_type_cd) {
  973. case 'VMC1':
  974. width = 400;
  975. height = 64;
  976. break;
  977. case 'VMC2':
  978. width = 384;
  979. height = 64;
  980. break;
  981. case 'VMC3':
  982. width = 288;
  983. height = 160;
  984. break;
  985. case 'VMC4':
  986. width = 256;
  987. height = 192;
  988. break;
  989. }
  990. const windowHeight = $(window).height();
  991. if (isMobile || windowHeight < 900) {
  992. width = width/2;
  993. height = height/2;
  994. }
  995. width = width +'px';
  996. height = height + 'px';
  997. const msg = this.obj.msg;
  998. if (!msg || msg.length === 0) {
  999. width = '256px';
  1000. height = '50px';
  1001. }
  1002. let iwContent =
  1003. `<div class="vms-info-window" style="width: calc(${width} + 10px); height: calc(${height} + 50px);">
  1004. <div class="title">
  1005. <div class="vms-name-${this.ID}">${this.NAME}</div>
  1006. <div onclick="infoWindowEvent('vms', ${this.ID}, 'close')">X</div>
  1007. </div>
  1008. <div class="content" style="width: ${width}; height: ${height};">`;
  1009. if (msg && msg.length > 0) {
  1010. for (let idx in msg) {
  1011. let msgObj = msg[idx];
  1012. let className = '';
  1013. if (idx === "0") {
  1014. className = 'active'
  1015. }
  1016. iwContent += `<img id="phase-${msgObj.phase}" class="${className}" style="width: ${width}; height: ${height};" src="/api/traffic/vms-dspl-image/${this.ID}/${msgObj.phase}">`;
  1017. this.phaseArray.push(msgObj.phase);
  1018. }
  1019. }
  1020. else {
  1021. iwContent += '표출 이미지 데이터가 없습니다.';
  1022. }
  1023. iwContent += `</div></div>`;
  1024. this.iwContent = iwContent;
  1025. }
  1026. setVisibleMarker(isVisible) {
  1027. this.marker.setVisible(isVisible);
  1028. }
  1029. }
  1030. /**
  1031. * 돌발정보 Object
  1032. */
  1033. class TbIncdObj {
  1034. constructor(obj) {
  1035. this.ID = obj.incd_ocrr_id;
  1036. this.NAME = obj.incd_titl;
  1037. this.X_CRDN = obj.x_crdn;
  1038. this.Y_CRDN = obj.y_crdn;
  1039. this.obj = obj;
  1040. this.marker = null;
  1041. this.infoWindow = null;
  1042. this.isClick = false;
  1043. this.imgSrc = '/images/icon/incd';
  1044. this.iwContent = null;
  1045. this.type = 'incident';
  1046. }
  1047. init() {
  1048. this.marker = createMarker(this, 'incident');
  1049. this.iwContent = `<div class="incident-info-window">
  1050. <div class="title">
  1051. <div class="incident-name-${this.ID}">${this.NAME}</div>
  1052. <div onclick="infoWindowEvent('incident', '${this.ID}', 'close')">X</div>
  1053. </div>
  1054. <div class="content">
  1055. <div>
  1056. 위치 : ${this.obj.road_nm}
  1057. </div>
  1058. <div>
  1059. 설명 : ${this.obj.incd_expl}
  1060. </div>
  1061. <div>
  1062. 기간 : ${this.obj.incd_strt_dt} ~ ${this.obj.incd_end_prar_dt}
  1063. </div>
  1064. </div>
  1065. </div>`;
  1066. }
  1067. setVisibleMarker(isVisible) {
  1068. this.marker.setVisible(isVisible);
  1069. }
  1070. }
  1071. /**
  1072. * 스마트 교차로 Object
  1073. */
  1074. class IntersectionObj {
  1075. constructor(obj) {
  1076. this.ID = obj.ixr_id;
  1077. this.NAME = obj.ixr_nm;
  1078. this.X_CRDN = obj.x_crdn;
  1079. this.Y_CRDN = obj.y_crdn;
  1080. this.obj = obj;
  1081. this.marker = null;
  1082. this.infoWindow = null;
  1083. this.isClick = false;
  1084. this.imgSrc = '/images/icon/intersection';
  1085. this.detail = [];
  1086. this.type = 'intersection';
  1087. }
  1088. init() {
  1089. let imageSrc = this.imgSrc + '.png', // 마커이미지의 주소입니다
  1090. size = _size[_Level],
  1091. imageSize = new kakao.maps.Size(size, size), // 마커이미지의 크기입니다
  1092. imageOption = {
  1093. offset: new kakao.maps.Point(size/2, size/2),
  1094. alt: this.NAME,
  1095. };
  1096. // 마커의 이미지정보를 가지고 있는 마커이미지를 생성합니다
  1097. let markerImage = new kakao.maps.MarkerImage(imageSrc, imageSize, imageOption),
  1098. markerPosition = getKakaoPosition(this.Y_CRDN, this.X_CRDN); // 마커가 표시될 위치입니다
  1099. this.marker = new kakao.maps.Marker(
  1100. {map: _MapHandler.map, position: markerPosition, image: markerImage, zindex: 10, clickable: true, title : this.NAME}
  1101. );
  1102. const level = _Level;
  1103. const isVisible = (level > 2 && _MapHandler['intersectionFlag']);
  1104. this.marker.setVisible(isVisible);
  1105. let _self = this;
  1106. new kakao.maps.event.addListener(this.marker, 'click', ()=> _MapHandler.click('intersection', _self.ID));
  1107. }
  1108. setVisibleMarker(isVisible) {
  1109. if (_Level <= 2) isVisible = false;
  1110. this.marker.setVisible(isVisible);
  1111. }
  1112. }
  1113. /**
  1114. * 스마트교차로 카메라 Object
  1115. */
  1116. class IntersectionCameraObj {
  1117. constructor(obj) {
  1118. this.ID = obj.cmra_id + '_' + obj.drct_dvsn_cd;
  1119. this.NAME = obj.drct_lctn;
  1120. this.X_CRDN = obj.cmra_x_crdn;
  1121. this.Y_CRDN = obj.cmra_y_crdn;
  1122. this.URL = obj.hmpg_cmra_url;
  1123. this.obj = obj;
  1124. this.marker = null;
  1125. this.infoWindow = null;
  1126. this.iwContent = null;
  1127. this.isClick = false;
  1128. this.timer = null;
  1129. this.polyline = null;
  1130. this.type = 'intersectionCamera';
  1131. }
  1132. init() {
  1133. this.marker = createIntersectionCameraMarker(this);
  1134. this.iwContent =
  1135. `<div class="cctv-info-window">
  1136. <div class="title">
  1137. <div class="intersectionCamera-name-${this.ID}">${this.NAME}</div>
  1138. <div class="close-window" onclick="infoWindowEvent('intersectionCamera', '${this.ID}', 'close')">X</div>
  1139. </div>
  1140. <div class="content">
  1141. <div>
  1142. <video id="video-${this.ID}" class="video-js" style="width: 100%; height: 100%;"></video>
  1143. </div>
  1144. <div>
  1145. <div>※ CCTV영상은 30초간 제공됩니다.</div>
  1146. <div class="continue-play">계속재생</div>
  1147. </div>
  1148. </div>
  1149. </div>`;
  1150. }
  1151. setVisibleMarker(isVisible) {
  1152. const visible = isVisible && _Level <= 2 ? _MapHandler.map : null;
  1153. this.marker.setMap(visible);
  1154. this.polyline.setMap(visible);
  1155. }
  1156. }
  1157. /**
  1158. * 인포윈도우 이벤트
  1159. * @param type 시설물 유형
  1160. * @param id 요소 ID
  1161. * @param event 이벤트 종류 (click, close)
  1162. */
  1163. function infoWindowEvent(type, id, event) {
  1164. _MapHandler[event](type, id);
  1165. }
  1166. let isHide = false
  1167. /**
  1168. * 좌측 목록 토글 이벤트
  1169. */
  1170. function toggleEvent() {
  1171. const $listArea = $('.left-list-area');
  1172. const $toggleButton = $('.toggle-button');
  1173. if (!isHide) {
  1174. $toggleButton.animate({
  1175. left: 0
  1176. }, 'slow');
  1177. $listArea .animate({
  1178. left: -$listArea.width()
  1179. }, 'slow');
  1180. $toggleButton.text('>');
  1181. }
  1182. else {
  1183. $toggleButton.animate({
  1184. left: $listArea.width()
  1185. }, 'slow');
  1186. $listArea .animate({
  1187. left: 0
  1188. }, 'slow');
  1189. $toggleButton.text('<');
  1190. }
  1191. isHide = !isHide;
  1192. }
  1193. window.addEventListener('resize', function(event) {
  1194. if ($(this).width() > 450) {
  1195. const $toggleButton = $('.toggle-button');
  1196. const $listArea = $('.left-list-area');
  1197. const left = $toggleButton.offset().left;
  1198. const listLeft = $listArea.offset().left;
  1199. if ($(this).width() >= 920) {
  1200. if (left > 0 && left < 400) {
  1201. $toggleButton.css('left', 400);
  1202. }
  1203. if (listLeft > -400 && listLeft < 0) {
  1204. $listArea.css('left', -400);
  1205. }
  1206. }
  1207. else {
  1208. if (left > 0 && left > 275) {
  1209. $toggleButton.css('left', 275);
  1210. }
  1211. if (listLeft < -273) {
  1212. $listArea.css('left', -273);
  1213. }
  1214. }
  1215. }
  1216. })
  1217. /**
  1218. * 시설물 마커 초기화
  1219. * @param obj 시설물 객체
  1220. * @returns {kakao.maps.Marker}
  1221. */
  1222. function createMarker(obj, type) {
  1223. let map = _MapHandler.map;
  1224. let imageSrc = obj.imgSrc + '1.png', // 마커이미지의 주소입니다
  1225. size = _size[map.getLevel()],
  1226. imageSize = new kakao.maps.Size(size, size), // 마커이미지의 크기입니다
  1227. imageOption = {
  1228. offset: new kakao.maps.Point(size/2, size/2),
  1229. alt: obj.NAME,
  1230. };
  1231. // 마커의 이미지정보를 가지고 있는 마커이미지를 생성합니다
  1232. let markerImage = new kakao.maps.MarkerImage(imageSrc, imageSize, imageOption),
  1233. markerPosition = getKakaoPosition(obj.Y_CRDN, obj.X_CRDN); // 마커가 표시될 위치입니다
  1234. let marker = new kakao.maps.Marker(
  1235. {map: map, position: markerPosition, image: markerImage, zindex: 10, clickable: true, title : obj.NAME}
  1236. );
  1237. let flag = _MapHandler[type+'Flag'];
  1238. marker.setVisible(flag);
  1239. kakao.maps.event.addListener(marker, 'mouseover', function () {
  1240. if (!obj.isClick) {
  1241. setMarkerImage(obj, 2, false);
  1242. }
  1243. });
  1244. kakao.maps.event.addListener(marker, 'mouseout', function () {
  1245. if (!obj.isClick) {
  1246. setMarkerImage(obj, 1, false)
  1247. }
  1248. });
  1249. kakao.maps.event.addListener(marker, 'click', ()=> _MapHandler.click(type, obj.ID));
  1250. return marker;
  1251. }
  1252. /**
  1253. * 스마트 교차로 카메라 마커 초기화
  1254. * @param obj 스마트 교차로 카메라 객체
  1255. * @returns {kakao.maps.Marker}
  1256. */
  1257. function createIntersectionCameraMarker(obj) {
  1258. const position = getKakaoPosition(obj.Y_CRDN, obj.X_CRDN);
  1259. const content = $('<div id="camera_'+obj.ID+'" title="'+obj.NAME+'">');
  1260. const angle = Number(obj.obj.cmra_angn);
  1261. content.css(
  1262. {
  1263. width: '38.45px',
  1264. height: '38.45px',
  1265. backgroundImage:'url(/images/icon/intersection-cctv.png)',
  1266. backgroundSize : '38.45px 38.45px',
  1267. backgroundRepeat: 'no-repeat',
  1268. backgroundPosition : 'center',
  1269. transform : 'rotate(' + angle +'deg)'
  1270. });
  1271. const marker = new kakao.maps.CustomOverlay({
  1272. content: content[0],
  1273. position: position,
  1274. zindex: 15,
  1275. });
  1276. const linePath1 = [obj.obj.start_x, obj.obj.start_y]
  1277. const linePath2 = [obj.obj.end_x, obj.obj.end_y];
  1278. const color = ['#888888', '#15B337', '#15B337', '#15B337', '#FFAA00', '#FFAA00', '#EB260C', '#EB260C', '#EB260C'];
  1279. obj.polyline = new kakao.maps.Polyline({
  1280. path: [
  1281. getKakaoPosition(linePath1[1], linePath1[0]),
  1282. getKakaoPosition(linePath2[1], linePath2[0]),
  1283. ],
  1284. strokeWeight: 10,
  1285. strokeColor: color[obj.obj.acrd_los],
  1286. strokeOpacity: 1,
  1287. strokeStyle: 'solid',
  1288. endArrow: true,
  1289. name : obj.NAME,
  1290. });
  1291. if (_Level <= 2 && _MapHandler['intersectionFlag']){
  1292. marker.setMap(_MapHandler.map);
  1293. obj.polyline.setMap(_MapHandler.map);
  1294. }
  1295. content.on('click', ()=> {
  1296. obj.click();
  1297. });
  1298. return marker;
  1299. }
  1300. /**
  1301. * 시설물 이미지 유형 변경 이벤트
  1302. * @param obj 시설물 객체
  1303. * @param type 시설물 이미지 유형
  1304. */
  1305. function setMarkerImage(obj, type, isAtrd) {
  1306. const currentLevel = _Level;
  1307. let size = _size[currentLevel];
  1308. let point1 = size/2;
  1309. let point2 = size/2;
  1310. if (isAtrd) {
  1311. size = ( currentLevel >= 7 ) ? 24 : 48;
  1312. point1 = size/2;
  1313. point2 = size;
  1314. }
  1315. const imageSize = new kakao.maps.Size(size, size);
  1316. const imageSrc = obj.imgSrc + type +'.png';
  1317. const imageOption = {
  1318. offset: new kakao.maps.Point(point1, point2),
  1319. alt: obj.NAME
  1320. };
  1321. const markerImage = new kakao.maps.MarkerImage(imageSrc, imageSize, imageOption);
  1322. obj.marker.setImage(markerImage);
  1323. }
  1324. /**
  1325. * 선택 리스트 스크롤 높이 반환 이벤트
  1326. * @param selectIndex 선택 인덱스
  1327. * @returns {number} 스크롤 높이
  1328. */
  1329. function getScrollTop(selectIndex) {
  1330. let scrollTop = 0;
  1331. for (let ii=0; ii < selectIndex; ii++) {
  1332. let height = $('.left-list-area .list-content.list').children().eq(ii).css('height');
  1333. if (height) {
  1334. height = Number(height.replace('px', ''));
  1335. if (!isNaN(height)) {
  1336. scrollTop += height;
  1337. }
  1338. }
  1339. }
  1340. return scrollTop;
  1341. }
  1342. /**
  1343. * 좌측 리스트 선택 시 스크롤 변경 이벤트
  1344. * @param flag
  1345. * @param array
  1346. * @param id
  1347. */
  1348. function moveToScroll(flag, array, id) {
  1349. if (flag) {
  1350. let selectIndex = array.findIndex((obj)=> obj.ID == id);
  1351. let scrollTop = getScrollTop(selectIndex);
  1352. $('.left-list-area .list-content.list').animate({
  1353. scrollTop : scrollTop + 'px'
  1354. });
  1355. $('.mobile-select').val(id);
  1356. }
  1357. }
  1358. /**
  1359. * 시설물 데이터 처리 메서드
  1360. * @param jsonData 수신 데이터
  1361. * @param array 시설물 Object Array List
  1362. * @param facilityClass 시설물 Object Class
  1363. * @param listFlag 시설물 리스트 목록 표출 플래그
  1364. * @param type 시설물 유형
  1365. * @returns {*[]} 시설물 Object Array List
  1366. */
  1367. function receiveFacilityData(jsonData, facilityClass, type) {
  1368. if (_MapHandler[type].length > 0) {
  1369. _MapHandler[type].forEach((obj)=>{
  1370. if (obj.marker) {
  1371. obj.marker.setMap(null);
  1372. }
  1373. if (obj.polyline) {
  1374. obj.polyline.setMap(null);
  1375. }
  1376. });
  1377. _MapHandler[type] = [];
  1378. }
  1379. let listStr = "";
  1380. let mobileStr = "";
  1381. if (jsonData && jsonData.length > 0) {
  1382. jsonData.forEach((obj)=>{
  1383. const marker = new facilityClass(obj);
  1384. marker.init();
  1385. if (type === 'intersection') {
  1386. if (obj.detail && obj.detail.length > 0) {
  1387. obj.detail.forEach((cameraObj)=>{
  1388. const camera = new IntersectionCameraObj(cameraObj);
  1389. camera.init();
  1390. _MapHandler[type + 'Camera'].push(camera);
  1391. })
  1392. }
  1393. }
  1394. listStr += `<li id="${type}-${marker.ID}" onclick="infoWindowEvent('${type}', '${marker.ID}' , 'click')">${marker.NAME}</li>`
  1395. mobileStr += `<option value="${marker.ID}">${marker.NAME}</option>`;
  1396. _MapHandler[type].push(marker);
  1397. });
  1398. if (_MapHandler[type + 'Flag']) {
  1399. _MapHandler.show(type);
  1400. }
  1401. }
  1402. if (_MapHandler[type + 'ListFlag'] === true) {
  1403. const listSection = $('.left-list-area .list-content.list');
  1404. listSection.empty();
  1405. listSection.html(listStr);
  1406. const $mobileSelect = $('.mobile-select');
  1407. $mobileSelect.append($(mobileStr));
  1408. $mobileSelect.on('change', function(){
  1409. const id = $(this).val();
  1410. if (id && id !== "-") {
  1411. infoWindowEvent(type, id , 'click');
  1412. }
  1413. })
  1414. }
  1415. }
  1416. /**
  1417. * 맵 중앙 아이콘 위 위치 좌표
  1418. * @param infoWindow
  1419. * @returns {number[]}
  1420. */
  1421. function getInfoWidowPosition(infoWindow) {
  1422. const map = $('#map');
  1423. let mapHalfW = map.innerWidth() / 2;
  1424. let mapHalfH = map.innerHeight() / 2;
  1425. let mapTop = map.offset().top;
  1426. let halfW = infoWindow.innerWidth() / 2;
  1427. let height = infoWindow.innerHeight();
  1428. let left = mapHalfW - halfW;
  1429. let iconH = _size[_Level];
  1430. let top = mapTop + mapHalfH - height - iconH;
  1431. return [top, left];
  1432. }
  1433. /**
  1434. * 맵 드래그 적용
  1435. */
  1436. function setInfoWindowPositionWidthDraggable(markerObj, type) {
  1437. const {infoWindow, ID} = markerObj;
  1438. const position = getInfoWidowPosition(infoWindow);
  1439. let top = position[0];
  1440. let left = position[1];
  1441. infoWindow.css({
  1442. top : top + 'px',
  1443. left : left + 'px',
  1444. position : 'absolute',
  1445. zIndex : 999,
  1446. });
  1447. infoWindow.draggable({containment : 'body', handle: '.'+ type + '-name-' + ID});
  1448. }
  1449. /**
  1450. * 카카오 포지션 지정
  1451. */
  1452. function getKakaoPosition(yCoordinate, xCoordinate) {
  1453. return new kakao.maps.LatLng(Number(yCoordinate), Number(xCoordinate));
  1454. }
  1455. /**
  1456. * videoJs 객체 생성
  1457. */
  1458. function createVideoJs(id, url) {
  1459. let video = videojs("video-" + id, {
  1460. sources: [
  1461. {
  1462. src: url,
  1463. type: "application/x-mpegURL",
  1464. crossorigin: "anonymous",
  1465. },
  1466. ],
  1467. responsive: false,
  1468. autoplay: true,
  1469. muted: true,
  1470. preload: "metadata",
  1471. });
  1472. video.on('error', ()=>{
  1473. if (video.error().code === 4) {
  1474. video.pause();
  1475. video.dispose();
  1476. const $errorBox = $('.content > div:nth-child(1)');
  1477. $errorBox.append($('<img src="/images/icon/error.png" alt="스트리밍 오류 이미지">'));
  1478. $errorBox.css({
  1479. display : 'flex',
  1480. alignItems : 'center',
  1481. justifyContent : 'center',
  1482. });
  1483. video = null;
  1484. }
  1485. });
  1486. return video;
  1487. }
  1488. class MapHandler {
  1489. constructor(id) {
  1490. this.selectedObj = null;
  1491. this.map = null;
  1492. this.mapElement = id;
  1493. this.atrd = [];
  1494. }
  1495. init () {
  1496. //시설물별 배열, 토글 플래그, 리스트 플래그 생성
  1497. _FacilityArray.forEach((type)=>{
  1498. this[type] = [];
  1499. this[type + 'Flag'] = false;
  1500. this[type + 'ListFlag'] = false;
  1501. });
  1502. const container = document.getElementById(this.mapElement); //지도를 담을 영역의 DOM 레퍼런스
  1503. const options = { //지도를 생성할 때 필요한 기본 옵션
  1504. center: getKakaoPosition(36.0191816, 129.3432983), //지도의 중심좌표.
  1505. level: _Level,
  1506. maxLevel: 9,
  1507. minLevel: 1,
  1508. disableDoubleClickZoom: true
  1509. };
  1510. this.map = new kakao.maps.Map(container, options);
  1511. const mapTypeControl = new kakao.maps.MapTypeControl();
  1512. this.map.addControl(mapTypeControl, kakao.maps.ControlPosition.TOPRIGHT);
  1513. const zoomControl = new kakao.maps.ZoomControl();
  1514. this.map.addControl(zoomControl, kakao.maps.ControlPosition.RIGHT);
  1515. const handler = this;
  1516. /**
  1517. * Map Zoom Level Change 이벤트 (이미지 사이즈, 스마트 교차로 이미지 토글, 소통정보 정보 변경)
  1518. */
  1519. kakao.maps.event.addListener(this.map, 'zoom_changed', function () {
  1520. _Level = this.getLevel();
  1521. const zoomChangeArray = ['cctv', 'vms', 'parking', 'incident'];
  1522. zoomChangeArray.forEach((type)=>{
  1523. const markerArr = handler[type];
  1524. const markerFlag = handler[type + 'Flag'];
  1525. markerSizeChangeWithZoomLevel(markerArr, markerFlag);
  1526. });
  1527. intersectionMarkerChangeWithZoomLevel();
  1528. intersectionCameraChangeWidthZoomLevel();
  1529. if (handler['atrd'].length > 0) {
  1530. atrdMarkerResize();
  1531. }
  1532. getVertex();
  1533. });
  1534. /**
  1535. * 좌표 데이터가의 양이 많으므로 이동 할때마다 영역별 소통정보를 새로 그려줌
  1536. */
  1537. kakao.maps.event.addListener(this.map, 'dragend', function() {
  1538. getVertex();
  1539. });
  1540. }
  1541. //마커 클릭 이벤트
  1542. click(type, id) {
  1543. const markerArr = this[type]; // 시설물 배열
  1544. const markerFlag = this[ type + 'Flag']; // 시설물 토글 플래그
  1545. const markerListFlag = this[ type + 'ListFlag']; // 시설물 토글 플래그
  1546. const atrdArr = this['atrd'];
  1547. if (atrdArr && atrdArr.length > 0) {
  1548. atrdArr.forEach((atrd)=>{
  1549. atrd.close();
  1550. });
  1551. this['atrd'] = [];
  1552. _AtrdData = [];
  1553. const $selectedLi = $('.left-list-area .list-content.list > li.click');
  1554. if ($selectedLi) {
  1555. $selectedLi.removeClass('click');
  1556. }
  1557. }
  1558. let selectObj = this.selectedObj; // 이전 클릭 객체
  1559. let clickObj = this.getSelectObj(markerArr, id); // 현재 클릭 객체
  1560. if (selectObj) {
  1561. if (selectObj === clickObj && type !== 'intersection') {
  1562. return;
  1563. }
  1564. _MapHandler.close(selectObj.type, selectObj.ID);
  1565. }
  1566. const coordinates = getKakaoPosition(clickObj.Y_CRDN, clickObj.X_CRDN);
  1567. this.selectedObj = clickObj;
  1568. const selectedLi = $('#'+type+'-' + clickObj.ID);
  1569. selectedLi.addClass('click');
  1570. selectedLi.focus();
  1571. this.map.setCenter(coordinates);
  1572. if (this['trafficFlag']) {
  1573. getVertex();
  1574. }
  1575. if (clickObj.iwContent) { // 인포 윈도우가 있을때만 실행
  1576. clickObj.infoWindow = $(clickObj.iwContent);
  1577. $('body').append(clickObj.infoWindow);
  1578. setInfoWindowPositionWidthDraggable(clickObj, type);
  1579. }
  1580. if (clickObj.URL) { // Url 유무로 영상 이벤트 실행
  1581. this.videoEvent(clickObj);
  1582. }
  1583. if (type === 'vms') { // vms 일 경우 이미지 표출실행
  1584. this.vmsEvent(clickObj);
  1585. }
  1586. if (type === 'intersection') { // 스마트 교차로는 줌레벨 2로 변경
  1587. this.map.setLevel(2);
  1588. }
  1589. else if (clickObj.imgSrc) { // img src 값이 있는 객체만 클릭 이미지 변경
  1590. setMarkerImage(clickObj, 2, false);
  1591. }
  1592. clickObj.isClick = true;
  1593. if (markerListFlag) {
  1594. moveToScroll(markerFlag, markerArr, clickObj.ID); // 클릭 시 리스트 이동
  1595. }
  1596. }
  1597. //마커 이벤트 종료
  1598. close(type, id) {
  1599. const markerArr = this[type];
  1600. const listFlag = this[type + 'ListFlag'];
  1601. const closeObj = this.getSelectObj(markerArr, id);
  1602. if (closeObj) {
  1603. closeObj.isClick = false;
  1604. this.selectedObj = null;
  1605. if (!type.includes('intersection')) { // 스마트교차로 아닌 화면은 이미지를 원래대로 돌린다.
  1606. setMarkerImage(closeObj, 1, false);
  1607. }
  1608. let oldPlayer = document.getElementById("video-" + closeObj.ID);
  1609. let selectedLi = $("#" + type + "-" + closeObj.ID);
  1610. if (selectedLi.hasClass('click')) { // 선택 리스트가 있는지 여부
  1611. selectedLi.removeClass('click');
  1612. }
  1613. if (listFlag) { // 리스트 플래그 있는지 여부
  1614. $('.mobile-select').val("-");
  1615. }
  1616. if (oldPlayer) { // 켜져있던 영상이 있는지 여부
  1617. videojs(oldPlayer).dispose();
  1618. }
  1619. if (closeObj.infoWindow) { // 인포 윈도우를 화면에 올려놨는지
  1620. closeObj.infoWindow.remove();
  1621. closeObj.infoWindow = null;
  1622. }
  1623. if (closeObj.timer) { // 인터벌 된 객체가 있는지
  1624. clearTimeout(closeObj.timer);
  1625. }
  1626. }
  1627. }
  1628. //선택 객체 찾기
  1629. getSelectObj(array, id) {
  1630. let idx = array.findIndex(obj => obj.ID.toString() === id.toString());
  1631. return array[idx];
  1632. }
  1633. // 마커 보이기
  1634. show(type) {
  1635. this[type].forEach(obj => obj.setVisibleMarker(true));
  1636. this[type + 'Flag'] = true;
  1637. }
  1638. // 마커 숨기기
  1639. hide(type) {
  1640. this[type].forEach(obj => {
  1641. obj.setVisibleMarker(false);
  1642. if (obj.isClick === true) {
  1643. _MapHandler.close(type, obj.ID);
  1644. }
  1645. });
  1646. this[type + 'Flag'] = false;
  1647. }
  1648. //영상 이벤트
  1649. videoEvent(obj) {
  1650. let video = createVideoJs(obj.ID, obj.URL);
  1651. obj.timer = setTimeout(()=>{
  1652. if (video) {
  1653. video.pause();
  1654. }
  1655. }, CCTV_DISPLAY_TIME);
  1656. $('.continue-play').on('click', ()=>{
  1657. if (obj.timer) {
  1658. setTimeout(obj.timer);
  1659. }
  1660. if (video) {
  1661. video.play();
  1662. obj.timer = setTimeout(()=>{
  1663. video.pause();
  1664. }, CCTV_DISPLAY_TIME);
  1665. }
  1666. });
  1667. }
  1668. //vms 이미지 표출 이벤트
  1669. vmsEvent(obj) {
  1670. let cnt = 1;
  1671. if (obj.phaseArray.length > 0) {
  1672. obj.timer = setInterval(()=>{
  1673. if (cnt === obj.phaseArray.length) {
  1674. cnt = 0;
  1675. }
  1676. const activeImage = $('.vms-info-window .content img.active');
  1677. if (activeImage[0]) {
  1678. activeImage.removeClass('active');
  1679. }
  1680. $("#phase-" + obj.phaseArray[cnt]).addClass('active');
  1681. cnt++;
  1682. }, VMS_DISPLAY_TIME);
  1683. }
  1684. }
  1685. }