|
|
|
@ -15,7 +15,7 @@ import "react-loader-spinner/dist/loader/css/react-spinner-loader.css";
|
|
|
|
|
import { ToastContainer, toast } from "react-toastify"; |
|
|
|
|
import "react-toastify/dist/ReactToastify.css"; |
|
|
|
|
import './MapMonitoring.css'; |
|
|
|
|
import { BASE_SIMPRO_LUMEN_IMAGE } from '../../const/ApiConst'; |
|
|
|
|
import { BASE_SIMPRO_LUMEN_IMAGE, PROYEK_SEARCH } 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'; |
|
|
|
@ -26,13 +26,32 @@ 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'; |
|
|
|
|
import axios from "../../const/interceptorApi"; |
|
|
|
|
const MapMonitoring = ({ ...props }) => { |
|
|
|
|
let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = ''; |
|
|
|
|
if (props.location.state && props.location.state.role_id && props.location.state.user_id) { |
|
|
|
|
role_id = props.location.state.role_id; |
|
|
|
|
user_id = props.location.state.user_id; |
|
|
|
|
token = props.location.state.token; |
|
|
|
|
isLogin = props.location.state.isLogin; |
|
|
|
|
|
|
|
|
|
const MapMonitoring = () => { |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
role_id = localStorage.getItem("role_id"); |
|
|
|
|
proyek_id = localStorage.getItem("proyek_id"); |
|
|
|
|
user_id = localStorage.getItem("user_id"); |
|
|
|
|
token = localStorage.getItem("token"); |
|
|
|
|
isLogin = localStorage.getItem("isLogin"); |
|
|
|
|
} |
|
|
|
|
const HEADER = { |
|
|
|
|
headers: { |
|
|
|
|
"Content-Type": "application/json", |
|
|
|
|
Authorization: `Bearer ${token}`, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
const GRID_LEFT = 6; |
|
|
|
|
const GRID_MIDDLE = 12; |
|
|
|
|
const GRID_RIGHT = 6; |
|
|
|
|
const GRID_TOTAL = GRID_LEFT+GRID_MIDDLE+GRID_RIGHT;
|
|
|
|
|
const GRID_TOTAL = GRID_LEFT + GRID_MIDDLE + GRID_RIGHT; |
|
|
|
|
const mapRef = useRef() |
|
|
|
|
const center = { |
|
|
|
|
// lat: -6.200000,
|
|
|
|
@ -41,7 +60,7 @@ const MapMonitoring = () => {
|
|
|
|
|
lng: 120.13025155062624 |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
const {userPoints, mymap, openLeft, openRight, routingBarVisible, userHistory, isSearchingRoute, selectedFeature} = useSelector(state => state.mapReducer); |
|
|
|
|
const { userPoints, mymap, openLeft, openRight, routingBarVisible, userHistory, isSearchingRoute, selectedFeature } = useSelector(state => state.mapReducer); |
|
|
|
|
const [gridMiddle, setGridMiddle] = useState(GRID_MIDDLE); |
|
|
|
|
const [gridLeft, setGridLeft] = useState(0); |
|
|
|
|
const [gridRight, setGridRight] = useState(0); |
|
|
|
@ -105,7 +124,7 @@ const MapMonitoring = () => {
|
|
|
|
|
}); |
|
|
|
|
let userHistoryLayer = L.geoJson(userHistory, { |
|
|
|
|
name: 'userHistoryLayer', |
|
|
|
|
onEachFeature: function(feature, layer) { |
|
|
|
|
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") : '-'}`; |
|
|
|
|
|
|
|
|
@ -113,20 +132,20 @@ const MapMonitoring = () => {
|
|
|
|
|
closeButton: true, |
|
|
|
|
// offset: L.point(0, -20)
|
|
|
|
|
}); |
|
|
|
|
layer.on('click', function() { |
|
|
|
|
layer.on('click', function () { |
|
|
|
|
layer.openPopup(); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
pointToLayer: function(feature, latlng) { |
|
|
|
|
pointToLayer: function (feature, latlng) { |
|
|
|
|
var type = feature.properties.type; |
|
|
|
|
if (type === 'Start') { |
|
|
|
|
return L.marker(latlng, {icon: startIcon}); |
|
|
|
|
return L.marker(latlng, { icon: startIcon }); |
|
|
|
|
} |
|
|
|
|
else if (type === "Working") { |
|
|
|
|
return L.marker(latlng, {icon: onTripIcon}); |
|
|
|
|
return L.marker(latlng, { icon: onTripIcon }); |
|
|
|
|
} |
|
|
|
|
else if (type === "End") { |
|
|
|
|
return L.marker(latlng, {icon: endIcon}); |
|
|
|
|
return L.marker(latlng, { icon: endIcon }); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
@ -155,9 +174,11 @@ const MapMonitoring = () => {
|
|
|
|
|
// init for left content panel, get projects and build tree select antd
|
|
|
|
|
const getMapLeftContent = async () => { |
|
|
|
|
store.dispatch(setMapLoading(true)); |
|
|
|
|
let project = await ApiProject.list(); |
|
|
|
|
// console.log('project', project);
|
|
|
|
|
if (project && project.status && project.data && project.data.length > 0) { |
|
|
|
|
|
|
|
|
|
let project = await ApiProject.search(role_id); |
|
|
|
|
// console.log('projectsearch', projectsearch.data.data);
|
|
|
|
|
console.log('project', project); |
|
|
|
|
if (project && project.data && project.data.length > 0) { |
|
|
|
|
let projectData = [ |
|
|
|
|
{ |
|
|
|
|
"title": 'All', |
|
|
|
@ -182,7 +203,7 @@ const MapMonitoring = () => {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onEachFeatureUserPoints = (feature, layer) => { |
|
|
|
|
layer.on('click', function(e) { |
|
|
|
|
layer.on('click', function (e) { |
|
|
|
|
L.DomEvent.stopPropagation(e); |
|
|
|
|
if (!store.getState().mapReducer.routingBarVisible) { |
|
|
|
|
// proceed only when routing mode is not visible
|
|
|
|
@ -226,7 +247,7 @@ const MapMonitoring = () => {
|
|
|
|
|
let lon = feature.geometry.coordinates[0]; |
|
|
|
|
|
|
|
|
|
// create a new marker using the icon style
|
|
|
|
|
let marker = new L.Marker([lat,lon],{icon: logoMarker}); |
|
|
|
|
let marker = new L.Marker([lat, lon], { icon: logoMarker }); |
|
|
|
|
markerCluster.addLayer(marker); |
|
|
|
|
return marker; |
|
|
|
|
} |
|
|
|
@ -271,8 +292,8 @@ const MapMonitoring = () => {
|
|
|
|
|
// kalo bukan point bikin hightlight jadi biru
|
|
|
|
|
if (feature && feature.geometry && feature.geometry.type !== 'Point') { |
|
|
|
|
L.geoJSON(feature, { |
|
|
|
|
style: function(feature) { |
|
|
|
|
return {color: 'blue'} |
|
|
|
|
style: function (feature) { |
|
|
|
|
return { color: 'blue' } |
|
|
|
|
}, |
|
|
|
|
name: 'popupTemp', |
|
|
|
|
onEachFeature: function (feature, layer) { |
|
|
|
@ -299,12 +320,12 @@ const MapMonitoring = () => {
|
|
|
|
|
<div id="map-area" style={{ height: '90vh', width: '100%' }} ref={mapRef}></div> |
|
|
|
|
<button |
|
|
|
|
title='Project List' |
|
|
|
|
style={{position: 'absolute', top: 80, left: 10, zIndex: 999, backgroundColor:'white', backgroundSize:'34px 34px', width: '34px', height: '34px', borderRadius: '2px', borderWidth: '1px', borderColor: 'grey'}}
|
|
|
|
|
style={{ position: 'absolute', top: 80, left: 10, zIndex: 999, backgroundColor: 'white', backgroundSize: '34px 34px', width: '34px', height: '34px', borderRadius: '2px', borderWidth: '1px', borderColor: 'grey' }} |
|
|
|
|
onClick={() => store.dispatch(setOpenLeft(!openLeft))}> |
|
|
|
|
<i className='fa fa-list'></i> |
|
|
|
|
</button> |
|
|
|
|
{ routingBarVisible && <RoutingBar /> } |
|
|
|
|
{ isSearchingRoute && ( |
|
|
|
|
{routingBarVisible && <RoutingBar />} |
|
|
|
|
{isSearchingRoute && ( |
|
|
|
|
<div className="loader-container"> |
|
|
|
|
<Loader |
|
|
|
|
type="TailSpin" |
|
|
|
@ -321,13 +342,13 @@ const MapMonitoring = () => {
|
|
|
|
|
<ToastContainer autoClose={5000} /> |
|
|
|
|
</Row> |
|
|
|
|
) |
|
|
|
|
}, [openLeft, openRight, gridLeft, gridMiddle, gridRight, routingBarVisible ]) |
|
|
|
|
}, [openLeft, openRight, gridLeft, gridMiddle, gridRight, routingBarVisible]) |
|
|
|
|
|
|
|
|
|
const renderGridMap = () => { |
|
|
|
|
let middle = GRID_MIDDLE; |
|
|
|
|
let left = GRID_LEFT; |
|
|
|
|
let right = GRID_RIGHT; |
|
|
|
|
if (openLeft && openRight){ |
|
|
|
|
if (openLeft && openRight) { |
|
|
|
|
middle = GRID_MIDDLE; |
|
|
|
|
left = GRID_LEFT; |
|
|
|
|
right = GRID_RIGHT; |
|
|
|
|