<commit_before>var map;
var markers; // this will hold all markers we put on the map...
var markerUpdateTimer;	// this will hold the object for the setInterval timer to auto-update the last set marker...

function init() 
{
	map = L.map('map').setView([50.00,10.000], 5);

	L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
		maxZoom: 18,
		attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>'
		}).addTo(map);
		
// add location control to global name space for testing only
// on a production site, omit the "lc = "!
L.control.locate({follow: false}).addTo(map);

var button = new L.Control.Button('Toggle me', {
  toggleButton: 'active',
  className: 'leaflet-control-locate leaflet-bar leaflet-control leaflet-bar-part leaflet-bar-part-single'
});
button.addTo(map);
button.on('click', function () {
    if (button.isToggled()) {
        sidebar.hide();
    } else {
        sidebar.show();
    }
});


L.control.scale().addTo(map);

//map.on('startfollowing', function() {
//    map.on('dragstart', lc.stopFollowing);
//}).on('stopfollowing', function() {
//    map.off('dragstart', lc.stopFollowing);
//});
}

function AddMarkerDistinct(newMarkerObject)
{
	if (markers == null)
		markers = [];
	if (newMarkerObject.ID == null)
		return;
	if (newMarkerObject.Marker == null)
		return;
	
	// check if it's already in...
	var foundmarker = false;
	for( var k=0; k<markers.length; k++ ) 
	{
		//console.log(KnownDevices[k]);
		if (markers[k].ID == newMarkerObject.ID)
		{
			console.log("Device already on the marker list");
			foundmarker = true;
			map.removeLayer(markers[k].Marker);
			oldobject = markers[k].Marker;
			
			markers[k] = newMarkerObject;
			break;
		}
	}
	if (!foundmarker)
	{
		markers.push(newMarkerObject);
	}
	else
		return oldobject;
}


function GetLocation(DeviceID)
{
	// build miataru GetLocationRequest
	var GetLocationRequest = {};
	var Device = {};
	Device.Device = DeviceID;
	GetLocationRequest.MiataruGetLocation = new Array(Device);

	var GLR = JSON.stringify(GetLocationRequest);
	
	console.log("Miataru Service Request Body: "+GLR);

	// do the request
	$.ajax({
    		contentType: 'application/json',
			data: GLR,
			dataType: 'json',
			success: function(data)
			{
				// add to the map...
				console.log(data);

				if (data.MiataruLocation[0] != null)
				{
					// the Name
					var deviceName = data.MiataruLocation[0].Device + " - "+ timeSince(data.MiataruLocation[0].Timestamp)+ " ago";
					
					var newMarker = new L.marker([data.MiataruLocation[0].Latitude,data.MiataruLocation[0].Longitude]);		
					
					newMarker.addTo(map).bindPopup(deviceName);
					
					var newMarkerObject = {};
					newMarkerObject.ID = DeviceID;
					newMarkerObject.Marker = newMarker;

					oldObject = AddMarkerDistinct(newMarkerObject);
					
					//map.fitBounds([[data.MiataruLocation[0].Latitude,data.MiataruLocation[0].Longitude]]);
					map.panTo(new L.LatLng(data.MiataruLocation[0].Latitude,data.MiataruLocation[0].Longitude));
					var Device = {};
					Device.Name = DeviceID;
					Device.ID = DeviceID;
					
					// set the timer for this device...
					markerUpdateTimer = setTimeout(function () { GetLocation(DeviceID); }, 5000);
					
					AddKnownDevices(Device);					
				}
				else
				{
					console.log("Device could not be found");
					$('#doesnotexist').modal();
					
				}
			},
			error: function(){
				console.log("The miataru service could not be reached or returned an error.");
				},
			processData: false,
			type: 'POST',
			url: 'https://service.miataru.com/v1/GetLocation'
		   });
	
}

// TimeSince

function timeSince(date) {

	var seconds = Math.floor(((new Date().getTime()/1000) - date))
    //var seconds = Math.floor((new Date() - date) / 1000);
<commit_msg>following the marker can be turned on/off now - also markers are only added when there is movement<commit_after>var map;
var markers; // this will hold all markers we put on the map...
var markerUpdateTimer;	// this will hold the object for the setInterval timer to auto-update the last set marker...
var followMarkerUpdates = true;

function init() 
{
	map = L.map('map').setView([50.00,10.000], 5);

	L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
		maxZoom: 18,
		attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.<EMAIL>">CloudMade</a>'
		}).addTo(map);
		
