Update map-customer.tpl
fix Map
This commit is contained in:
parent
af3995b421
commit
21058d5c4e
@ -4,59 +4,42 @@
|
|||||||
<div id="map" style="width: '100%'; height: 600px; margin: 20px auto"></div>
|
<div id="map" style="width: '100%'; height: 600px; margin: 20px auto"></div>
|
||||||
|
|
||||||
{literal}
|
{literal}
|
||||||
<script>
|
<script>
|
||||||
function getLocation() {
|
window.onload = function() {
|
||||||
if (navigator.geolocation) {
|
var map = L.map('map').setView([51.505, -0.09], 13);
|
||||||
navigator.geolocation.getCurrentPosition(showPosition);
|
var group = L.featureGroup().addTo(map);
|
||||||
} else {
|
|
||||||
setupMap(51.505, -0.09);
|
var customers = {/literal}{$customers|json_encode}{literal};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function showPosition(position) {
|
L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/light_all/{z}/{x}/{y}.png', {
|
||||||
setupMap(position.coords.latitude, position.coords.longitude);
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>',
|
||||||
}
|
subdomains: 'abcd',
|
||||||
|
maxZoom: 20
|
||||||
|
}).addTo(map);
|
||||||
|
|
||||||
function setupMap(lat, lon) {
|
customers.forEach(function(customer) {
|
||||||
var map = L.map('map').setView([lat, lon], 13);
|
var name = customer.id;
|
||||||
var group = L.featureGroup().addTo(map);
|
var name = customer.name;
|
||||||
|
var info = customer.info;
|
||||||
|
var coordinates = customer.coordinates;
|
||||||
|
var balance = customer.balance;
|
||||||
|
var address = customer.address;
|
||||||
|
|
||||||
var customers = {/literal}{$customers|json_encode}{literal};
|
// Create a popup for the marker
|
||||||
|
var popupContent = "<strong>Customer Name</strong>: " + name + "<br>" +
|
||||||
|
"<strong>Customer Info</strong>: " + info + "<br>" +
|
||||||
|
"<strong>Customer Balance</strong>: " + balance + "<br>" +
|
||||||
|
"<strong>Address</strong>: " + address + "<br>" +
|
||||||
|
"<strong>Coordinates</strong>: " + coordinates + "<br>" +
|
||||||
|
"<a href='{/literal}{$_url}{literal}customers/view/"+ customer.id +"'>More Info</a><br>";
|
||||||
|
|
||||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/light_all/{z}/{x}/{y}.png', {
|
// Add marker to map
|
||||||
attribution:
|
var marker = L.marker(JSON.parse(coordinates)).addTo(group);
|
||||||
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>',
|
marker.bindTooltip(name).bindPopup(popupContent);
|
||||||
subdomains: 'abcd',
|
});
|
||||||
maxZoom: 20
|
|
||||||
}).addTo(map);
|
|
||||||
|
|
||||||
customers.forEach(function(customer) {
|
map.fitBounds(group.getBounds());
|
||||||
var name = customer.id;
|
}
|
||||||
var name = customer.name;
|
</script>
|
||||||
var info = customer.info;
|
|
||||||
var coordinates = customer.coordinates;
|
|
||||||
var balance = customer.balance;
|
|
||||||
var address = customer.address;
|
|
||||||
|
|
||||||
// Create a popup for the marker
|
|
||||||
var popupContent = "<strong>Customer Name</strong>: " + name + "<br>" +
|
|
||||||
"<strong>Customer Info</strong>: " + info + "<br>" +
|
|
||||||
"<strong>Customer Balance</strong>: " + balance + "<br>" +
|
|
||||||
"<strong>Address</strong>: " + address + "<br>" +
|
|
||||||
"<strong>Coordinates</strong>: " + coordinates + "<br>" +
|
|
||||||
"<a href='{/literal}{$_url}{literal}customers/view/"+ customer.id +"'>More Info</a><br>";
|
|
||||||
|
|
||||||
// Add marker to map
|
|
||||||
var marker = L.marker(JSON.parse(coordinates)).addTo(group);
|
|
||||||
marker.bindTooltip(name).bindPopup(popupContent);
|
|
||||||
});
|
|
||||||
|
|
||||||
map.fitBounds(group.getBounds());
|
|
||||||
}
|
|
||||||
window.onload = function() {
|
|
||||||
getLocation();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
{/literal}
|
{/literal}
|
||||||
|
|
||||||
{include file="sections/footer.tpl"}
|
{include file="sections/footer.tpl"}
|
Loading…
x
Reference in New Issue
Block a user