2023-01-31 07:20:45 +00:00
|
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css"
|
2023-02-07 10:34:56 +00:00
|
|
|
integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI=" crossorigin="" />
|
2023-01-31 07:20:45 +00:00
|
|
|
|
|
|
|
<script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"
|
2023-02-07 10:34:56 +00:00
|
|
|
integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM=" crossorigin=""></script>
|
2023-01-31 07:20:45 +00:00
|
|
|
|
|
|
|
<div id="map"></div>
|
|
|
|
|
|
|
|
<style>
|
2023-02-07 10:34:56 +00:00
|
|
|
#map {
|
|
|
|
width: 100%;
|
|
|
|
padding-bottom: 70%;
|
|
|
|
margin-bottom: 80px;
|
|
|
|
}
|
2023-01-31 07:20:45 +00:00
|
|
|
</style>
|
|
|
|
|
|
|
|
<script>
|
2023-02-07 10:34:56 +00:00
|
|
|
var osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
|
maxZoom: 19,
|
|
|
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create makers layer group
|
|
|
|
var makers = L.layerGroup();
|
|
|
|
{{ with getJSON "https://kios-admin.lumbung.space/api/makers"}}
|
|
|
|
{{ range .docs }}
|
|
|
|
var makerMarker = L.marker(L.GeoJSON.coordsToLatLng({{ .location }}));
|
|
|
|
makerMarker.bindPopup({{ .name }})
|
|
|
|
makers.addLayer(makerMarker);
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
2023-01-31 07:20:45 +00:00
|
|
|
|
2023-02-07 10:34:56 +00:00
|
|
|
// Create retailers layer group
|
|
|
|
var retailers = L.layerGroup();
|
|
|
|
{{ with getJSON "https://kios-admin.lumbung.space/api/retailers"}}
|
|
|
|
{{ range .docs }}
|
|
|
|
var retailerMarker = L.marker(L.GeoJSON.coordsToLatLng({{ .location }}));
|
|
|
|
retailerMarker.bindPopup({{ .name }})
|
|
|
|
retailers.addLayer(retailerMarker);
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
// Create dispatches layer group
|
|
|
|
var dispatches = L.layerGroup();
|
|
|
|
{{ with getJSON "https://kios-admin.lumbung.space/api/dispatches"}}
|
|
|
|
{{ range .docs }}
|
2023-01-31 07:20:45 +00:00
|
|
|
var start = L.GeoJSON.coordsToLatLng({{ .startingPoint.location }});
|
2023-02-07 10:34:56 +00:00
|
|
|
var startMarker = L.marker(start);
|
2023-01-31 11:24:39 +00:00
|
|
|
startMarker.bindPopup({{ .startingPoint.name }});
|
2023-02-07 10:34:56 +00:00
|
|
|
|
|
|
|
var end = L.GeoJSON.coordsToLatLng({{ .endPoint.location }});
|
|
|
|
var endMarker = L.marker(end);
|
2023-01-31 11:24:39 +00:00
|
|
|
endMarker.bindPopup({{ .endPoint.name }});
|
|
|
|
|
2023-02-07 10:34:56 +00:00
|
|
|
// Add line to display dispatch route
|
2023-02-08 11:51:46 +00:00
|
|
|
var myDashArray = {{ .status }} === "routeRequested" ? "20, 10" : {{ .status }} === "completed" ? "1, 5" : "0, 0"; // Dashed line based on status
|
|
|
|
var route = L.polyline([start, end], {color: '#000', dashArray: myDashArray });
|
2023-02-07 10:34:56 +00:00
|
|
|
|
|
|
|
// Generate string to display list of products in popup
|
2023-01-31 11:24:39 +00:00
|
|
|
var productsString = "";
|
|
|
|
var productsList = {{ .products }};
|
|
|
|
productsList.forEach((product, i) => productsString = productsString + product.productTitle + (i + 1 < productsList.length ? ', ' : ""));
|
|
|
|
|
|
|
|
route.bindPopup(
|
|
|
|
'<p>Origin: <strong>' + {{ .startingPoint.name }} + '</strong><br />' +
|
|
|
|
'Destination: <strong>' + {{ .endPoint.name }} + '</strong><br />' +
|
|
|
|
'Courier: <strong>' + {{ .courier.name }} + '</strong><br />' +
|
|
|
|
'Products: <strong>' + productsString + '</strong><br />' +
|
|
|
|
'Status: <strong>' + {{ .status }} + '</strong></p>');
|
2023-01-31 07:20:45 +00:00
|
|
|
|
2023-02-07 10:34:56 +00:00
|
|
|
dispatches.addLayer(route);
|
|
|
|
dispatches.addLayer(startMarker);
|
|
|
|
dispatches.addLayer(endMarker);
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
var map = L.map('map', {
|
|
|
|
center: [0, 0],
|
|
|
|
zoom: 2,
|
2023-02-08 11:51:46 +00:00
|
|
|
layers: [osm, dispatches]
|
2023-02-07 10:34:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var overlayMaps = {
|
2023-02-08 11:51:46 +00:00
|
|
|
"Dispatches": dispatches,
|
2023-02-07 10:34:56 +00:00
|
|
|
"Makers": makers,
|
2023-02-08 11:51:46 +00:00
|
|
|
"Retailers": retailers
|
2023-02-07 10:34:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var layerControl = L.control.layers(overlayMaps, null, {collapsed: false, position: "topleft"}).addTo(map);
|
|
|
|
window.addEventListener('load', (event) => {
|
|
|
|
map.invalidateSize();
|
|
|
|
});
|
2023-01-31 07:20:45 +00:00
|
|
|
</script>
|