var map = L.map('map'); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA', maxNativeZoom: 19, maxZoom: 22 }).addTo(map); var overlay_config = { maxNativeZoom: 22, maxZoom: 22, attribution: "", maximumAge: 1000*3600*24*10 } var links_and_routers = new L.TileLayer(tileurls.links_and_routers + '/{z}/{x}/{y}.png', overlay_config).addTo(map); var hoods = new L.TileLayer(tileurls.hoods + '/{z}/{x}/{y}.png', overlay_config); layersControl = new L.Control.Layers({}, {"Links & Routers": links_and_routers, "Hoods": hoods}); map.addControl(layersControl); var router_pointer_radius = 7.5; // actually 7 but let's add some rounding tolerance var popup; map.on('click', function(pos) { // height = width of world in px var size_of_world_in_px = map.options.crs.scale(map.getZoom()); var px_per_deg_lng = size_of_world_in_px / 360; var px_per_deg_lat = size_of_world_in_px / 180; // normalize longitude (user can shift map west/east and leave the [-180..180] range var lng = mod(pos.latlng.lng, 360); var lat = pos.latlng.lat; if (lng > 180) { lng -= 360; } ajax_get_request(url_get_nearest_router + "?lng=" + lng + "&lat=" + lat, function(router) { // decide if router is close enough var lng_delta = Math.abs(lng - router.position.coordinates[0]) var lat_delta = Math.abs(lat - router.position.coordinates[1]) // convert degree distances into px distances on the map var x_delta_px = lng_delta * px_per_deg_lng; var y_delta_px = lat_delta * px_per_deg_lat; // use pythagoras to calculate distance var px_distance = Math.sqrt(x_delta_px*x_delta_px + y_delta_px*y_delta_px); console.debug("Distance to closest router ("+router.hostname+"): " + px_distance+"px"); // check if mouse click was on the router icon if (px_distance <= router_pointer_radius) { console.log("Click on '"+router.hostname+"' detected."); console.log(router); var popup_html = ""; var has_neighbours = 'neighbours' in router && router.neighbours.length > 0; // avoid empty tables if (has_neighbours) { has_neighbours = false; for (neighbour of router.neighbours) { if ('_id' in neighbour) { has_neighbours = true; } } } if (has_neighbours) { popup_html += "
Hostname | "; popup_html += "MAC Address | "; popup_html += "Quality | "; popup_html += "Outgoing Interface | "; popup_html += "
---|---|---|---|
'+neighbour.hostname+' | '; popup_html += ""+neighbour.mac+" | "; popup_html += ""+neighbour.quality+" | "; popup_html += ""+neighbour.net_if+" | "; popup_html += "