Merge pull request #874 from rasika/geo-fence-issues

Geo Fencing improvements
revert-70aa11f8
Madhawa Perera 7 years ago committed by GitHub
commit 28060d011d

@ -745,24 +745,37 @@
geoPublicUri = $("#geo-charts").data("geo-public-uri"); geoPublicUri = $("#geo-charts").data("geo-public-uri");
{{#if geoServicesEnabled}} {{#if geoServicesEnabled}}
var geoToolsMenu = $('#location-action-bar'); var geoToolsMenu = $('#location-action-bar');
var realtTime = createGeoToolListItem('javascript:enableRealTime()',
'Return to Real Time View', 'fw fw-undo', geoToolsMenu); var refreshMap = createGeoToolListItem('javascript:void(0);', 'Refresh', 'fw fw-refresh', geoToolsMenu, true);
refreshMap.addClass("geo-alert");
refreshMap.on("click", function(){enableRealTime();});
var realtTime = createGeoToolListItem('javascript:void(0);', 'Return to Real Time View', 'fw fw-undo', geoToolsMenu, true);
realtTime.on("click", function(){enableRealTime();});
realtTime.css("display", "none"); realtTime.css("display", "none");
realtTime.attr("id", "realTimeShow"); realtTime.attr("id", "realTimeShow");
createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/speed_alert.html',
var speedAlert = createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/speed_alert.html',
'Set Speed Alert', 'glyphicon glyphicon-dashboard', geoToolsMenu); 'Set Speed Alert', 'glyphicon glyphicon-dashboard', geoToolsMenu);
createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/stationery_alert.html', speedAlert.addClass("geo-alert");
var stationaryAlert = createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/stationery_alert.html',
'Add Stationary Alert', 'glyphicon glyphicon-link', geoToolsMenu); 'Add Stationary Alert', 'glyphicon glyphicon-link', geoToolsMenu);
createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/within_alert.html', stationaryAlert.addClass("geo-alert");
var withinAlert = createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/within_alert.html',
'Add Geofence Alert', 'glyphicon glyphicon-log-in', geoToolsMenu); 'Add Geofence Alert', 'glyphicon glyphicon-log-in', geoToolsMenu);
createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/exit_alert.html', withinAlert.addClass("geo-alert");
var exitAlert = createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/exit_alert.html',
'Add Geofence Exit Alert', 'glyphicon glyphicon-log-out', geoToolsMenu); 'Add Geofence Exit Alert', 'glyphicon glyphicon-log-out', geoToolsMenu);
exitAlert.addClass("geo-alert");
{{/if}} {{/if}}
} }
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
$('#dateRangePopup').dialog('close'); $('#dateRangePopup.ui-dialog-content').dialog('close');
}) });
}); });
</script> </script>
{{/zone}} {{/zone}}

