-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
601 lines (523 loc) · 26.5 KB
/
index.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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
<!DOCTYPE html>
<html lang="zh_TW">
<head>
<title>觀展牛奶車 - 台中駐點地圖</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:locale" content="zh_TW">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" crossorigin="anonymous");
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.min.css" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/L.Control.Locate.min.css" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/MarkerCluster.css" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/MarkerCluster.Default.css" crossorigin="anonymous" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.all.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/papaparse.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/src/L.Control.Locate.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.markercluster.min.js" crossorigin="anonymous"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7285054564848006"
crossorigin="anonymous"></script>
<style>
html, body, #main, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-control-container {
z-index: 500 !important;
}
#layer-visible {
z-index: 1002;
display: block;
background-color: #fff;
padding: 0.3rem 0.5rem;
position: absolute;
right: 10px;
top: 40px;
}
#logo-banner {
display: flex;
align-items: flex-end;
}
#logo-banner i {
font-size: 25px;
}
/* #logo-banner-title {
margin-bottom: 10px;
} */
.btn-line-green {
background-color: #38CD00 !important;
border: 0px;
}
.btn-pec-go-blue {
background-color: #1875D1 !important;
border: 0px;
}
/* The sidebar menu */
.sidebar {
height: 100%; /* 100% Full-height */
width: 0; /* 0 width - change this with JavaScript */
position: fixed; /* Stay in place */
z-index: 1001; /* Stay on top */
top: 0;
right: 0;
background-color: #FFFFFF; /* Black*/
overflow-x: hidden; /* Disable horizontal scroll */
transition: 0.15s; /* 0.5 second transition effect to slide in the sidebar */
display: flex;
flex-direction: column;
justify-content: space-between;
box-shadow: -3px 5px 9px 0px rgba(0,0,0,0.19);
-webkit-box-shadow: -3px 5px 9px 0px rgba(0,0,0,0.19);
-moz-box-shadow: -3px 5px 9px 0px rgba(0,0,0,0.19);
}
.sidebar #content {
padding: 25px 15px 10px;
}
/* Position and style the close button (top right corner) */
.sidebar .closeBtn {
position: absolute;
top: 0px;
right: 25px;
font-size: 36px;
margin-left: 50px;
color: #444;
z-index: 1001;
}
.sidebar .closeBtn:hover {
cursor: pointer;
}
#profile {
display: flex;
justify-content: center;
width: 100%;
position: absolute;
margin-left: auto;
margin-top: 25px;
}
#profile-img {
background-color: #E3F3FF;
padding: 10px;
/* 陰影 */
box-shadow: 0px 4px 4px 0px rgba(150,177,203,0.24);
-webkit-box-shadow: 0px 4px 4px 0px rgba(150,177,203,0.24);
-moz-box-shadow: 0px 4px 4px 0px rgba(150,177,203,0.24);
}
#banner {
background-color: #F0F4F7;
height: 135px;
margin-top: 90px;
padding-top: 60px;
}
#sidebar-welcome-info {
padding: 0 24px;
}
#sidebar-welcome-info hr {
margin: 1rem 0;
color: inherit;
background-color: #202F5A;
border: 0;
opacity: 0.25;
}
#sidebar-footer {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 20px;
font-size: 13px;
}
#sidebar-footer-action {
display: flex;
justify-content: space-evenly;
margin-bottom: 25px;
}
#join-facebook-btn {
border-radius: 4px;
font-size: 14px;
height: 28px;
padding: 0 8px;
}
#join-facebook-btn a {
background-color: rgba(9, 30, 66);
border-radius: inherit;
height: 100%;
width: 100%;
}
#action-list {
margin-top: 25px;
}
.action-btn {
padding: 12px;
font-size: 16px;
color: #2f84c0;
background-color: #E3F3FF;
border-radius: 10px;
/* drop shadow */
box-shadow: 0px 4px 4px 0px rgba(150,177,203,0.24);
-webkit-box-shadow: 0px 4px 4px 0px rgba(150,177,203,0.24);
-moz-box-shadow: 0px 4px 4px 0px rgba(150,177,203,0.24);
margin: 0 5px;
margin-bottom: 15px;
}
/* The button used to open the sidebar */
.openBtn {
font-size: 20px;
cursor: pointer;
background-color: #111;
color: white;
padding: 10px 15px;
border: none;
}
.openBtn:hover {
background-color: #444;
}
.modal-swal-popup {
border-radius: 20px;
}
.modal-swal-confirm-btn {
background-color: #2f84c0 !important;
}
/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
transition: margin-left 0.5s; /* If you want a transition effect */
}
/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
@media screen and (max-height: 450px) {
.sidebar {padding-top: 15px;}
.sidebar a {font-size: 18px;}
}
</style>
</head>
<body>
<div id="mySidebar" class="sidebar">
<div class="closeBtn" onclick="closeNav()">×</div>
<div>
<div id="profile" >
<img class="img-responsive rounded-circle" id="profile-img" src="/assets/images/GZMilkDailyIcon.png" width="110" height="110">
</div>
<div id="banner" style="color: #2F84C0">
<h4 id="sidebar-title" class="text-center">PEC GO 觀展牛奶車</h4>
<h6 id="sidebar-subtitle" class="text-center">專配送統一企業冷藏品</h6>
</div>
<div id="content" style="color: #2F84C0">
<div class="text-start px-3">觀展牛奶車前進社區為大家服務啦!歡迎大家依據配送區域加入該社群 💙</div>
<ul class="list-unstyled mt-3 mx-2">
<li>
<img src="/assets/images/bulletListTick.png" width="12" height="12" class="mx-2">固定每週配送效期新鮮的產品
</li>
<li>
<img src="/assets/images/bulletListTick.png" width="12" height="12" class="mx-2">不限訂單金額!免運費!
</li>
<li>
<img src="/assets/images/bulletListTick.png" width="12" height="12" class="mx-2">週週另享獨家優惠
</li>
<li>
<img src="/assets/images/bulletListTick.png" width="12" height="12" class="mx-2">冷藏專車配送,品質保證
</li>
</ul>
<div id="action-list">
<a class="text-decoration-none" href="https://online.fliphtml5.com/bqfbe/caoc" target="_blank">
<div class="action-btn text-left" role="button">
<img src="/assets/images/catalogueIcon.png" height="28" width="28" class="me-3">產品目錄
</div>
</a>
<div class="action-btn text-left" role="button" onclick="openCommunityDeliveryInvitation()">
<img src="/assets/images/communityDeliveryInvitationicon.png" height="28" width="28" class="me-3">社區配送大募集
</div>
</div>
</div>
</div>
<div>
<div id="sidebar-footer-action">
<a href="tel:04-23507266,507">
<img src="https://cdn-icons-png.flaticon.com/512/446/446446.png" width="45" height="45" role="button" alt="撥打電商部電話">
</a>
<a href="https://lin.ee/vZ6U77F" target="_blank">
<img src="https://cdn-icons-png.flaticon.com/512/3670/3670089.png" width="45" height="45" role="button" alt="加入官方 Line 好友">
</a>
<a id="facebookPageHyperLink" target="_blank">
<img src="https://cdn-icons-png.flaticon.com/512/3670/3670032.png" width="45" height="45" role="button" alt="前往 Facebook 粉絲專頁">
</a>
</div>
<div id="sidebar-footer">
<div>觀展企業股份有限公司</div>
<div>電商部 04-23507266 #507</div>
<div>台中市西屯區工業區二路9-1號</div>
<!-- <div>電商部 <a class="text-decoration-none" href="tel:04-23507266,507">04-23507266 #507</a></div>
<a class="text-decoration-none" href="https://maps.google.com/maps?q=台中西屯區工業區二路9-1號" target="_blank">台中西屯區工業區二路9-1號</a> -->
</div>
</div>
</div>
</div>
<div id="main">
<div id="map"></div>
<div id="layer-visible" class="leaflet-bar leaflet-control text-monospace unselectable">
<div id="logo-banner" onClick="openNav()">
<img src="/assets/images/GZMilkDailyIcon.png" width="45" height="45" role="button">
<i class="bi bi-list"></i>
</div>
<!-- <div class="border-top mt-2 mb-2"></div>
<a class="openbtn" onClick="openNav()" role="button" target="_blank">OpenNav</a>
<a class="btn btn-pecgo-blue btn-block text-white mt-2 h-auto w-100" href="https://pec-go.web.app" role="button" target="_blank">馬上訂購</a> -->
</div>
</div>
<script type="text/javascript">
// initialize
let map;
let markerCluster;
let locate;
const markerIcon = L.Icon.extend({
options: {
iconSize: [70, 70], // size of the icon
iconAnchor: [36, 48], // point of the icon which will correspond to marker's location
popupAnchor: [0, -38], // point from which the popup should open relative to the iconAnchor
}
})
const smallMarkerIcon = L.Icon.extend({
options: {
iconSize: [50, 50], // size of the icon
iconAnchor: [24, 36], // point of the icon which will correspond to marker's location
popupAnchor: [0, -38], // point from which the popup should open relative to the iconAnchor
}
})
const icons = {
pickupTruck: new markerIcon({ iconUrl: '/assets/images/GZMilkDailyIcon.png' }),
selfPickupFlag: new smallMarkerIcon({ iconUrl: '/assets/images/selfPickupIcon.png' })
}
const facebookLink = getFacebookLink()
document.getElementById('facebookPageHyperLink').href = facebookLink
initMap()
async function initMap() {
let layers = L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/light_all/{z}/{x}/{y}.png')
// 準備地圖
map = L.map('map', {
center: [24.162361500290167, 120.64669143864016],
layers: [layers],
tap: false,
zoom: 13,
})
// 定位
locate = L.control.locate({
initialZoomLevel: 13,
position: 'topleft',
strings: { title: '取得定位', popup: '您目前的位置' },
}).addTo(map)
// 標記集合
markerCluster = await createMarkerCluster()
showLoading()
fetchDataAndCreateMarker(markerCluster)
locate.start()
}
async function showLoading () {
await Swal.fire({
title: '請稍候',
text: '觀展牛奶車正在前往據點',
imageUrl: '/assets/images/GZMilkDailyIcon.png',
imageWidth: 250,
imageHeight: 250,
timer: 2500,
imageAlt: 'Custom image',
allowOutsideClick: false,
showConfirmButton: false,
willOpen: () => Swal.showLoading(),
})
}
function businessHourInfo (businessHour) {
let info = ''
for (const item of businessHour) {
info += `<div>${item}</div>`
}
return info
}
async function createMarkerCluster () {
markerCluster = L.markerClusterGroup({
chunkedLoading: true,
disableClusteringAtZoom: 14,
spiderfyOnMaxZoom: false,
})
return markerCluster
}
async function fetchDataAndCreateMarker (markerCluster, options) {
try {
const points = await fetchData(
url='https://docs.google.com/spreadsheets/d/e/2PACX-1vRoiI74btFPRwDN0496EBKNkXKqvm4FSAt7uvE8AlKIqS7f6LQAjJnNSLip86SSs2t1ytiBSzhFdGis/pub?gid=0&single=true&output=csv'
)
// Popup
const pointPopup = point => {
let addressElement = point.address
if (point.type == '定點取貨') {
addressElement = `<a href="https://maps.google.com/maps?q=${point.address}" target="_blank" style="display: flex; align-items: flex-start;"><img src="/assets/images/googleMapsIcon.png" height="15" width="15" class="me-1">${point.address}</a>`
}
return `<h5 class="text-center">${point.name}</h5>` +
(point.thumbnail !== '' ? `<img class="img-thumbnail img-fluid mb-2" alt="觀展牛奶車" src="${point.thumbnail}">` : ``) +
`<table class="table table-sm mt-1 mb-2 table-borderless table-store text-monospace" aria-describedby="info">` +
`<tbody>` +
`<tr><th>地址</th><td>${addressElement}</td></tr>` +
`<tr><th>類型</th><td>${point.type}</td></tr>` +
`<tr><th>時間</th><td>${businessHourInfo(point.businessHour)}</td></tr>` +
`</tbody>` +
'</table>' +
(point.lineOpenChatLink !== '' ? `<a class="btn btn-line-green btn-block text-white mt-2 w-100" href="${point.lineOpenChatLink}" role="button" target="_blank">加入 Line 社群</a>` : ``)
}
const customMarker = L.Marker.extend({
options: {
pointInfo: {}
}
});
function getMarkerIcon (pointType) {
if (pointType == "定點取貨") {
return icons.selfPickupFlag
} else {
return icons.pickupTruck
}
}
points.map(point => new customMarker(new L.LatLng(point.lat, point.lng), { icon: getMarkerIcon(point.type), pointInfo: point }) // 新增Marker
.bindPopup(pointPopup(point))) // 資訊視窗
.forEach(item => markerCluster.addLayer(item)); // 把marker加入 L.markerClusterGroup中
// 顯示半徑 1KM 的 Layer
let circleGroup = L.featureGroup();
markerCluster.getLayers().forEach(function (item) {
item.on('click', function(e) {
// 清除所有 Circle
map.removeLayer(circleGroup)
circleGroup = L.featureGroup();
// 將點擊的牛奶車畫出半徑 1KM 的 Circle
if (item.options.pointInfo.type == '配送到府') {
L.circle(item.getLatLng(), {
radius: 1000,
color: '#006EB4',
weight: 1,
fillOpacity: .05
}).addTo(circleGroup);
map.addLayer(circleGroup);
}
map.setView(item.getLatLng(), 14);
item.openPopup()
})
item.on('mouseover', function(e) {
// 清除所有 Circle
map.removeLayer(circleGroup)
circleGroup = L.featureGroup();
// 將點擊的牛奶車畫出半徑 1KM 的 Circle
if (item.options.pointInfo.type == '配送到府') {
L.circle(item.getLatLng(), {
radius: 1000,
color: '#006EB4',
weight: 1,
fillOpacity: .05
}).addTo(circleGroup);
map.addLayer(circleGroup);
}
item.openPopup()
})
})
map.on('mousedown', function(e) {
map.removeLayer(circleGroup)
closeNav()
})
map.addLayer(markerCluster)
} catch (err) {
console.log(err)
}
}
async function fetchData (url) {
try {
// 取得 CSV 並解析
const response = await axios.get(url,{ responseType: 'blob'})
const csv = await response.data.text();
let rawPoints = await Papa.parse(csv, {
encoding: 'utf8',
header: true,
})
// 重新命名欄位
function renameKey ( obj, oldKey, newKey ) {
obj[newKey] = obj[oldKey];
delete obj[oldKey];
}
const points = rawPoints.data
points.forEach( obj => renameKey( obj, '名稱', 'name' ) )
points.forEach( obj => renameKey( obj, '地址', 'address' ) )
points.forEach( obj => renameKey( obj, '電話', 'mobile_no' ) )
points.forEach( obj => renameKey( obj, 'Line 社群連結', 'lineOpenChatLink' ) )
points.forEach( obj => renameKey( obj, '類型', 'type' ) )
points.forEach( obj => renameKey( obj, '封面照', 'thumbnail' ) )
// 上班時間處理
points.forEach( obj => {
obj['businessHour'] = obj['時間'].split('\n')
delete obj['時間']
})
// 經緯度處理
points.forEach( obj => {
obj['lat'] = obj['經緯度'].split(',')[0]
obj['lng'] = obj['經緯度'].split(',')[1]
delete obj['經緯度']
})
return points
} catch (err) {
console.log(err)
}
}
/* Set the width of the sidebar to 250px and the left margin of the page content to 250px */
function openNav() {
document.getElementById("mySidebar").style.width = "320px";
document.getElementById("layer-visible").style.display = "None";
document.getElementById("content").style.visibility = "visible";
document.getElementById("content").style.opacity = "1";
}
/* Set the width of the sidebar to 0 and the left margin of the page content to 0 */
function closeNav() {
document.getElementById("mySidebar").style.width = "0";
document.getElementById("layer-visible").style.display = "block";
document.getElementById("content").style.visibility = "hidden";
document.getElementById("content").style.opacity = "0";
}
async function openCommunityDeliveryInvitation() {
const wrapper = document.createElement('div');
wrapper.innerHTML = '<img class="w-100 p-3" src="/assets/images/communityDeliveryInvitation.png" style="border-radius: 30px;">' +
'<div class="text-start mx-3 my-2" style="color: #2F84C0">為提供我們廣大的牛奶車朋友更多的方便,歡迎大家提出希望可以免運配送的社區,大家的願望很有可能會實現喲 💙</div>' +
'<div class="mt-4 mx-3 p-1 btn-line-green text-center fs-6" style="border-radius: 10px;">' +
'<a class="text-decoration-none text-white me-2" href="https://lin.ee/vZ6U77F" target="_blank">' +
'<img src="https://cdn-icons-png.flaticon.com/512/3670/3670089.png" height="46" width="46" class="me-2">歡迎留言給小編' +
'</a>' +
'</div>';
await Swal.fire({
allowOutsideClick: true,
showConfirmButton: false,
showCloseButton: true,
allowEnterKey: false,
background: '#F0F4F7',
html: wrapper,
customClass: {
popup: 'modal-swal-popup',
confirmButton: 'modal-swal-confirm-btn'
}
})
}
/* 根據手機平台回傳 Facebook 連結 */
function getFacebookLink () {
if (isIos() || isAndroid) {
link = "fb://profile/100070453045823"
} else {
link = "https://www.facebook.com/gzmilkdaily"
}
return link
}
/* 判斷手機平台 */
function isIos (){
return (
(navigator.userAgent.toLowerCase().indexOf("ipad") > -1) ||
(navigator.userAgent.toLowerCase().indexOf("iphone") > -1) ||
(navigator.userAgent.toLowerCase().indexOf("ipod") > -1)
);
}
function isAndroid () {
return navigator.userAgent.toLowerCase().indexOf("android");
}
</script>
</body>
</html>