1
0

Converted remaining methods from JavaScript to CoffeeScript.

This commit is contained in:
Markus Birth 2018-04-28 15:05:00 +02:00
parent 8b2845d4d2
commit df75b59737
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
5 changed files with 61 additions and 86 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/assets/*.js
/assets/*.js.map
/bower_components/
/tools/Location History.json

View File

@ -1,81 +0,0 @@
function geodecodeMarker(i)
{
console.log("geodecodeMarker : INIT");
console.log("geodecodeMarker : INFO Geodecoding marker #" + i);
//ajax call to remove marker from backend
$.ajax({
url: 'rpc.php',
data: {
'epoch': markers[i].epoch,
'action': 'geoDecode'
},
type: 'get',
dataType: 'json',
success: function(data, status)
{
if (data.status) {
console.log("geodecodeMarker : INFO Status : " + status);
console.log("geodecodeMarker : INFO Data : " + data);
//update marker data
$('#loc_'+i).html("<a href='javascript:showBoundingBox("+ i +");' title='Show location bounding box' >" + data.location + "</a>");
} else {
console.log("geodecodeMarker : ERROR Status : " + status);
console.log("geodecodeMarker : ERROR Data : " + data);
}
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("geodecodeMarker : ERROR Details: " + desc + "\nError:" + err);
}
});
}
/**
* Adds two numbers
* @param {Number} a
*/
function deleteMarker(tid, i)
{
console.log("deleteMarker : INIT tid = "+tid+" i = "+i);
if (confirm('Do you really want to permanently delete marker ?')) {
console.log("deleteMarker : INFO Removing marker #" + i);
//ajax call to remove marker from backend
$.ajax({
url: 'rpc.php',
data: {
'epoch': tid_markers[tid][i].epoch,
'action': 'deleteMarker'
},
type: 'get',
dataType: 'json',
success: function(data, status) {
if (data.status) {
//removing element from JS array
tid_markers[tid].splice(i, 1);
//redraw map from scratch
eraseMap();
drawMap();
} else {
console.log("deleteMarker : ERROR Status : " + status);
console.log("deleteMarker : ERROR Data : " + data);
}
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("deleteMarker : ERROR Details: " + desc + "\nError:" + err);
}
});
}
}
function showBoundingBox(i)
{
console.log("showBoundingBox : INIT i = "+i);
}

View File

@ -151,3 +151,17 @@ window.setLiveMap = ->
$('#livemap_on').removeClass('btn-default').addClass('btn-primary').addClass 'active'
else
$('#livemap_on').addClass('btn-default').removeClass('btn-primary').removeClass 'active'
window.geodecodeMarker = (tid, i) ->
console.log 'geodecodeMarker: %o, %o', tid, i
window.mymap.geodecodeMarker tid, i
window.deleteMarker = (tid, i) ->
console.log 'deleteMarker: %o, %o', tid, i
if confirm "Do you really want to delete this marker for #{tid}?"
console.log 'deleteMarker: Confirmation given'
window.mymap.deleteMarker tid, i
window.showBoundingBox = (tid, i) ->
console.log 'showBoundingBox: %o, %o', tid, i
console.warn 'NOT YET IMPLEMENTED'

View File

@ -2,6 +2,7 @@ class window.OwnMap
constructor: ->
console.log 'initMap'
@my_markers = {}
@trackerIDs = []
@live_view = false
@ -122,7 +123,7 @@ class window.OwnMap
trackerIDs = Object.keys _tid_markers
tid_markers = [] # markers collected from json
@my_markers = []
@my_markers = {}
my_latlngs = []
@polylines = []
@ -148,11 +149,11 @@ class window.OwnMap
velocityString = if marker.velocity? then "<br/>Velocity: #{marker.velocity} km/h" else ''
locationString = ""
if marker.display_name?
locationString = "<br/>Location: <a href='javascript:showBoundingBox(#{i});' title='Show location bounding box'>#{marker.display_name}</a>"
locationString = "<br/>Location: <a href=\"#\" onclick=\"showBoundingBox('#{tid}', #{i});\" title=\"Show location bounding box\">#{marker.display_name}</a>"
else
locationString = "<br/>Location: <span id='loc_#{i}'><a href='javascript:geodecodeMarker(#{i});' title='Get location (geodecode)'>Get location</a></span>"
locationString = "<br/>Location: <span id=\"loc_#{tid}_#{i}\"><a href=\"#\" onclick=\"geodecodeMarker('#{tid}', #{i});\" title=\"Get location (geodecode)\">Get location</a></span>"
removeString = "<br/><br/><a href=\"javascript:deleteMarker('#{tid}', #{i});\">Delete marker</a>"
removeString = "<br/><br/><a href=\"#\" onclick=\"deleteMarker('#{tid}', #{i});\">Delete marker</a>"
# prepare popup HTML code for marker
popupString = dateString + trackerIDString + accuracyString + headingString + velocityString + locationString + removeString
@ -192,6 +193,7 @@ class window.OwnMap
#}
# array of all markers for display / hide markers + initial auto zoom scale
my_marker.epoch = markers[i].epoch # needed for geocoding/deleting
@my_markers[tid][i] = my_marker
# var polylines[tid] = L.polyline(my_latlngs[tid]).addTo(mymap);
@ -273,3 +275,43 @@ class window.OwnMap
else
clearTimeout @live_view_timer
return @live_view
geodecodeMarker: (tid, i) ->
console.log 'geodecodeMarker: %o, %o', tid, i
# ajax call to remove marker from backend
$.ajax
url: 'rpc.php'
data:
'epoch': @my_markers[tid][i].epoch
'action': 'geoDecode'
type: 'get'
dataType: 'json'
success: (data, status) =>
if data.status?
console.log 'geodecodeMarker: Status=%o, Data=%o', status, data
# update marker data
$("#loc_#{tid}_#{i}").html "<a href='javascript:showBoundingBox(#{tid}, #{i});' title='Show location bounding box'>#{data.location}</a>"
else
console.error 'geodecodeMarker: Status=%o, Data=%o', status, data
error: (xhr, desc, err) ->
console.error 'geodecodeMarker: XHR=%o, Error=%o, Details=%o', xhr, err, desc
deleteMarker: (tid, i) ->
console.log 'deleteMarker: %o, %o', tid, i
# ajax call to remove marker from backend
$.ajax
url: 'rpc.php'
data:
'epoch': @my_markers[tid][i].epoch
'action': 'deleteMarker'
type: 'get'
dataType: 'json'
success: (data, status) =>
if data.status
@getMarkers()
else
console.error 'deleteMarker: Status=%o Data=%o', status, data
error: (xhr, desc, err) ->
console.error 'deleteMarker: XHR=%o, Error=%o, Details=%o', xhr, err, desc

View File

@ -10,7 +10,6 @@
<!-- our scripts -->
<script type="text/javascript" src="assets/main.js"></script>
<script type="text/javascript" src="assets/ownmap.js"></script>
<script type="text/javascript" src="assets/index.js"></script>
<link rel="stylesheet" href="assets/style.css"/>
<title>Your Own Tracks</title>
</head>