Skip to content

Commit

Permalink
fly to device
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenakh committed Nov 23, 2019
1 parent c9c711b commit 235abea
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/geottnd/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,48 @@
devicelist.innerHTML += `<li class="list-group-item"><button type="button" class="btn btn-link">` + value + `</button></li>`;
});

let btns = document.getElementsByClassName( 'btn' );

for ( let btn of btns ) {
btn.onclick = function() {
console.log(this.textContent);
const bxhr = new XMLHttpRequest();

bxhr.open('GET', "/api/data/" + this.textContent, true);
bxhr.onload = function() {
if (xhr.status !== 200) {
return;
}
let data = JSON.parse(bxhr.responseText);

const devicediv = document.getElementById('device_id');
devicediv.innerHTML = data[0].device_id;

const devicebody = document.getElementById('device_body');
devicebody.innerHTML = '';

map.flyTo({
center: [ data[0].lng, data[0].lat ],
zoom: 13,
bearing: 0,
});
data.forEach(function (value) {
let html = '<tr><td>' + value["time"] + '<td>';

for (let key of Object.keys(value)) {
if (key === 'time' || key === 'device_id') { continue; }
html += key + ":" + value[key] + " ";
}
html += '</td></tr>';

devicebody.innerHTML += html;
});

};
bxhr.send();
}
}

};
xhr.send();
});
Expand Down
2 changes: 2 additions & 0 deletions web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func (s *Server) DataQuery(w http.ResponseWriter, r *http.Request) {
jsresp[k] = v
}
jsresp["device_id"] = dp.Key
jsresp["lat"] = dp.Lat
jsresp["lng"] = dp.Lng
jsresp["time"] = dp.Time.Format(time.RFC3339)

res[i] = jsresp
Expand Down

0 comments on commit 235abea

Please sign in to comment.