traffic.js 60 KB

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