map: add layer groups and layer controld for makers, retailers, dispatches
This commit is contained in:
parent
99bea6ae6c
commit
5506d3cfa2
@ -15,30 +15,47 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var map = L.map('map').setView([51.505, -0.09], 3);
|
var osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
window.addEventListener('load', (event) => {
|
|
||||||
map.invalidateSize();
|
|
||||||
});
|
|
||||||
|
|
||||||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
||||||
maxZoom: 19,
|
maxZoom: 19,
|
||||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||||
}).addTo(map);
|
});
|
||||||
|
|
||||||
|
// 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 }}
|
||||||
|
|
||||||
{{ with getJSON "https://kios-admin.lumbung.space/api/dispatches"}}
|
// 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 }}
|
{{ range .docs }}
|
||||||
var start = L.GeoJSON.coordsToLatLng({{ .startingPoint.location }});
|
var start = L.GeoJSON.coordsToLatLng({{ .startingPoint.location }});
|
||||||
var end = L.GeoJSON.coordsToLatLng({{ .endPoint.location }});
|
var startMarker = L.marker(start);
|
||||||
|
|
||||||
var startMarker = L.marker(start).addTo(map);
|
|
||||||
startMarker.bindPopup({{ .startingPoint.name }});
|
startMarker.bindPopup({{ .startingPoint.name }});
|
||||||
|
|
||||||
var endMarker = L.marker(end).addTo(map);
|
var end = L.GeoJSON.coordsToLatLng({{ .endPoint.location }});
|
||||||
|
var endMarker = L.marker(end);
|
||||||
endMarker.bindPopup({{ .endPoint.name }});
|
endMarker.bindPopup({{ .endPoint.name }});
|
||||||
|
|
||||||
var route = L.polyline([start, end], {color: '#000'}).addTo(map);
|
// Add line to display dispatch route
|
||||||
|
var route = L.polyline([start, end], {color: '#000'})
|
||||||
|
|
||||||
|
// Generate string to display list of products in popup
|
||||||
var productsString = "";
|
var productsString = "";
|
||||||
var productsList = {{ .products }};
|
var productsList = {{ .products }};
|
||||||
productsList.forEach((product, i) => productsString = productsString + product.productTitle + (i + 1 < productsList.length ? ', ' : ""));
|
productsList.forEach((product, i) => productsString = productsString + product.productTitle + (i + 1 < productsList.length ? ', ' : ""));
|
||||||
@ -50,6 +67,26 @@
|
|||||||
'Products: <strong>' + productsString + '</strong><br />' +
|
'Products: <strong>' + productsString + '</strong><br />' +
|
||||||
'Status: <strong>' + {{ .status }} + '</strong></p>');
|
'Status: <strong>' + {{ .status }} + '</strong></p>');
|
||||||
|
|
||||||
|
dispatches.addLayer(route);
|
||||||
|
dispatches.addLayer(startMarker);
|
||||||
|
dispatches.addLayer(endMarker);
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
var map = L.map('map', {
|
||||||
|
center: [0, 0],
|
||||||
|
zoom: 2,
|
||||||
|
layers: [osm, makers]
|
||||||
|
});
|
||||||
|
|
||||||
|
var overlayMaps = {
|
||||||
|
"Makers": makers,
|
||||||
|
"Retailers": retailers,
|
||||||
|
"Dispatches": dispatches
|
||||||
|
};
|
||||||
|
|
||||||
|
var layerControl = L.control.layers(overlayMaps, null, {collapsed: false, position: "topleft"}).addTo(map);
|
||||||
|
window.addEventListener('load', (event) => {
|
||||||
|
map.invalidateSize();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue
Block a user