From 99131ba2e13c71edc27c8ed7d642f043fc96d339 Mon Sep 17 00:00:00 2001 From: Vitaly Litvak Date: Thu, 5 May 2016 10:36:47 +0300 Subject: [PATCH] Fixed issues with displaying latest positions on map when devices are not yet loaded --- .../web/client/controller/MapController.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/traccar/web/client/controller/MapController.java b/src/main/java/org/traccar/web/client/controller/MapController.java index f72e9ea1..b79fa231 100644 --- a/src/main/java/org/traccar/web/client/controller/MapController.java +++ b/src/main/java/org/traccar/web/client/controller/MapController.java @@ -138,13 +138,15 @@ public void onSuccess(List result) { } else if (position.getIdleStatus() == Position.IdleStatus.IDLE) { deviceVisibilityHandler.idle(device); } - device = deviceStore.findModelWithKey(Long.toString(device.getId())); - device.setOdometer(position.getDistance()); - // check maintenances - for (Maintenance maintenance : device.getMaintenances()) { - if (device.getOdometer() >= maintenance.getLastService() + maintenance.getServiceInterval()) { - alertsMap.put(device.getId(), position); - break; + Device storedDevice = deviceStore.findModelWithKey(Long.toString(device.getId())); + if (storedDevice != null) { + storedDevice.setOdometer(position.getDistance()); + // check maintenances + for (Maintenance maintenance : storedDevice.getMaintenances()) { + if (storedDevice.getOdometer() >= maintenance.getLastService() + maintenance.getServiceInterval()) { + alertsMap.put(device.getId(), position); + break; + } } } }