// add location control to global name space for testing only
// on a production site, omit the "lc = "!
L.control.locate({follow: false}).addTo(map);

var button = new L.Control.Button('Toggle me', {
  toggleButton: 'active'
});
button.addTo(map);
button.on('click', function () {
    if (button.isToggled()) {
       	console.log("Marker Following ON");
        followMarkerUpdates = true;
    } else {
    	console.log("Marker Following OFF");
		followMarkerUpdates = false;

    }
});


L.control.scale().addTo(map);

//map.on('startfollowing', function() {
//    map.on('dragstart', lc.stopFollowing);
//}).on('stopfollowing', function() {
//    map.off('dragstart', lc.stopFollowing);
//});
}

function AddMarkerDistinct(newMarkerObject)
{
	if (markers == null)
		markers = [];
	if (newMarkerObject.ID == null)
		return;
	if (newMarkerObject.Marker == null)
		return;
	
	// check if it's already in...
	var foundmarker = false;
	for( var k=0; k<markers.length; k++ ) 
	{
		//console.log(KnownDevices[k]);
		if (markers[k].ID == newMarkerObject.ID)
		{
			console.log("Device already on the marker list");
			foundmarker = true;
			oldobject = markers[k].Marker;
			
			markers[k] = newMarkerObject;
			break;
		}
	}
	if (!foundmarker)
	{
		markers.push(newMarkerObject);
		return null;
	}
	else
		return oldobject;
}


function GetLocation(DeviceID)
{
	// build miataru GetLocationRequest
	var GetLocationRequest = {};
	var Device = {};
	Device.Device = DeviceID;
	GetLocationRequest.MiataruGetLocation = new Array(Device);

	var GLR = JSON.stringify(GetLocationRequest);
	
	console.log("Miataru Service Request Body: "+GLR);

	// do the request
	$.ajax({
    		contentType: 'application/json',
			data: GLR,
			dataType: 'json',
			success: function(data)
			{
				// add to the map...
				console.log(data);

				if (data.MiataruLocation[0] != null)
				{
					// the Name
					var deviceName = data.MiataruLocation[0].Device + " - "+ timeSince(data.MiataruLocation[0].Timestamp)+ " ago";
					
					var newMarker = new L.marker([data.MiataruLocation[0].Latitude,data.MiataruLocation[0].Longitude]);		
				
					var newMarkerObject = {};
					newMarkerObject.ID = DeviceID;
					newMarkerObject.Marker = newMarker;

					oldObject = AddMarkerDistinct(newMarkerObject);

					var addToMap = true;
					
					if (newMarkerObject != null && oldObject != null)
					{
						if (newMarkerObject.Marker.getLatLng().lat == oldObject.getLatLng().lat && newMarkerObject.Marker.getLatLng().lng == oldObject.getLatLng().lng)
						{
							// it's equal... do not add
							console.log("We already have that Marker, don't add it again...");
							addToMap = false;
						}						
					}
					
					if (addToMap)
					{
						// remove the old one
						if (oldObject != null)
							map.removeLayer(oldObject);
						// add the new one...
						newMarker.addTo(map).bindPopup(deviceName);
					}

					//map.fitBounds([[data.MiataruLocation[0].Latitude,data.MiataruLocation[0].Longitude]]);
					if (followMarkerUpdates && addToMap)
						map.panTo(new L.LatLng(data.MiataruLocation[0].Latitude,data.MiataruLocation[0].Longitude));
					
					var Device = {};
					Device.Name = DeviceID;
					Device.ID = DeviceID;
					
					// set the timer for this device...
					markerUpdateTimer = setTimeout(function () { GetLocation(DeviceID); }, 5000);
					
					AddKnownDevices(Device);
				}
				else
				{
					console.log("Device could not be found");
					$('#doesnotexist').modal();
					
				}
			},
			error: function(){
				console.log("The miataru service could not be reached or returned an error.");
				},
			processData: false,
			type: 'POST',
			url: 'https://service.miataru.com/v1/GetLocation'
		   });
	
}

// TimeSince

function timeSince(date) {

	var seconds = Math.floor(((new Date().getTime()/1000) - date))
    //var seconds = Math.floor((new Date() - date) / 1000);

{'fraction_non_alphanumeric': 0.15678310316815597, 'fraction_numerical': 0.014854357665080654, 'mean_word_length': 3.2100635075720567, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1473261', 'n_tokens_mistral': 3457, 'n_tokens_neox': 2846, 'n_words': 618}