@ -35,12 +35,12 @@ var zoomLevel = 15;
var tileSet = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"; var tileSet = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
var attribution = "&copy; <a href='https://openstreetmap.org/copyright'>OpenStreetMap</a> contributors"; var attribution = "&copy; <a href='https://openstreetmap.org/copyright'>OpenStreetMap</a> contributors";
function initialLoad() { function initialLoad(geoFencingEnabled) {
if (document.getElementById('map') == null) { if (document.getElementById('map') == null) {
setTimeout(initialLoad, 500); // give everything some time to render setTimeout(initialLoad, 500); // give everything some time to render
} else { } else {
initializeMap(); initializeMap();
processAfterInitializationMap(); processAfterInitializationMap(geoFencingEnabled);
$("#loading").hide(); $("#loading").hide();
} }
} }
@ -111,7 +111,7 @@ var geoAlertsBar;
var groupedOverlays; var groupedOverlays;
var layerControl; var layerControl;
function processAfterInitializationMap() { function processAfterInitializationMap(geoFencingEnabled) {
attributionControl = L.control({ attributionControl = L.control({
position: "bottomright" position: "bottomright"
}); });
@ -123,7 +123,9 @@ function processAfterInitializationMap() {
map.addControl(L.control.fullscreen({position: 'bottomright'})); map.addControl(L.control.fullscreen({position: 'bottomright'}));
geoAlertsBar = L.control.geoAlerts({position: 'topright'}); geoAlertsBar = L.control.geoAlerts({position: 'topright'});
if (geoFencingEnabled) {
map.addControl(geoAlertsBar); map.addControl(geoAlertsBar);
}
groupedOverlays = { groupedOverlays = {
"Web Map Service layers": {} "Web Map Service layers": {}
@ -277,6 +279,7 @@ var getProviderData = function (timeFrom, timeTo) {
var serviceUrl = '/api/device-mgt/v1.0/geo-services/stats/' + deviceType + '/' + deviceId + '?from=' + timeFrom + '&to=' + timeTo; var serviceUrl = '/api/device-mgt/v1.0/geo-services/stats/' + deviceType + '/' + deviceId + '?from=' + timeFrom + '&to=' + timeTo;
invokerUtil.get(serviceUrl, invokerUtil.get(serviceUrl,
function (data) { function (data) {
if(data === ""){showCurrentLocation(tableData);}
tableData = JSON.parse(data); tableData = JSON.parse(data);
if (tableData.length === 0) { if (tableData.length === 0) {
showCurrentLocation(tableData); showCurrentLocation(tableData);
@ -359,7 +362,8 @@ function notifyError(message) {
} }
function enableRealTime() { function enableRealTime() {
document.getElementById('realTimeShow').style.display = 'none'; $("#realTimeShow").hide();
$(".geo-alert").show();
spatialObject = currentSpatialObjects[selectedSpatialObject]; spatialObject = currentSpatialObjects[selectedSpatialObject];
if (spatialObject) { if (spatialObject) {
spatialObject.removePath(); spatialObject.removePath();
@ -368,8 +372,13 @@ function enableRealTime() {
selectedSpatialObject = null; selectedSpatialObject = null;
clearFocus(); clearFocus();
clearMap(); clearMap();
document.getElementById('objectInfo').style.display = 'none';
isBatchModeOn = false; isBatchModeOn = false;
initializeGeoLocation(geoFencingEnabled);
}
function disableRealTime(){
$(".geo-alert").hide();
$("#realTimeShow").show();
} }
var geoFencingEnabled = true; var geoFencingEnabled = true;
@ -456,7 +465,7 @@ function focusOnHistorySpatialObject(objectId, timeFrom, timeTo) {
notifyError('No end time provided to show history. Please provide a suitable value' + timeTo); notifyError('No end time provided to show history. Please provide a suitable value' + timeTo);
} else { } else {
$('#dateRangePopup').dialog('close'); $('#dateRangePopup').dialog('close');
document.getElementById('realTimeShow').style.display = 'block'; disableRealTime();
isBatchModeOn = true; isBatchModeOn = true;
clearFocus(); // Clear current focus if any clearFocus(); // Clear current focus if any
clearMap(); clearMap();
@ -524,11 +533,13 @@ function clearFocus() {
} }
} }
function createGeoToolListItem(link, text, icon, menuRoot) { function createGeoToolListItem(link, text, icon, menuRoot, noModal) {
var listItem = $("<div/>", { class: 'action-btn filter'}).appendTo(menuRoot); var listItem = $("<div/>", { class: 'action-btn filter'}).appendTo(menuRoot);
var anchor = $("<a/>", {href: link, text: ' ' + text}).appendTo(listItem); var anchor = $("<a/>", {href: link, text: ' ' + text}).appendTo(listItem);
if(!noModal){
anchor.attr('data-toggle', 'modal'); anchor.attr('data-toggle', 'modal');
anchor.attr('data-target', '#commonModal'); anchor.attr('data-target', '#commonModal');
}
$("<i/>", {class: icon}).prependTo(anchor); $("<i/>", {class: icon}).prependTo(anchor);
return listItem; return listItem;
} }

@ -630,7 +630,7 @@ function initializeGeoLocation(geoFencingEnabled) {
+ "deviceId=" + deviceId + "&deviceType=" + deviceType + "&websocketToken=" + wsToken; + "deviceId=" + deviceId + "&deviceType=" + deviceType + "&websocketToken=" + wsToken;
$("#proximity_alert").hide(); $("#proximity_alert").hide();
initialLoad(); initialLoad(geoFencingEnabled);
InitSpatialObject(geoFencingEnabled); InitSpatialObject(geoFencingEnabled);
if (geoFencingEnabled) { if (geoFencingEnabled) {

Loading…
Cancel
Save