forked from pknu-wap/2023_1_WEB8_NaPugation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.html
198 lines (174 loc) · 5.6 KB
/
route.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>simpleMap</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script
src="https://apis.openapi.sk.com/tmap/jsv2?version=1&appKey=Hz2FRQ7V1LaHuZxpL92Fn7UPuG3RndEq1ENh2wA6"></script>
<script type="text/javascript">
var map;
var marker_s, marker_e, marker_p1, marker_p2;
var totalMarkerArr = [];
var drawInfoArr = [];
var resultdrawArr = [];
function initTmap() {
// 1. 지도 띄우기
map = new Tmapv2.Map("map_div", {
center : new Tmapv2.LatLng(35.13399576311834, 129.1055538706261 ),
width : "100%",
height : "400px",
zoom : 17,
zoomControl : true,
scrollwheel : true
});
// 2. 시작, 도착 심볼찍기
// 시작
marker_s = new Tmapv2.Marker(
{
position : new Tmapv2.LatLng( 35.13537525752147, 129.10291822980423),
icon : "http://tmapapi.sktelecom.com/upload/tmap/marker/pin_r_m_s.png",
iconSize : new Tmapv2.Size(24, 38),
map : map
});
// 도착
marker_e = new Tmapv2.Marker(
{
position : new Tmapv2.LatLng(35.13130027314456,129.10613164272561 ),
icon : "http://tmapapi.sktelecom.com/upload/tmap/marker/pin_r_m_e.png",
iconSize : new Tmapv2.Size(24, 38),
map : map
});
// 3. 경로탐색 API 사용요청
var headers = {};
headers["appKey"]="Hz2FRQ7V1LaHuZxpL92Fn7UPuG3RndEq1ENh2wA6";
$.ajax({
method : "POST",
headers : headers,
url : "https://apis.openapi.sk.com/tmap/routes/pedestrian?version=1&format=json&callback=result",
async : false,
data : {
"startX" : "129.10291822980423",
"startY" : "35.13537525752147",
"endX" : "129.10613164272561 ",
"endY" : "35.13130027314456",
"reqCoordType" : "WGS84GEO",
"resCoordType" : "EPSG3857",
"startName" : "출발지",
"endName" : "도착지"
},
success : function(response) {
var resultData = response.features;
//결과 출력
var tDistance = "총 거리 : "
+ ((resultData[0].properties.totalDistance) / 1000)
.toFixed(1) + "km,";
var tTime = " 총 시간 : "
+ ((resultData[0].properties.totalTime) / 60)
.toFixed(0) + "분";
$("#result").text(tDistance + tTime);
//기존 그려진 라인 & 마커가 있다면 초기화
if (resultdrawArr.length > 0) {
for ( var i in resultdrawArr) {
resultdrawArr[i]
.setMap(null);
}
resultdrawArr = [];
}
drawInfoArr = [];
for ( var i in resultData) { //for문 [S]
var geometry = resultData[i].geometry;
var properties = resultData[i].properties;
var polyline_;
if (geometry.type == "LineString") {
for ( var j in geometry.coordinates) {
// 경로들의 결과값(구간)들을 포인트 객체로 변환
var latlng = new Tmapv2.Point(
geometry.coordinates[j][0],
geometry.coordinates[j][1]);
// 포인트 객체를 받아 좌표값으로 변환
var convertPoint = new Tmapv2.Projection.convertEPSG3857ToWGS84GEO(
latlng);
// 포인트객체의 정보로 좌표값 변환 객체로 저장
var convertChange = new Tmapv2.LatLng(
convertPoint._lat,
convertPoint._lng);
// 배열에 담기
drawInfoArr.push(convertChange);
}
} else {
var markerImg = "";
var pType = "";
var size;
if (properties.pointType == "S") { //출발지 마커
markerImg = "http://tmapapi.sktelecom.com/upload/tmap/marker/pin_r_m_s.png";
pType = "S";
size = new Tmapv2.Size(24, 38);
} else if (properties.pointType == "E") { //도착지 마커
markerImg = "http://tmapapi.sktelecom.com/upload/tmap/marker/pin_r_m_e.png";
pType = "E";
size = new Tmapv2.Size(24, 38);
} else { //각 포인트 마커
markerImg = "http://topopen.tmap.co.kr/imgs/point.png";
pType = "P";
size = new Tmapv2.Size(8, 8);
}
// 경로들의 결과값들을 포인트 객체로 변환
var latlon = new Tmapv2.Point(
geometry.coordinates[0],
geometry.coordinates[1]);
// 포인트 객체를 받아 좌표값으로 다시 변환
var convertPoint = new Tmapv2.Projection.convertEPSG3857ToWGS84GEO(
latlon);
var routeInfoObj = {
markerImage : markerImg,
lng : convertPoint._lng,
lat : convertPoint._lat,
pointType : pType
};
// Marker 추가
marker_p = new Tmapv2.Marker(
{
position : new Tmapv2.LatLng(
routeInfoObj.lat,
routeInfoObj.lng),
icon : routeInfoObj.markerImage,
iconSize : size,
map : map
});
}
}//for문 [E]
drawLine(drawInfoArr);
},
error : function(request, status, error) {
console.log("code:" + request.status + "\n"
+ "message:" + request.responseText + "\n"
+ "error:" + error);
}
});
}
function addComma(num) {
var regexp = /\B(?=(\d{3})+(?!\d))/g;
return num.toString().replace(regexp, ',');
}
function drawLine(arrPoint) {
var polyline_;
polyline_ = new Tmapv2.Polyline({
path : arrPoint,
strokeColor : "#DD0000",
strokeWeight : 6,
map : map
});
resultdrawArr.push(polyline_);
}
</script>
</head>
<body onload="initTmap();">
<!-- 190430 기존 지도를 모두 이미지 처리 위해 주석 처리 S -->
<div id="map_wrap" class="map_wrap3">
<div id="map_div"></div>
</div>
<div class="map_act_btn_wrap clear_box"></div>
<p id="result"></p>
</body>
</html>