|
|
|
@ -17,11 +17,15 @@ import "react-toastify/dist/ReactToastify.css";
|
|
|
|
|
import './MapMonitoring.css'; |
|
|
|
|
import { BASE_SIMPRO_LUMEN_IMAGE } from '../../const/ApiConst'; |
|
|
|
|
import DEFAULT_USER_ICON from '../../assets/img/avatars/user.png'; |
|
|
|
|
import pinRouteStart from '../../assets/img/map/pin_route_green.png'; |
|
|
|
|
import pinRouteEnd from '../../assets/img/map/pin_route_red.png'; |
|
|
|
|
import pinRouteOnTrip from '../../assets/img/map/pin_route_on_trip.png'; |
|
|
|
|
import 'leaflet.markercluster/dist/MarkerCluster.Default.css' |
|
|
|
|
import 'leaflet.markercluster/dist/MarkerCluster.css' |
|
|
|
|
import 'leaflet.markercluster/dist/leaflet.markercluster.js' |
|
|
|
|
import 'leaflet-control-geocoder/dist/Control.Geocoder.css' |
|
|
|
|
import 'leaflet-control-geocoder/dist/Control.Geocoder.js' |
|
|
|
|
import moment from 'moment'; |
|
|
|
|
|
|
|
|
|
const MapMonitoring = () => { |
|
|
|
|
|
|
|
|
@ -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 = `<b>Status: </b>${feature.properties.type}<br>
|
|
|
|
|
<b>Time: </b> ${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()); |
|
|
|
|