mirror of
https://github.com/TheGreyDiamond/elevatormapRewritten.git
synced 2025-07-18 02:23:50 +02:00
Now shows markers on the map
This commit is contained in:
19
index.js
19
index.js
@ -179,8 +179,23 @@ app.get("/api/getElevators", function (req, res) {
|
||||
var lan = parseFloat(req.query.lan)
|
||||
var lat = parseFloat(req.query.lat)
|
||||
var radius = parseFloat(req.query.radius)
|
||||
res.send(JSON.stringify({ state: "Ok", "message": ""}));
|
||||
res.status(200);
|
||||
|
||||
// TODO: Return just the elevators in the viewers area
|
||||
|
||||
con.query("SELECT * FROM elevators", function (err, result, fields) {
|
||||
if (err){
|
||||
res.status(500);
|
||||
res.send(JSON.stringify({ state: "Failed", "message": "A server side error occured.", "results": []}));
|
||||
logger.error("The server failed to execute a request")
|
||||
throw err;
|
||||
}else{
|
||||
console.log(result[0]);
|
||||
res.status(200);
|
||||
res.send(JSON.stringify({ state: "Ok", "message": "", "results": result}));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}else{
|
||||
// Welp something is missing
|
||||
res.status(400);
|
||||
|
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2011-2014 Dave Gamache
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
@ -95,6 +95,14 @@
|
||||
);
|
||||
// mymap.setView(new L.LatLng(10.737, -73.923), 8);
|
||||
}
|
||||
|
||||
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 () {
|
||||
@ -106,6 +114,24 @@
|
||||
}
|
||||
|
||||
home();
|
||||
|
||||
function addPin(item, index){
|
||||
var marker = new L.Marker([item.lat, item.lng])
|
||||
marker.addTo(mymap);
|
||||
}
|
||||
|
||||
// Start getting the elevators
|
||||
response = httpGet("http://localhost:3000/api/getElevators?lan=" + mymap.getCenter.lng + "&lat=" + mymap.getCenter.lat + "&radius=" + mymap.getZoom())
|
||||
response = JSON.parse(response)
|
||||
|
||||
if(response.state == "Ok"){
|
||||
response.results.forEach(addPin)
|
||||
}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")
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user