function createNewElev() { window.location.href = "/createElevator"; } var amountOfImages = 0; var markers = L.markerClusterGroup(); slideIndex = 1; theMarker = L.Marker.extend({ options: { id: "-1", }, }); function showPosition(position) { console.log(position.coords); mymap.setView( new L.LatLng(position.coords.latitude, position.coords.longitude), 10 ); // mymap.setView(new L.LatLng(10.737, -73.923), 8); } function onClick(e) { slideIndex = 1; document.getElementById("inspector").innerHTML = '

'; res = JSON.parse(httpGet("/api/getElevatorById?id=" + this.options.id)); if (res.state == "Ok") { visitStates = [ "Test elevator", "Public", "On private property", "Public but locked", ]; typeStates = [ "Hydraulic", "Wiredriven, motor in shaft", "Wiredriven, motor in motorroom", ]; // Prepare the template inspector = httpGet("/templates/inspectorContent.html"); inspector = inspector.replace("#MODELL", res.results[0].modell); inspector = inspector.replace("#MANUF", res.results[0].manufacturer); inspector = inspector.replace("#DESC", res.results[0].info); inspector = inspector.replace( "#TYPE", typeStates[res.results[0].technology] ); inspector = inspector.replace("#MAXPASS", res.results[0].maxPassangers); inspector = inspector.replace("#MASSWEIGH", res.results[0].maxWeight); inspector = inspector.replace( "#VISIT", visitStates[res.results[0].visitabilty] ); try { var username = JSON.parse( httpGet("/api/resolveNameById?id=" + res.results[0].creator) ).results[0].username; } catch { username = "Unknown"; } inspector = inspector.replace("#CREATOR", username); document.getElementById("inspector").innerHTML = inspector; // Make gallery document.getElementById("imageGallery").innerHTML = "
"; imgs = JSON.parse(res.results[0].images); amountOfImages = imgs.images.length; console.log(imgs); var iH = 0; while (amountOfImages > iH) { newBox = "
"; newBox += iH + 1; newBox += "/"; newBox += amountOfImages; newBox += "
" +
        imgs.images[iH].alt +
        "
"; document.getElementById("imageGallery").innerHTML += newBox; iH++; } document.getElementById("imageGallery").innerHTML += "




"; showSlides(1); } else { document.getElementById("inspector").innerHTML = ' \
\

\

Oh no!

\ The website failed to fetch the information about this elevator. It responded with the error code: \
\ ' + res.message + "
"; } console.log(res); } function httpGet(theUrl) { var xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET", theUrl, false); // false for synchronous request xmlHttp.send(null); return xmlHttp.responseText; } function home() { if (navigator.geolocation) { setTimeout(function () { navigator.geolocation.getCurrentPosition(showPosition); }, 200); } else { console.warn("Geolocation of user could not be fetched"); } } home(); function addPin(item, index) { var marker = new theMarker([item.lat, item.lng], { id: item.id, }).on("click", onClick); // var marker = new L.Marker() //marker.addTo(mymap).on('click', onClick); markers.on("clusterclick", function (a) { //alert('cluster ' + a.layer.getAllChildMarkers().length); }); markers.addLayer(marker); } // Start getting the elevators response = httpGet( "/api/getElevatorLocation?lan=" + mymap.getCenter.lng + "&lat=" + mymap.getCenter.lat + "&radius=" + mymap.getZoom() ); response = JSON.parse(response); if (response.state == "Ok") { response.results.forEach(addPin); mymap.addLayer(markers); } else { // DONT FORGET TO SHOW POPUP OR SOMETHING console.log("Request failed with " + response.message); console.log(response); alert("Loading of the map pins failed"); } // Next/previous controls function plusSlides(n) { showSlides((slideIndex += n)); } // Thumbnail image controls function currentSlide(n) { showSlides((slideIndex = n)); } function showSlides(n) { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); if (n > slides.length) { slideIndex = 1; } if (n < 1) { slideIndex = slides.length; } for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } for (i = 0; i < dots.length; i++) { dots[i].className = dots[i].className.replace(" active", ""); } slides[slideIndex - 1].style.display = "block"; dots[slideIndex - 1].className += " active"; }