From 3a1fac9961461944b3f007be87269fbc2a56d74e Mon Sep 17 00:00:00 2001 From: ardhi Date: Mon, 4 Sep 2023 19:05:07 +0700 Subject: [PATCH] add marker and popup definition when searching user waypoint --- src/appredux/modules/map/actions.js | 49 +++++++++++++++-------- src/assets/img/map/pin_route_on_trip.png | Bin 0 -> 3864 bytes src/views/MapMonitoring/index.js | 48 +++++++++++++++++++++- 3 files changed, 79 insertions(+), 18 deletions(-) create mode 100644 src/assets/img/map/pin_route_on_trip.png diff --git a/src/appredux/modules/map/actions.js b/src/appredux/modules/map/actions.js index db12266..0462355 100644 --- a/src/appredux/modules/map/actions.js +++ b/src/appredux/modules/map/actions.js @@ -158,11 +158,41 @@ export const getUserHistory = async (userId, dateString) => { "features": [] } + // build waypoint line + let featureLine = { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [] + } + } + + userHistory.data.map((n, idx) => { + featureLine.geometry.coordinates.push([parseFloat(n.lon), parseFloat(n.lat)]) + + if (idx > startIdx && idx < endIdx) { + let featureOnTrip = { + "type": "Feature", + "properties": { + "type": "Working", + "wptime": n.wptime + }, + "geometry": { + "type": "Point", + "coordinates": [parseFloat(n.lon), parseFloat(n.lat)] + } + } + featureCollection.features.push(featureOnTrip); + } + }); + featureCollection.features.push(featureLine); + // set waypoint start let featurePointStart = { "type": "Feature", "properties": { - "type": "start", + "type": "Start", "wptime": userHistory.data[startIdx].wptime }, "geometry": { @@ -176,7 +206,7 @@ export const getUserHistory = async (userId, dateString) => { let featurePointEnd = { "type": "Feature", "properties": { - "type": "end", + "type": "End", "wptime": userHistory.data[endIdx].wptime }, "geometry": { @@ -186,21 +216,6 @@ export const getUserHistory = async (userId, dateString) => { } featureCollection.features.push(featurePointEnd); - // build waypoint line - let featureLine = { - "type": "Feature", - "properties": {}, - "geometry": { - "type": "LineString", - "coordinates": [] - } - } - - userHistory.data.map(n => { - featureLine.geometry.coordinates.push([parseFloat(n.lon), parseFloat(n.lat)]) - }); - featureCollection.features.push(featureLine); - store.dispatch(setUserHistory(featureCollection)); store.dispatch(setIsSearchingRoute(false)); } diff --git a/src/assets/img/map/pin_route_on_trip.png b/src/assets/img/map/pin_route_on_trip.png new file mode 100644 index 0000000000000000000000000000000000000000..a3c9d0c8813c41a47e99c1bb8354dd8cc3972d17 GIT binary patch literal 3864 zcmbtXX;f3!7C!eT0h1^cnF;|?YYPa9aX^M>(Wj`$D5zjT2}Q*^kSGYqcmq{m9~Nv; z3d*3Rf&&6d85MGo_XMq_Do|8}1Se(^l?r5h=cKUO_v8I4Yq9RW=X~Fu&ffdneC_A6 zVGhHb0RWiev2mS0062mEXHnn^*U-fPKBy6Eyw?D5J(H;nqrvx&!Z-SR0}yWw0Pz(7 za=1hc0C0o@zz`1r*Bk&$1$p(GSHg{DeqLMLH5!d|rFCv@Zg6n0d8(O3s=1ZW+$xo2 znaX0NnwtsD*eT|0A&Zq}&L+$)Q_Ufs7+NcabUfPMCjfw$tY4hr8}^0ghIQbdG|P?f zMK{{R+g-PxPGwpw%(uMq0`2n;`)t8}{UP=&jHbn7-I^_NPe*&`hl^^Ak3Br!nRe6C zMj<}<%<7)Uz3Po$)Pi0YdoYyzd-`{_Lu?J?|NTGW`O|%Ds~gIoLCbqj%Nx9op{HYG zr$KS7?fzl8$%>rb3#HfEgLA^-Puys`#7|Cx09PAP9UTIOe^lj?e zdZ#@CIO$Ao5+aS|ja_q*hJ4kkP{fFwBYUDXu|MTk6Qt5}IKdUEp!*SrJofEwIl@g^oonLw%#kPypb*3h_^+kwz5OAu{_~N1lrmv{gw(N z`E)h5ek)zpfJ|<^=!QjJ*_bTVX3tfnNlG(Sa}t8R#VGrOEz)?kt0+f#h+OkBwQf?b~y(TkA(8 z0>ww^3;}Z)#Ue-?Ta;owpS1KE;lF&rzXK8698-x*S*$&QB6&grOTNbpi{$we zQEwGb^zmCi=YbZHQjrGAmtGX5_>A!VQLfG!NII0(+Df1(SV8B(i#xi`B3M)m&RDD3 zTAQ|qSlJ*y5uweWiB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F$r4%30fukS7;%dSG~)%{i17$Y}5AX>hs`x4ofjuxY84l+g>&}f?J?$}!I zxg(A4aAj;(g~kNx87hoS!*xSGh7*`loo?#vWVi5zz|91y|@JcVV{ zt%1}#_f5S752nzFjVFrQ3jc_6Uk7m+r^VHVVe1(dv2u6`d~=So`8>#sjV37i5L7B; zl`V#&fa^kj8{rGT7FrDgO>If0g@xonQ3?E#8u*td(<0$5V&)$T6Q=1GKvEO8%-)ZP zb#^2l_WMZvvSEoi#<#lD^xR^gE5{et6|cs6pWg>9g|0A!7bPLkWciYL^>)NOHe&hV3#m z0NEGP@VxjA#NKgauQ1B@EM(VJX27d9(AAo}tBcq#ceKE+;^xnlj6}__SB+eP?8|HM zyyW|c9U8My_|7+XI^pV{D2xz6E8IYr3$uFELGT|lcq-`Q2d&uO8C@v2YXDcOcJ(wu zMU^T_NYw3V{QlRY3!wdABgrt$!8H^nB1T`(IR(#qhJRHj`8v6~#q*D>R~_iVexZcd>PqE#l)0;CY%x}?8Nzv5!1wUzN^M{*T4!o(} z3J0zMoH&QGoUj|)iKb@Qg{X)ak-gN`ZJ711-~DlPo8a2a-TZREn>b*^8@HYAyC1GP zVc9jl#FMOP^1U|raoV#2JFY*?w!4*J$UAhCn)4ZI?MKbbirR4*zR+RSEs*Z1znFaf zm!(8Q-oe4XZYy}BefpPu%{HF=1Ki6)U$dVWTsDhi{g=I(P=*(K4Y35$CP2H*Ui_qo zzL**m96xEj`tSdif*Ky*P62vvpF3P=7(+iMKaF+|iry6#z1ubX@NW13OF2uIE#kN= z;w;~?WQpriXV>M+?KvD*4rkr { @@ -81,8 +85,50 @@ const MapMonitoring = () => { if (mymap) { removeLayerByName('userHistoryLayer'); if (userHistory) { + var startIcon = new L.Icon({ + iconSize: [60, 60], + iconAnchor: [30, 47], + popupAnchor: [1, -24], + iconUrl: pinRouteStart + }); + var endIcon = new L.Icon({ + iconSize: [60, 60], + iconAnchor: [30, 47], + popupAnchor: [1, -24], + iconUrl: pinRouteEnd + }); + var onTripIcon = new L.Icon({ + iconSize: [60, 60], + iconAnchor: [30, 47], + popupAnchor: [1, -24], + iconUrl: pinRouteOnTrip + }); let userHistoryLayer = L.geoJson(userHistory, { - name: 'userHistoryLayer' + name: 'userHistoryLayer', + onEachFeature: function(feature, layer) { + var popupText = `Status: ${feature.properties.type}
+ Time: ${feature.properties.wptime ? moment(feature.properties.wptime).format("DD-MM-YYYY HH:mm:ss") : '-'}`; + + layer.bindPopup(popupText, { + closeButton: true, + // offset: L.point(0, -20) + }); + layer.on('click', function() { + layer.openPopup(); + }); + }, + pointToLayer: function(feature, latlng) { + var type = feature.properties.type; + if (type === 'Start') { + return L.marker(latlng, {icon: startIcon}); + } + else if (type === "Working") { + return L.marker(latlng, {icon: onTripIcon}); + } + else if (type === "End") { + return L.marker(latlng, {icon: endIcon}); + } + }, }); userHistoryLayer.addTo(mymap); mymap.fitBounds(userHistoryLayer.getBounds());