-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongTermCareMap.html
More file actions
334 lines (300 loc) · 13.2 KB
/
longTermCareMap.html
File metadata and controls
334 lines (300 loc) · 13.2 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<title>長照ABC據點</title>
<style>
h3 {
margin: 5px auto;
text-align: center;
}
#map {
height: 100vh;
}
div#data {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
div#reference p {
margin: 0;
}
div.tableArea {
overflow: auto;
max-height: 300px;
}
tbody>tr>td:last-child {
width: 40%;
}
tbody>tr>td:not(last-child) {
width: 30%;
}
tbody>tr>td:hover {
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-6">
<div id="map"></div>
</div>
<div class="col-6" id="data">
<div id="selection">
<h3>長照ABC據點</h3>
<!-- <label for="cties"></label> -->
<select class="form-select my-3" id="cities">
<option value="" selected>---請選擇縣市---</option>
</select>
<!-- <label for="cties"></label> -->
<select class="form-select my-3" id="districts">
<option value="" selected>---請選擇區域---</option>
</select>
<!-- <label for="insType"></label> -->
<select class="form-select my-3" id="insType">
<option value="">---請選擇長照機構類型---</option>
<option value="A">社區整合型服務中心(A)</option>
<option value="B">複合型服務中心(B)</option>
<option value="C">巷弄長照站(C)</option>
</select>
</div>
<div class="tableArea">
<table class="table table-info my-2">
<thead>
<tr>
</tr>
</thead>
<tbody>
<tr></tr>
</tbody>
</table>
</div>
<div id="reference">
<p>資料來源:政府資料開放平臺 - 長照ABC據點</p>
<p>資料網址:https://data.gov.tw/dataset/88270</p>
<p>取得日期:110/06/30</p>
</div>
</div>
</div>
</div>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"
integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js"
integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin="" />
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.Default.css" />
<script src="https://unpkg.com/leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"
integrity="sha512-bZS47S7sPOxkjU/4Bt0zrhEtWx0y0CRkhEp8IckzK+ltifIIE9EMIMTuT/mEzoIMewUINruDBIR/jJnbguonqQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
let map = L.map("map").setView([24.8199265622353, 120.96874010169432], 8.5);
let osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
let osm = new L.TileLayer(osmUrl, { minZoom: 8, maxZoom: 19 });
map.addLayer(osm);
let markers = L.markerClusterGroup();
let insRequest = axios.get("https://raw.githubusercontent.com/chilinglee/FileStorage/main/longTermCare.json")
let areaRequest = axios.get("https://raw.githubusercontent.com/chilinglee/FileStorage/main/TaiwanAreas.json");
//換顏色
var redIcon = new L.Icon({
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-green.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
var goldIcon = new L.Icon({
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-green.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
var greenIcon = new L.Icon({
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-green.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
let careData = [];
let areaData = [];
let areaSelection = [];
window.onload = function () {
Promise.all([insRequest, areaRequest])
.then(result => {
[careData, areaData] = result;
careData = careData.data;
console.log(careData);
areaData = areaData.data;
careData = careData.map(x => {
//台灣縣市區域 縣市名稱(3字)+區域名稱(2-4字):5-7字;應該可以只對照前5個字就好
let ctd = Array.from(x["地址全址"]).slice(0, 5).join("");
let cityOrCounty = Array.from(x["地址全址"]).slice(0, 3).join("");
return {
"name": x["機構名稱"],
"Lat": x["緯度"],
"Lng": x["經度"],
"item": x["特約服務項目"],
"address": x["地址全址"],
"phone": x["機構電話"],
"email": x["電子郵件"],
"ctd": ctd,
"cityOrCounty": cityOrCounty,
"type": x.O_ABC,
}
})
areaData = areaData.map(y => {
return {
"ctForSearch": y.City + Array.from(y.District).slice(0, 2).join(""),
"cties": y.City,
"district": y.District,
"Lat": y.Lat,
"Lng": y.Lng
}
})
console.log(areaData);
makeCtOptions();
document.querySelectorAll("select:not(:first-of-type)").forEach(s => { s.disabled = true });
})
}
//設定縣市選擇
document.querySelector("select#cities").addEventListener("change", function () {
document.querySelectorAll("select#insType option")[0].selected = true;
document.querySelector("select#insType").disabled = true;
let selecterDis = document.querySelector("select#districts");
selecterDis.innerHTML = "";
selecterDis.disabled = false;
let thead = document.querySelector("thead");
let tbody = document.querySelector("tbody");
thead.innerHTML = "";
tbody.innerHTML = "";
let value = this.value;
let districts = areaData.filter(x => x.cties == value);
console.log(districts);
selecterDis.innerHTML = "<option>---請選擇區域---</option>"
districts.forEach(d => {
let option = document.createElement("option");
option.value = value + d.district;
option.innerText = d.district;
selecterDis.add(option);
});
let insInCt = careData.filter(x => x.cityOrCounty == value);
map.setView([districts[0].Lat, districts[0].Lng], 11)
// setMarkers(insInCt);
});
//設計區域選擇
let ins = [];
document.querySelector("select#districts").addEventListener("change", function () {
document.querySelector("select#insType").disabled = false;
document.querySelectorAll("select#insType option")[0].selected = true;
let thead = document.querySelector("thead");
let tbody = document.querySelector("tbody");
thead.innerHTML = "";
tbody.innerHTML = "";
theArea = Array.from(this.value).slice(0, 5).join("");
console.log(theArea)
theArea = areaData.filter(a => a.ctForSearch == theArea)[0];
map.setView([theArea.Lat, theArea.Lng]);
ins = careData.filter(c => c.ctd == theArea.ctForSearch);
setMarkers(ins);
});
//新增長照類型選擇
document.querySelector("select#insType").addEventListener("change", function () {
console.log(ins);
let type = this.value;
let resultIns = ins.filter(i => i.type == type);
setMarkers(resultIns);
createTable(resultIns);
console.log(resultIns);
})
function setMarkers(info) {
// console.log("setMarker")
if (markers) markers.clearLayers();
info.forEach(ins => {
let marker = L.marker([ins.Lat, ins.Lng]);
console.log(marker);
marker.bindPopup(
`<h5>${ins.name}</h5>
<p>服務項目:${ins.item}</p>
<p>地址:${ins.address}</p>
<p>電話:${ins.phone}</p>
<p>電子郵件:${ins.email}</p>
`
)
markers.addLayer(marker);
map.addLayer(markers);
});
}
function makeCtOptions() {
let cties = new Set(areaData.map(x => x.cties));
cties.forEach(ct => {
let selectCt = document.querySelector("select#cities");
let option = document.createElement("option");
option.innerText = ct;
option.value = ct;
selectCt.add(option);
})
}
function createTable(insArray) {
let thead = document.querySelector("thead");
let tbody = document.querySelector("tbody");
thead.innerHTML = "";
tbody.innerHTML = "";
if (insArray.length == 0) {
thead.innerText = "查無資料";
return;
}
let ths = document.querySelectorAll("th");
console.log(ths);
let titles = ["機構名稱", "服務項目", "機構地址"];
let tr = document.createElement("tr");
titles.forEach(t => {
let th = document.createElement("th");
th.innerText = t;
tr.appendChild(th);
});
thead.appendChild(tr);
insArray.forEach(ins => {
let tr = document.createElement("tr");
let data = [ins.name, ins.item, ins.address];
data.forEach(d => {
let td = document.createElement("td");
td.innerText = d;
tr.appendChild(td);
td.addEventListener("click", function () {
map.setView([ins.Lat, ins.Lng], 18);
})
})
tbody.appendChild(tr);
});
}
Array.prototype.groupBy = function (prop) {
return this.reduce(function (groups, item) {
const val = item[prop];
groups[val] = groups[val] || [];
groups[val].push(item);
return groups;
}, {});
}
</script>
</body>
</html>