function createMarker(position, label, url) {
return new woosmap.map.Marker({
labelOrigin: new woosmap.map.Point(14, 15),
function fitBoundsToMatrix(origins, destinations) {
origins.forEach((origin) => {
createMarker(origin, "O", "https://images.woosmap.com/marker-blue.svg"),
destinations.forEach((destination) => {
bounds.extend(destination);
"https://images.woosmap.com/marker-red.svg",
map.fitBounds(bounds, { top: 70, bottom: 40, left: 50, right: 50 }, true);
function createRequest() {
const origin1 = { lat: 45.4642, lng: 9.19 };
const origin2 = { lat: 45.75, lng: 4.85 };
const destinationA = { lat: 42.6976, lng: 9.45 };
origins: [origin1, origin2],
destinations: [destinationA, destinationB],
travelMode: woosmap.map.TravelMode.DRIVING,
unitSystem: woosmap.map.UnitSystem.METRIC,
function handleResponse(response) {
const responseElement = document.getElementById("response");
responseElement.innerText = JSON.stringify(response, null, 2);
fitBoundsToMatrix(distanceRequest.origins, distanceRequest.destinations);
function calculateDistances() {
distanceRequest = createRequest();
const requestElement = document.getElementById("request");
requestElement.innerText = JSON.stringify(distanceRequest, null, 2);
distanceService.getDistanceMatrix(distanceRequest).then(handleResponse);
map = new woosmap.map.Map(document.getElementById("map"), {
center: { lat: 45.53, lng: 2.4 },
distanceService = new woosmap.map.DistanceService();
bounds = new woosmap.map.LatLngBounds();
window.initMap = initMap;